Traversing a robot in a prespecified path
Hi!
Last day i was trying out an experiment to traverse a robot in a pre specified path (say a mathematical curve). To keep thing simple at the beginning I choose a straight path. I made a learning_joy package and added the following code in the learning_joy/src/turtle_teleop_joy.cpp
:
#include "ros/ros.h"
#include "turtlesim/Velocity.h"
#include "geometry_msgs/Twist.h"
class TeleopTurtle
{
public:
TeleopTurtle();
void move_robot();
ros::NodeHandle nh_;
ros::Publisher vel_pub_;
};
TeleopTurtle::TeleopTurtle()
{
vel_pub_ = nh_.advertise<geometry_msgs::Twist>("base_controller/command",1);
move_robot();
}
void TeleopTurtle::move_robot()
{
geometry_msgs::Twist cmdvel;
int i = 0;
while(i < 100) //continue publishing the message
{
cmdvel.angular.z = 0;
cmdvel.linear.x = 2;
vel_pub_.publish(cmdvel);
i++;
}
}
int main(int argc, char** argv)
{
ros::init(argc, argv, "teleop_turtle");
TeleopTurtle teleop_turtle;
ros::spin();
}
the steps i followed after that are:
$ roscore $ roscd stage ./bin/stageros world/willow-erratic.world $ rosmake learning_joy $ rosrun learning_joy turtle_teleop_joy
This does not give any errors but the robot does not move. rxgraph
shows that the node is running. Can you please tell me the reason as to why this does not work ?
Regards!
do you see the topic you publish (base_controller/command) when you type in "rostopic list". If so, have you tried "rostopic echo base_controller/command" to see that you can publish the messages correctly?
@koushik just FYI, if you put four spaces in front of each line of your C code, it will end up formatted as C code in your post. This makes it much easier for others to read, meaning they will often be more likely to help.
@jarvis You can also do <pre> ..code.. </pre> which is way easier for big snippets.
@felix k haha yeah good point! I usually paste them in from emacs, and just use string-insert-rectangle to accomplish the 4 spaces. But you are definitely right, the tags are much easier
hello, have you found the complete code that would be able to do this?