Ask Your Question
0

Can I use arduino to subscribe /cmd_vel?

asked 2019-11-07 08:32:15 -0600

Crowdeal gravatar image

updated 2019-11-09 09:35:52 -0600

jayess gravatar image

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!

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2019-11-07 09:30:15 -0600

wintermute gravatar image

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

edit flag offensive delete link more

Comments

But i want to know how to publish it to arduino

Crowdeal gravatar imageCrowdeal ( 2019-11-07 21:48:52 -0600 )edit

Should i use rosserial?

Crowdeal gravatar imageCrowdeal ( 2019-11-07 21:50:23 -0600 )edit

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..., 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/2970...

Best regards, C.A.

wintermute gravatar imagewintermute ( 2019-11-08 01:09:46 -0600 )edit
0

answered 2019-11-09 04:20:53 -0600

parzival gravatar image

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)
edit flag offensive delete link more

Comments

Can you give me the detailed code ?

I dont really understand about this

thank you for your help!

Crowdeal gravatar imageCrowdeal ( 2019-11-10 00:10:24 -0600 )edit

thank you i did it

Crowdeal gravatar imageCrowdeal ( 2019-11-10 01:11:04 -0600 )edit

but i have another problem

can i println the linear.x on my arduino serial

it seems to appear error

Crowdeal gravatar imageCrowdeal ( 2019-11-10 01:12:08 -0600 )edit
1

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

use e.g

nh.loginfo("Hello world");

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

bob-ROS gravatar imagebob-ROS ( 2019-11-11 02:51:40 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2019-11-07 08:32:15 -0600

Seen: 45 times

Last updated: Nov 09