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

Problem subscribing to ax12_controller_core topic

asked 2011-05-21 13:32:58 -0500

kp3509 gravatar image

updated 2011-05-28 05:24:28 -0500

kwc gravatar image

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);

ros::spin();

return 0; }

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2011-05-21 14:29:46 -0500

arebgun gravatar image

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.

edit flag offensive delete link more

Comments

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.
kp3509 gravatar image kp3509  ( 2011-05-22 18:09:21 -0500 )edit
@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.
tfoote gravatar image tfoote  ( 2011-05-23 06:07:02 -0500 )edit

Question Tools

Stats

Asked: 2011-05-21 13:32:58 -0500

Seen: 277 times

Last updated: May 21 '11