Rosanswers logo

Hi, I am new to ros and I have a dynamixel ax12 driver publishing position information and I want to access that info and put into a variable that I can use for a transform. I have done the publisher and listener tutorial successfully, but I am having trouble getting it to work with the dynamixel. Specifically I am unsure of how to change the paramaters in void since the motor doesnt seem to use std_msgs. Any suggestions? Below are the topic data and what I have for my listener.cpp program so far.

rostopic list= /motor_states/ttyUSB0

/motor_states/ttyUSB0 [ax12_driver_core/MotorStateList] 1 publisher

rosmsg show ax12_driver_core/MotorStateList

ax12_driver_core/MotorState[] motor_states

float64 timestamp

int32 id

int32 goal

int32 position

int32 error

int32 speed

float64 load

float64 voltage

int32 temperature

bool moving

============Begin Listener.cpp=================

#include "ros/ros.h"

#include "std_msgs/String"

void motorCallback(const std_msgs::String::ConstPtr& msg)

{ ROS_INFO("I heard: [%s]", msg->data.c_str()); }

int main(int argc, char **argv) {

ros::init(argc, argv, "listener");

ros::NodeHandle n;

ros::Subscriber sub = n.subscribe("motor_states/ttyUSB0", 1000, motorCallback);


return 0; }

Originally posted by kp3509 on ROS Answers with karma: 11 on 2011-05-21

Post score: 0


1 Answer 1


Rosanswers logo

Well, you are trying to subscribe to a topic that publishes ax12_driver_core/MotorStateList, so your callback needs to accept that instead of std_msgs/String type. For that you need to have include "ax12_driver_core/MotorStateList" and replace const std_msgs::String::ConstPtr& in callback function with const ax12_driver_core::MotorStateList::ConstPtr&. Also make sure that your manifest.xml has a dependency on ax12_driver_core package.

Originally posted by arebgun with karma: 2121 on 2011-05-21

This answer was ACCEPTED on the original site

Post score: 1

Original comments

Comment by tfoote on 2011-05-23:
@kp3509 please write this up in a separate question. I've marked this question as answered for you. It's good practice to have complete but concise questions and concrete answers for others who will come along and try to use your question as a reference.

Comment by kp3509 on 2011-05-22:
Thank you, that was a big help, I am able to compile the code now. I have one more question, how do I use the position value that I am subscribing to in my code? So far I have: void motorchatterCallback(const ax12_driver_core::MotorStateList::ConstPtr& msg) { //ROS_INFO("I heard: [%s]", msg->data.c_str()); } The commented part in void would display the data that it got from the subribed topic, but I am unsure of what to replace "msg->data.c_str()" with.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.