Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "mh5l_traj.h"
00032
00033
00034 Fs100State *robotState;
00035 float joint_pos[6];
00036
00037
00038 Fs100Cmd *robotCommander;
00039
00040
00041 ros::Subscriber *sub_target;
00042 ros::ServiceServer *get_reset_srv;
00043 ros::Publisher *pub_joints;
00044 int retry = 1;
00045
00046 void joint_target_cb(const trajectory_msgs::JointTrajectoryPoint& input){
00047 float temp_pos[6],temp_vel[6],temp_time;
00048 for(int i=0;i<6;i++){
00049 temp_pos[i] = input.positions[i];
00050 temp_vel[i] = input.velocities[i];
00051 temp_time = input.time_from_start.toSec();
00052 }
00053 robotCommander->addPointToQueue(temp_pos,temp_vel,temp_time);
00054 }
00055
00056 bool reset_robot_trajectory(fs100_motoman::setReset::Request &req, fs100_motoman::setReset::Response &res){
00057 bool result;
00058 retry = 1;
00059 result = robotCommander->resetTrajectory(&retry);
00060 res.success = true;
00061 return true;
00062 }
00063
00064 void *get_data_func(void *arg){
00065 sensor_msgs::JointState js;
00066 js.position.resize(6);
00067 while( *((bool *) arg)){
00068 while(!robotState->getJointsUpdated(joint_pos));
00069 for(int i=0;i<6;i++){
00070 js.position[i] = joint_pos[i];
00071 }
00072 js.header.stamp = ros::Time::now();
00073 pub_joints->publish(js);
00074 }
00075
00076 }
00077
00078
00079
00080 int main(int argc, char **argv){
00081 char* robot_ip;
00082 ROS_INFO("argc %d",argc);
00083 if (argc > 1)
00084 {
00085 robot_ip = argv[1];
00086 }
00087 else
00088 {
00089 ROS_ERROR("invalid number of arguments, expected 1 (robot IP)");
00090 return 1;
00091 }
00092
00093
00094
00095 robotState = new Fs100State (robot_ip);
00096 robotCommander = new Fs100Cmd (robot_ip);
00097
00098 ros::init(argc, argv, "fs100_motoman");
00099 ros::NodeHandle nh("~mh5l");
00100
00101 sub_target = new ros::Subscriber;
00102 *sub_target = nh.subscribe("joint_target", 1, &joint_target_cb);
00103
00104 get_reset_srv = new ros::ServiceServer;
00105 *get_reset_srv = nh.advertiseService("reset_trajectory",&reset_robot_trajectory);
00106
00107 pub_joints = new ros::Publisher;
00108 *pub_joints = nh.advertise<sensor_msgs::JointState> ("joint_state", 1);
00109 float pos[6],current_pos[6];
00110 float vel[6];
00111 bool run_thread = true;
00112 pthread_t getthreadID;
00113
00114
00115
00116
00117
00118 if(robotState->init())
00119 {
00120 ROS_ERROR("Could not open socket");
00121 return 1;
00122 }
00123 if(robotState->makeConnect())
00124 {
00125 ROS_ERROR("Could not connect to robot controller state server");
00126 return 1;
00127 }
00128
00129
00130
00131
00132
00133 if(robotCommander->init())
00134 {
00135 ROS_ERROR("Could not open socket");
00136 return 1;
00137 }
00138 if(robotCommander->makeConnect())
00139 {
00140 ROS_ERROR("Could not connect to robot controller motion server");
00141 return 1;
00142 }
00143
00144
00145
00146 ros::Duration(2.0).sleep();
00147 if (robotCommander->start(1)){
00148 ROS_ERROR("Could not start trajectory on fs100, aborting");
00149 robotState->pgmClose();
00150 robotCommander->pgmClose();
00151 ros::shutdown();
00152 return 1;
00153 }
00154
00155
00156
00157
00158
00159 pthread_create(&getthreadID,NULL,get_data_func,&run_thread);
00160 ROS_INFO("Ready to recieve trajectory points");
00161 while(nh.ok()){
00162 ros::spinOnce();
00163 }
00164 run_thread = false;
00165 pthread_join(getthreadID,NULL);
00166 robotState->pgmClose();
00167 robotCommander->pgmClose();
00168
00169
00170
00171 ros::shutdown();
00172 return 0;
00173 }
00174