Hello,
I would want to send PWM signal with an arduino in order to control motors. But, as a beginner, I am not exactly sure of what to do. I need first to publish "cmd_vel". Then I need to write a node in Arduino which subscribe to "cmd_vel", right ?
If so, I am not confident with the code I wrote :
include "ros.h"
include "geometry_msgs/Twist.h"
ros::NodeHandle nh;
void velCallback(const geometry_msgs::Twist& vel) {
geometry_msgs::Twist new_vel = vel;
// HERE I WANT TO USE vel TO DEFINE PWM }
void setup() {
nh.initNode();
ros::Subscriber<geometry_msgs::Twist> ("cmd_vel", &velCallback);
}
void loop()
{
nh.spinOnce();
delay(1);
}
It is the right way to do ? And is that code correct ?
PS : Sorry but I don't how to properly insert cpp code citation
Regards,
Matt
Originally posted by mattMGN on ROS Answers with karma: 78 on 2017-04-04
Post score: 0
Original comments
Comment by NEngelhard on 2017-04-04:
looks ok. How are the motors connected? What kind of motors do you use? Which driver hardware do you use?
Comment by tonybaltovski on 2017-04-04:
Do you have feedback? PWM isn't velocity control.
Comment by mattMGN on 2017-04-05:
I don't want to make feedback control yet. I just want to use cmd_vel, like analogWrite(cmd_vel.linear.x).
But currently when I run roscore, compile this arduino script, and run "rosrun rosserial_python serial_node.py /dev/ttyACM0". I just get this message : Connecting to /dev/ttyACM0 at 57600 baud
Comment by mattMGN on 2017-04-05:
Someone know why I am stuck to 'Connecting to /dev/ttyACM0 at 57600 baud' ? And why i can't see my node working with 'rostopic list' ?
Comment by DavidN on 2017-04-05:
Firstly , you should update the question with what you tried and any new error message you have. Secondly, can you check if the serial node is working and sending out data?