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
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 #include <ros/ros.h>
00062 #include <actionlib/client/simple_action_client.h>
00063 #include <actionlib/client/terminal_state.h>
00064
00065
00066 #include <trajectory_msgs/JointTrajectory.h>
00067 #include <pr2_controllers_msgs/JointTrajectoryAction.h>
00068
00069
00070 #include <cob_srvs/Trigger.h>
00071 #include <cob_srvs/SetOperationMode.h>
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 int main(int argc, char** argv)
00093 {
00094
00095 ros::init(argc, argv, "powercube_chain_test");
00096
00097
00098 ros::NodeHandle n;
00099
00100
00101
00102 actionlib::SimpleActionClient<pr2_controllers_msgs::JointTrajectoryAction> ac("joint_trajectory_action", true);
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 ros::ServiceClient srvClient_Init = n.serviceClient<cob_srvs::Trigger>("Init");
00113 ros::ServiceClient srvClient_Stop = n.serviceClient<cob_srvs::Trigger>("Stop");
00114 ros::ServiceClient srvClient_Recover = n.serviceClient<cob_srvs::Trigger>("Recover");
00115 ros::ServiceClient srvClient_SetOperationMode = n.serviceClient<cob_srvs::SetOperationMode>("SetOperationMode");
00116
00117
00118 bool srv_querry = false;
00119 bool srv_execute = false;
00120 std::string srv_errorMessage = "no error";
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 char c;
00156
00157
00158 while(n.ok())
00159 {
00160
00161 std::cout << "Choose service to test ([s]top, [i]nit, [r]ecover, setOperation[M]ode, send[C]ommand, [e]xit): ";
00162
00163
00164 std::cin >> c;
00165
00166 switch(c)
00167 {
00168 case 's':
00169 {
00170 cob_srvs::Trigger srv;
00171 srv_querry = srvClient_Stop.call(srv);
00172 srv_execute = srv.response.success.data;
00173 srv_errorMessage = srv.response.error_message.data.c_str();
00174 break;
00175 }
00176
00177 case 'i':
00178 {
00179 cob_srvs::Trigger srv;
00180 srv_querry = srvClient_Init.call(srv);
00181 srv_execute = srv.response.success.data;
00182 srv_errorMessage = srv.response.error_message.data.c_str();
00183 break;
00184 }
00185
00186 case 'r':
00187 {
00188 cob_srvs::Trigger srv;
00189 srv_querry = srvClient_Recover.call(srv);
00190 srv_execute = srv.response.success.data;
00191 srv_errorMessage = srv.response.error_message.data.c_str();
00192 break;
00193 }
00194
00195 case 'M':
00196 {
00197 cob_srvs::SetOperationMode srv;
00198
00199 std::cout << "Choose operation mode ([v] = velocity controll, [p] = position controll): ";
00200 std::cin >> c;
00201 if (c == 'v')
00202 {
00203 srv.request.operation_mode.data = "velocity";
00204 }
00205 else if (c == 'p')
00206 {
00207 srv.request.operation_mode.data = "position";
00208 }
00209 else
00210 {
00211 srv.request.operation_mode.data = "none";
00212 }
00213 ROS_INFO("changing operation mode to: %s controll", srv.request.operation_mode.data.c_str());
00214
00215
00216 srv_querry = srvClient_SetOperationMode.call(srv);
00217 srv_execute = srv.response.success.data;
00218 srv_errorMessage = srv.response.error_message.data.c_str();
00219 break;
00220 }
00221
00222 case 'C':
00223 {
00224
00225
00226
00227 pr2_controllers_msgs::JointTrajectoryGoal goal;
00228
00229
00230 XmlRpc::XmlRpcValue JointNames_param;
00231 std::vector<std::string> JointNames;
00232 ROS_INFO("getting JointNames from parameter server");
00233 if (n.hasParam("JointNames"))
00234 {
00235 n.getParam("JointNames", JointNames_param);
00236 }
00237 else
00238 {
00239 ROS_ERROR("Parameter JointNames not set");
00240 }
00241 JointNames.resize(JointNames_param.size());
00242 for (int i = 0; i<JointNames_param.size(); i++ )
00243 {
00244 JointNames[i] = (std::string)JointNames_param[i];
00245 }
00246 std::cout << "JointNames = " << JointNames_param << std::endl;
00247
00248 XmlRpc::XmlRpcValue traj_param;
00249 trajectory_msgs::JointTrajectory traj;
00250
00251 if (n.hasParam("Trajectories"))
00252 {
00253 n.getParam("Trajectories", traj_param);
00254 }
00255 else
00256 {
00257 ROS_ERROR("Parameter Trajectories not set");
00258 }
00259
00260 for (int i = 0; i < traj_param.size(); i++)
00261 {
00262 std::cout << "trajectory " << i << " = " << traj_param[i] <<std::endl;
00263 }
00264
00265 int traj_nr;
00266 std::cout << traj_param.size() << " trajectories available. Choose trajectory number [0, 1, 2, ...]: ";
00267 std::cin >> traj_nr;
00268 std::cout << std::endl;
00269
00270 if (traj_nr < 0 || traj_nr > traj_param.size()-1)
00271 {
00272 ROS_ERROR("traj_nr not in range. traj_nr requested was %d and should be between 0 and %d",traj_nr ,traj_param.size()-1);
00273 break;
00274 }
00275
00276 ROS_DEBUG("trajectory %d of %d",traj_nr,traj_param.size());
00277 traj.header.stamp = ros::Time::now();
00278 traj.joint_names = JointNames;
00279 traj.points.resize(traj_param[traj_nr].size());
00280 for (int j = 0; j<traj_param[traj_nr].size(); j++ )
00281 {
00282 ROS_DEBUG(" point %d of %d",j,traj_param[traj_nr].size());
00283 traj.points[j].positions.resize(traj_param[traj_nr][j].size());
00284 for (int k = 0; k<traj_param[traj_nr][j].size(); k++ )
00285 {
00286 ROS_DEBUG(" pos value %d of %d = %f",k,traj_param[traj_nr][j].size(),(double)traj_param[traj_nr][j][k]);
00287 traj.points[j].positions[k] = (double)traj_param[traj_nr][j][k];
00288 }
00289
00290 ros::Duration duration(3);
00291 traj.points[j].time_from_start = duration*(j+1);
00292 }
00293
00294 goal.trajectory = traj;
00295 ac.sendGoal(goal);
00296
00297 std::cout << std::endl;
00298 srv_querry = true;
00299 srv_execute = true;
00300 break;
00301 }
00302
00303 case 'e':
00304 {
00305 ROS_INFO("exit. Shutting down node");
00306 std::cout << std::endl;
00307 return 0;
00308 break;
00309 }
00310
00311 default:
00312 {
00313 std::cout << "ERROR: invalid input, try again..." << std::endl << std::endl;
00314 }
00315 }
00316
00317 if (!srv_querry)
00318 {
00319 ROS_ERROR("Failed to call service");
00320 }
00321 else
00322 {
00323 ROS_INFO("Service call succesfull");
00324
00325 if (srv_execute == false)
00326 {
00327 ROS_ERROR("Service execution failed. Error message: %s", srv_errorMessage.c_str());
00328 }
00329 }
00330
00331 }
00332
00333 return 0;
00334 }