test_traj_vel_control.cpp
Go to the documentation of this file.
00001 
00002 #include <yumi_test_controllers.h>
00003 
00004 
00005 sensor_msgs::JointState joints_state;
00006 trajectory_msgs::JointTrajectory left_traj;
00007 trajectory_msgs::JointTrajectory right_traj;
00008 
00009 
00010 int numSubscribersConnected = 0;
00011 int num_joints = 14;
00012 int num_joints_arm = 7;
00013 bool left_command_sent = false;
00014 bool right_command_sent = false;
00015 
00016 ros::Publisher left_pub;
00017 ros::Publisher right_pub;
00018 ros::Subscriber sub;
00019 
00020 
00021 
00022 
00023 void left_vel_controller_callback(const ros::SingleSubscriberPublisher& pub)
00024 {
00025         ROS_INFO("New subscriber!");
00026     numSubscribersConnected++;
00027 }
00028 
00029 
00030 void right_vel_controller_callback(const ros::SingleSubscriberPublisher& pub)
00031 {
00032         ROS_INFO("New subscriber!");
00033     numSubscribersConnected++;
00034 }
00035 
00036 
00037 
00038 
00039 void joint_states_callback(const sensor_msgs::JointState &msg)
00040 {
00041         ROS_INFO("Joint states update!");
00042         joints_state.name = msg.name;
00043         joints_state.position = msg.position;
00044 
00045 
00046         if(!left_command_sent)
00047         {
00048                 trajectory_msgs::JointTrajectoryPoint p;
00049                 for (int i = 0; i < num_joints_arm; i++)
00050                 {
00051                 p.positions.push_back(joints_state.position[i]);
00052                 p.velocities.push_back(0.0);
00053                 p.accelerations.push_back(0.0);
00054                 p.time_from_start = ros::Duration(1.0);
00055                 }
00056 
00057                 int joint_test_idx = 4;
00058                 p.positions[joint_test_idx] = p.positions[joint_test_idx] - 0.2;
00059                 p.velocities[joint_test_idx] = -1.0;
00060 
00061                 left_traj.points.push_back(p);
00062                 left_traj.header.stamp = ros::Time::now();
00063 
00064                 cout << "Publishing command" << endl;
00065                 left_pub.publish(left_traj);
00066 
00067                 left_command_sent = true;
00068         }
00069 
00070         if(!right_command_sent)
00071         {
00072                 trajectory_msgs::JointTrajectoryPoint p;
00073                 for (int i = 0; i < num_joints_arm; i++)
00074                 {
00075                 p.positions.push_back(joints_state.position[i]);
00076                 p.velocities.push_back(0.0);
00077                 p.accelerations.push_back(0.0);
00078                 p.time_from_start = ros::Duration(1.0);
00079                 }
00080 
00081                 int joint_test_idx = 4;
00082                 p.positions[joint_test_idx] = p.positions[joint_test_idx] - 0.2;
00083                 p.velocities[joint_test_idx] = -1.0;
00084 
00085                 right_traj.points.push_back(p);
00086                 right_traj.header.stamp = ros::Time::now();
00087 
00088                 cout << "Publishing command" << endl;
00089                 right_pub.publish(right_traj);
00090 
00091                 right_command_sent = true;
00092         }
00093 }
00094 
00095 
00096 
00097 
00098 int main( int argc, char* argv[] )
00099 {
00100 
00101         ros::init(argc, argv, "test_joint_vel_control");
00102         ros::NodeHandle nh;
00103 
00104 
00105     ROS_INFO("test_join_vel_control node started!");
00106 
00107     left_traj.joint_names.push_back("yumi_joint_1_l");
00108     left_traj.joint_names.push_back("yumi_joint_2_l");
00109     left_traj.joint_names.push_back("yumi_joint_7_l");
00110     left_traj.joint_names.push_back("yumi_joint_3_l");
00111     left_traj.joint_names.push_back("yumi_joint_4_l");
00112     left_traj.joint_names.push_back("yumi_joint_5_l");
00113     left_traj.joint_names.push_back("yumi_joint_6_l");
00114     
00115         right_traj.joint_names.push_back("yumi_joint_1_r");
00116         right_traj.joint_names.push_back("yumi_joint_2_r");
00117         right_traj.joint_names.push_back("yumi_joint_7_r");
00118         right_traj.joint_names.push_back("yumi_joint_3_r");
00119         right_traj.joint_names.push_back("yumi_joint_4_r");
00120         right_traj.joint_names.push_back("yumi_joint_5_r");
00121         right_traj.joint_names.push_back("yumi_joint_6_r");
00122 
00123 
00124     sub = nh.subscribe("/yumi/joint_states", 1000, joint_states_callback);
00125 
00126     left_pub = nh.advertise<trajectory_msgs::JointTrajectory>("/yumi/joint_traj_vel_controller_l/command", 100, left_vel_controller_callback);
00127         right_pub = nh.advertise<trajectory_msgs::JointTrajectory>("/yumi/joint_traj_vel_controller_r/command", 100, right_vel_controller_callback);
00128 
00129         ros::spin();
00130 
00131 
00132         return EXIT_SUCCESS;
00133 }
00134 


yumi_test_controllers
Author(s): Yoshua Nava
autogenerated on Sun Jul 2 2017 03:15:52