link_joints.cpp
Go to the documentation of this file.
1 
40 #include <ros/ros.h>
41 #include <string>
42 
43 // messages
44 #include <std_msgs/Float64.h>
45 #include <control_msgs/JointControllerState.h>
46 
48 std::string parent_name = "rh_ffj3";
50 std::string child_name = "rh_mfj3";
52 std::string controller_type = "_position_controller";
53 
54 // a ros subscriber (will be instantiated later on)
56 // a ros publisher (will be instantiated later on)
58 
65 void callback(const control_msgs::JointControllerStateConstPtr &msg)
66 {
67  // publish the message
68  std_msgs::Float64 command;
69  command.data = msg->set_point;
70  pub.publish(command);
71 
72  return;
73 }
74 
83 int main(int argc, char **argv)
84 {
85  // init the ros node
86  ros::init(argc, argv, "link_joints_example");
87  ros::NodeHandle node;
88 
94  sub = node.subscribe("sh_" + parent_name + controller_type + "/state", 2, callback);
95 
100  pub = node.advertise<std_msgs::Float64>("sh_" + child_name + controller_type + "/command", 2);
101 
102  // subscribe until interrupted.
103  while (ros::ok())
104  {
105  ros::spin();
106  }
107 
108  return 0;
109 }
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ROSLIB_DECL std::string command(const std::string &cmd)
ROSCPP_DECL bool ok()
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ROSCPP_DECL void spin()


sr_example
Author(s): Ugo Cupcic
autogenerated on Wed Oct 14 2020 04:05:12