ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Traversing a robot in a prespecified path

asked 2012-10-02 23:06:27 -0600

koushik gravatar image

updated 2018-06-19 04:03:50 -0600

felix k gravatar image

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!

edit retag flag offensive close merge delete

Comments

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?

yigit gravatar image yigit  ( 2012-10-02 23:30:19 -0600 )edit

@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.

jarvisschultz gravatar image jarvisschultz  ( 2012-10-03 14:12:46 -0600 )edit

@jarvis You can also do <pre> ..code.. </pre> which is way easier for big snippets.

felix k gravatar image felix k  ( 2012-10-04 02:36:12 -0600 )edit

@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

jarvisschultz gravatar image jarvisschultz  ( 2012-10-04 05:56:42 -0600 )edit

hello, have you found the complete code that would be able to do this?

aarontan gravatar image aarontan  ( 2018-06-16 10:28:18 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2012-10-03 08:12:46 -0600

SL Remy gravatar image

The robot is only going to move if the twist commands are published to the proper topic (/cmd_vel if memory serves right)...

So you will have to remap /cmd_vel (or what ever the topic is called) to /base_controller/command. (Take a look here)

To check this as @yygyt has indicated use rostopic.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-10-02 23:06:27 -0600

Seen: 406 times

Last updated: Jun 19 '18