Robotics StackExchange | Archived questions

Can I use arduino to subscribe /cmd_vel?

Hello ros forum!

I am new to ros

sorry for my bad english

I follow navigation_tutorial and it seems to work

How can i publish /cmd_vel to my arduino ?

I need to control my little car !

please help!

Asked by Crowdeal on 2019-11-07 09:32:15 UTC

Comments

Answers

/cmd_vel is a subscriber itself so you have to publish to it.

provided that you setup everything right, (rosserial), and when you do a rostopic list, you see /cmd_vel in the list of topics, you type

rostopic pub /cmd_vel geometry_msgs/Twist and hit tab, twice it will show:

rostopic pub /cmd_vel geometry_msgs/Twist "linear: x: 0.0 y: 0.0 z: 0.0 angular: x: 0.0 y: 0.0 z: 0.0"

Modify the linear speed, twist.linear.x to be 0.5 for example, and twist.angular.z for the angular speed, for example 0.4 and it will make the robot move in a circle, with speed of 0.5m/s.

Hope this helps, -C.A.

Asked by wintermute on 2019-11-07 10:30:15 UTC

Comments

But i want to know how to publish it to arduino

Asked by Crowdeal on 2019-11-07 22:48:52 UTC

Should i use rosserial?

Asked by Crowdeal on 2019-11-07 22:50:23 UTC

Yes, the above scheme publishes to arduino. /cmd_vel is a subscriber running on the arduino. you publish to it, from anywhere.

For example look at this tutorial: http://wiki.ros.org/rosserial_arduino/Tutorials/Blink, this code runs on the arduino, subscribes to /toggle_led - when someone publishes to /toggle_led, either from command line, or from a python script, the /toggle_led subscriber takes that messages, and turns on/off the led.

Instead of /toogle_led make a subsriber /cmd_vel with Twist message type. There should be code available if you search for it.

This could be useful: https://answers.ros.org/question/29706/twist-message-example-and-cmd_vel/

Best regards, C.A.

Asked by wintermute on 2019-11-08 02:09:46 UTC

Yes you can use an arduino to subscribe to cmd_vel topic, or any topic for that matter. Just include the necessary header file. In your case, that would be:

#include <geometry_msgs/Twist.h>

and then initialise the subscriber as below:

ros::Subscriber<geometry_msgs/Twist> sub("cmd_vel", &callback_func)

Asked by parzival on 2019-11-09 05:20:53 UTC

Comments

Can you give me the detailed code ?

I dont really understand about this

thank you for your help!

Asked by Crowdeal on 2019-11-10 01:10:24 UTC

thank you i did it

Asked by Crowdeal on 2019-11-10 02:11:04 UTC

but i have another problem

can i println the linear.x on my arduino serial

it seems to appear error

Asked by Crowdeal on 2019-11-10 02:12:08 UTC

See this, http://wiki.ros.org/rosserial_arduino/Tutorials/Logging

use e.g

nh.loginfo("Hello world");

I believe this should appear as outputs in your rosserial node.

Asked by bob-ROS on 2019-11-11 03:51:40 UTC