Go to the documentation of this file.00001 #include <ros/ros.h>
00002 #include <pr2_controllers_msgs/JointTrajectoryAction.h>
00003 #include <actionlib/client/simple_action_client.h>
00004
00005 typedef actionlib::SimpleActionClient< pr2_controllers_msgs::JointTrajectoryAction > TrajClient;
00006
00007 class SimpleMoveJoints
00008 {
00009 private:
00010
00011
00012 TrajClient* traj_client_;
00013 ros::Duration time_move;
00014 std::vector<double> pos;
00015
00016 public:
00018 SimpleMoveJoints()
00019 {
00020
00021 traj_client_ = new TrajClient("iri_ros_controller/joint_trajectory_action", true);
00022
00023
00024 while(!traj_client_->waitForServer(ros::Duration(5.0))){
00025 ROS_INFO("Waiting for the joint_trajectory_action server");
00026 }
00027 }
00028
00030 ~SimpleMoveJoints()
00031 {
00032 delete traj_client_;
00033 }
00034
00036 void startTrajectory(pr2_controllers_msgs::JointTrajectoryGoal goal)
00037 {
00038
00039 goal.trajectory.header.stamp = ros::Time::now() + ros::Duration(1.0);
00040 traj_client_->sendGoal(goal);
00041 }
00042
00043
00044 pr2_controllers_msgs::JointTrajectoryGoal armExtensionTrajectory()
00045 {
00046
00047 pr2_controllers_msgs::JointTrajectoryGoal goal;
00048
00049
00050 goal.trajectory.joint_names.push_back("j1_joint");
00051 goal.trajectory.joint_names.push_back("j2_joint");
00052 goal.trajectory.joint_names.push_back("j3_joint");
00053 goal.trajectory.joint_names.push_back("j4_joint");
00054 goal.trajectory.joint_names.push_back("j5_joint");
00055 goal.trajectory.joint_names.push_back("j6_joint");
00056 goal.trajectory.joint_names.push_back("j7_joint");
00057
00058
00059 goal.trajectory.points.resize(1);
00060
00061
00062 goal.trajectory.points[0].positions.resize(7);
00063 goal.trajectory.points[0].velocities.resize(7);
00064 goal.trajectory.points[0].accelerations.resize(7);
00065 for(int i=0; i < 7; ++i)
00066 {
00067 goal.trajectory.points[0].positions[i] = pos[i];
00068 goal.trajectory.points[0].velocities[i] = 0.0;
00069 goal.trajectory.points[0].accelerations[i] = 0.0;
00070 }
00071
00072
00073 goal.trajectory.points[0].time_from_start = time_move;
00074
00075
00076 return goal;
00077 }
00078
00080 actionlib::SimpleClientGoalState getState()
00081 {
00082 return traj_client_->getState();
00083 }
00084 void getTrajectory(int argc, char** argv)
00085 {
00086 if(argc < 8 || argc > 9)
00087 {
00088 ROS_FATAL("Error: The numbers of parameters out of bound");
00089 exit(1);
00090 }
00091 pos.resize(7);
00092 for(int i =1; i <=7; ++i) pos[i-1]=strtod(argv[i],NULL);
00093
00094 time_move= (argc == 9)?ros::Duration(strtod(argv[8],NULL)):ros::Duration(3.0);
00095
00096 }
00097
00098 };
00099
00100 int main(int argc, char** argv)
00101 {
00102
00103 ros::init(argc, argv, "simple_move_node");
00104 SimpleMoveJoints arm;
00105
00106 arm.getTrajectory(argc,argv);
00107 arm.startTrajectory(arm.armExtensionTrajectory());
00108
00109 while(!arm.getState().isDone() && ros::ok())
00110 {
00111 usleep(50000);
00112 }
00113 bool success = (arm.getState() == actionlib::SimpleClientGoalState::SUCCEEDED);
00114 if(success)
00115 ROS_INFO("Action finished: %s",arm.getState().toString().c_str());
00116 else
00117 ROS_INFO("Action failed: %s",arm.getState().toString().c_str());
00118 }