back_joint_node.cpp
Go to the documentation of this file.
00001 #include <carl_dynamixel/back_joints_node.h>
00002 #include <math.h>
00003 
00004 back_joints::back_joints()
00005 {
00006   std::string servo_name;
00007   int num, id;
00008 
00009   ros::NodeHandle private_node_handle_("~");
00010   node.getParam("back_servos/num_servos", num);
00011   for (int s = 1; s <= num; s++)
00012   {
00013     std::stringstream ss;
00014     ss << s;
00015     std::string servo_num = ss.str();
00016     std::string param_id("back_servos/" + servo_num + "/id");
00017     std::string param_name("back_servos/" + servo_num + "/link_name");
00018     node.getParam(param_id, id);
00019     node.getParam(param_name, servo_name);
00020     back_servos[id] = servo_name;
00021   }
00022 
00023   //setup the subscriber
00024   asus_sub = node.subscribe("motor_states/back_port", 1000, &back_joints::joints, this);
00025 
00026   //setup the publisher
00027   joint_states_pub = node.advertise<sensor_msgs::JointState>("dynamixel_back", 1);
00028 
00029 }
00030 
00031 void back_joints::joints(const dynamixel_msgs::MotorStateList::ConstPtr& state)
00032 {
00033   sensor_msgs::JointState back_states;
00034   for (int s = 0; s < state->motor_states.size(); s++)
00035   {
00036     dynamixel_msgs::MotorState servo = state->motor_states[s];
00037     std::string name = back_servos[servo.id];
00038     if (name.size() == 0)
00039     {
00040       name = "UNDEFINED";
00041     }
00042     back_states.name.push_back(name);
00043     float servo_pos_deg = ((float)servo.position - 512.0) * 0.2929;
00044     back_states.position.push_back((servo_pos_deg * M_PI) / 180.0);
00045   }
00046   back_states.header.stamp = ros::Time::now();
00047   joint_states_pub.publish(back_states);
00048 }
00049 
00050 int main(int argc, char **argv)
00051 {
00052   //initialize the node
00053   ros::init(argc, argv, "back_joints_node");
00054 
00055   // initialize the joystick controller
00056   back_joints back;
00057 
00058   //main loop
00059   ros::Rate loop_rate(30);
00060   while (ros::ok())
00061   {
00062     ros::spinOnce();
00063     loop_rate.sleep();
00064   }
00065 
00066   return EXIT_SUCCESS;
00067 }


carl_dynamixel
Author(s): Chris Dunkers , David Kent
autogenerated on Thu Jun 6 2019 21:09:46