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

sending velocity commands to the robot throught cmd_vel topic

asked 2019-08-25 06:45:28 -0500

rayane gravatar image

updated 2019-08-26 02:59:17 -0500

Hi, I want to send velocity comands to move th bebop drone up and then forward. Here is my code:

#include<ros/ros.h>
#include<nav_msgs/Odometry.h>
#include<geometry_msgs/Twist.h>
#include<stdlib.h>
#include<math.h>

float tag_yaw,tag_x,tag_y,tag_z;
ros::Publisher pub;
ros::Subscriber sub;
geometry_msgs::Twist msg;
float err;


 void getpos(const nav_msgs::Odometry& posmsg){

 if (posmsg.pose.pose.position.z<= 1){

 ROS_INFO_STREAM( "Showing position : "
 << "x1 =" << posmsg.pose.pose.position.x
 << "y1 =" << posmsg.pose.pose.position.y
  << "z1 =" << posmsg.pose.pose.position.z);

   msg.linear.x=0.0;
   msg.linear.y=0.0;
   msg.linear.z=  0.1;   // exp ( 0.1);
   msg.angular.x= 0;
   msg.angular.y= 0;
   msg.angular.z=0.0;
    }
    else {

    ROS_INFO_STREAM( "Showing position : "
    << "x =" << posmsg.pose.pose.position.x
    << "y =" << posmsg.pose.pose.position.y
    << "z =" << posmsg.pose.pose.position.z);

     msg.linear.x=0.8*(tag_x-posmsg.pose.pose.position.x);
     msg.linear.y=0.0;
     msg.linear.z=  0.0;   // exp ( 0.1);
     msg.angular.x= 0;
     msg.angular.y= 0;
     msg.angular.z=0.0;
     }

      pub.publish(msg);
     }


   int main(int argc, char **argv){
   ros::init(argc, argv,"velBebop");
   ros::NodeHandle nh;

  tag_x= .5;
  tag_y= 0.0;
   tag_z= 0.0;
   sub = nh.subscribe("/bebop/odom",100, &getpos) ;
    pub = nh.advertise<geometry_msgs::Twist>("/bebop/cmd_vel" ,100);

    ros::spin();
    return 0;
     }

I can see that the velocities are being published through the rqt_graph here: image description

but the drone is not moving at all! it is not even rotating the helices. Any suggestion!!! Thanks

edit retag flag offensive close merge delete

Comments

The code you show does not appear to initialise the Publisher at all. Is that a copy-pasta or actual code?

gvdhoorn gravatar image gvdhoorn  ( 2019-08-26 02:47:45 -0500 )edit

@gvdhoorn I forgot that line that I added now. this is my code

rayane gravatar image rayane  ( 2019-08-26 03:00:04 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-08-26 05:00:39 -0500

Ktysai gravatar image

updated 2019-08-26 10:09:50 -0500

Hello,

have you tried to post directly a speed in order to see if the robot accepts the command?

rostopic pub /cmd_vel geometry_msgs/Twist -r 10 -- '[0.2, 0.0, 0.0]' '[0.0, 0.0, 0.0]'

Please watch out the drone, I do not know which speeds are proper for you.

LATER EDIT

See this git. Sunk has made a wonderful job. I have used his solution, with some modifications at the robot I've work now.

https://github.com/sungjik/my_persona...

Good luck!

edit flag offensive delete link more

Comments

@Ktysai , thanks for your answer, actually it works that way, but how can I manage with the node that publish the commanded velocity, is there anything wrong with the sleep rate or the spining!!! Please help

rayane gravatar image rayane  ( 2019-08-26 05:42:15 -0500 )edit

@Ktysai thanks again. Actually I followed the same structure of the code in the link but the problem is solved by just send an empty message to /bebop/takeoff topic before running the node. I have another question!!! where to get the battery state so I can send an error message when the battery is low!!! Please help

rayane gravatar image rayane  ( 2019-08-27 11:10:59 -0500 )edit

Does this solution work for any set point of x, y for the robot. I mean if I want the robot to go to a set point x, y and the odom data is available from the odom topic. Will this above solution work ?

Vignesh_93 gravatar image Vignesh_93  ( 2021-03-23 05:40:18 -0500 )edit

Well, It worked for me at least.

rayane gravatar image rayane  ( 2021-03-23 05:58:44 -0500 )edit

Question Tools

3 followers

Stats

Asked: 2019-08-25 06:45:28 -0500

Seen: 7,673 times

Last updated: Aug 26 '19