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 #include <unistd.h>
00058
00059
00060 #include <ros/ros.h>
00061 #include <actionlib/client/simple_action_client.h>
00062 #include <actionlib/client/terminal_state.h>
00063
00064
00065 #include <trajectory_msgs/JointTrajectory.h>
00066 #include <pr2_controllers_msgs/JointTrajectoryAction.h>
00067
00068
00069 #include <cob_srvs/Trigger.h>
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 int main(int argc, char** argv)
00092 {
00093
00094 ros::init(argc, argv, "camera_axis_test");
00095
00096
00097 ros::NodeHandle n;
00098
00099
00100 actionlib::SimpleActionClient<cob_actions::JointCommandAction> ac("joint_trajectory_action", true);
00101 ros::Publisher topic_pub_joint_commands = n.advertise<cob_msgs::JointCommand>("/head_controller/commands", 50);
00102
00103
00104
00105
00106
00107
00108
00109
00110 ros::ServiceClient srvClient_Init = n.serviceClient<cob_srvs::Trigger>("Init");
00111 ros::ServiceClient srvClient_Stop = n.serviceClient<cob_srvs::Trigger>("Stop");
00112
00113
00114
00115 bool srv_querry = false;
00116 int srv_execute = 1;
00117 std::string srv_errorMessage = "no error";
00118
00119 char c;
00120
00121
00122 while(n.ok())
00123 {
00124
00125 std::cout << "Choose service to test ([s]top, [i]nit, send[C]ommand, [e]xit, [J]ointCommand): ";
00126
00127 std::cin >> c;
00128
00129 switch(c)
00130 {
00131 case 's':
00132 {
00133 cob_srvs::Trigger srv;
00134 srv_querry = srvClient_Stop.call(srv);
00135 srv_execute = srv.response.success;
00136 srv_errorMessage = srv.response.errorMessage.data.c_str();
00137 break;
00138 }
00139
00140 case 'i':
00141 {
00142 cob_srvs::Trigger srv;
00143 srv_querry = srvClient_Init.call(srv);
00144 srv_execute = srv.response.success;
00145 srv_errorMessage = srv.response.errorMessage.data.c_str();
00146 break;
00147 }
00148
00149 case 'C':
00150 {
00151
00152
00153
00154 cob_actions::JointCommandGoal goal;
00155
00156 XmlRpc::XmlRpcValue command_param;
00157 cob_msgs::JointCommand command;
00158
00159 if (n.hasParam("JointCommand"))
00160 {
00161 n.getParam("JointCommand", command_param);
00162 }
00163 else
00164 {
00165 ROS_ERROR("Parameter JointCommand not set");
00166 }
00167
00168 for (int i = 0; i < command_param.size(); i++)
00169 {
00170 std::cout << "command " << i << " = " << command_param[i] <<std::endl;
00171 }
00172
00173 int command_nr;
00174 std::cout << command_param.size() << " commands available. Choose command number [0, 1, 2, ...]: ";
00175 std::cin >> command_nr;
00176 std::cout << std::endl;
00177
00178 if (command_nr < 0 || command_nr > command_param.size()-1)
00179 {
00180 ROS_ERROR("command_nr not in range. command_nr requested was %d and should be between 0 and %d",command_nr ,command_param.size()-1);
00181 break;
00182 }
00183
00184 command.positions.resize(command_param[command_nr].size());
00185 for (int i = 0; i<command_param[command_nr].size(); i++ )
00186 {
00187 command.positions[i] = (double)command_param[command_nr][i];
00188 }
00189
00190 goal.command = command;
00191 ac.sendGoal(goal);
00192
00193 std::cout << std::endl;
00194 srv_querry = true;
00195 srv_execute = 0;
00196 break;
00197 }
00198
00199 case 'J':
00200 {
00201 double target_pos;
00202 double max_speed;
00203 cob_msgs::JointCommand send_cmd;
00204 std::cout << "Enter a position value in Radians that should be driven to" << std::endl;
00205 std::cin >> target_pos;
00206 std::cout << "Enter a speed value" << std::endl;
00207 std::cin >> max_speed;
00208
00209 send_cmd.positions.resize(1);
00210 send_cmd.velocities.resize(1);
00211
00212 send_cmd.positions[0] = target_pos;
00213 send_cmd.velocities[0] = max_speed;
00214
00215 topic_pub_joint_commands.publish(send_cmd);
00216 break;
00217 }
00218
00219 case 'e':
00220 {
00221 ROS_INFO("exit. Shutting down node");
00222 std::cout << std::endl;
00223 return 0;
00224 break;
00225 }
00226
00227 default:
00228 {
00229 ROS_ERROR("invalid input, try again...");
00230 }
00231 }
00232
00233 if (!srv_querry)
00234 {
00235 ROS_ERROR("Failed to call service");
00236 }
00237 else
00238 {
00239 ROS_DEBUG("Service call succesfull");
00240
00241 if (srv_execute != 0)
00242 {
00243 ROS_ERROR("Service execution failed, errorMessage: %s", srv_errorMessage.c_str());
00244 }
00245 }
00246
00247 }
00248
00249 return 0;
00250 }