Go to the documentation of this file.00001 #include "wam_test.h"
00002
00003
00004
00005 WamTest::WamTest() {
00006
00007 this->gocenter = true;
00008 this->targetid = 0;
00009
00010 this->numtargets = 10;
00011 this->tfMessage_msg.transforms.resize(numtargets+2);
00012 this->angles.resize(5);
00013 this->angles[0] = 0.0;
00014 this->angles[1] = M_PI/4.0;
00015 this->angles[2] = 3.0*M_PI/4.0;
00016 this->angles[3] = 9.0/8.0*M_PI;
00017 this->angles[4] = 13.0/8.0*M_PI;
00018
00019 std::string port_name;
00020
00021
00022 port_name = ros::names::append(ros::this_node::getName(), "tf");
00023 this->tf_publisher = this->nh_.advertise<tf::tfMessage>(port_name, 5);
00024 port_name = ros::names::append(ros::this_node::getName(), "pose_matrix");
00025 this->tf_publisher = this->nh_.advertise<tf::tfMessage>(port_name, 5);
00026
00027
00028 port_name = ros::names::append(ros::this_node::getName(), "pose");
00029 this->pose_subscriber = this->nh_.subscribe(port_name, 5, &WamTest::pose_callback, this);
00030 port_name = ros::names::append(ros::this_node::getName(), "joint_states");
00031 this->joint_states_subscriber = this->nh_.subscribe(port_name, 5, &WamTest::joint_states_callback, this);
00032
00033
00034
00035
00036 port_name = ros::names::append(ros::this_node::getName(), "pose_move2");
00037 pose_move2_client = this->nh_.serviceClient<iri_wam_common_msgs::pose_move>(port_name);
00038
00039 port_name = ros::names::append(ros::this_node::getName(), "pose_move");
00040 pose_move_client = this->nh_.serviceClient<iri_wam_common_msgs::pose_move>(port_name);
00041 port_name = ros::names::append(ros::this_node::getName(), "joints_move");
00042 joint_move_client = this->nh_.serviceClient<iri_wam_common_msgs::joints_move>(port_name);
00043
00044
00045
00046
00047 }
00048
00049 void WamTest::mainLoop(void)
00050 {
00051
00052
00053 tf::StampedTransform transform;
00054 geometry_msgs::TransformStamped msg;
00055 std::ostringstream oss;
00056 std::ostringstream oss2;
00057 std::ostringstream oss3;
00058 std::string targetname("target");
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 this->tfMessage_msg.transforms[0].header.stamp = ros::Time::now();
00085 this->tfMessage_msg.transforms[0].header.frame_id = "wam0";
00086 this->tfMessage_msg.transforms[0].child_frame_id = "central";
00087 this->tfMessage_msg.transforms[0].transform.rotation = tf::createQuaternionMsgFromRollPitchYaw(0,0,0);
00088
00089 this->tfMessage_msg.transforms[0].transform.translation.x = 0.55;
00090 this->tfMessage_msg.transforms[0].transform.translation.y = 0.2;
00091 this->tfMessage_msg.transforms[0].transform.translation.z = 0.1;
00092
00093 this->tfMessage_msg.transforms[1].header.stamp = ros::Time::now();
00094 this->tfMessage_msg.transforms[1].header.frame_id = "central";
00095 this->tfMessage_msg.transforms[1].child_frame_id = "target0b";
00096 this->tfMessage_msg.transforms[1].transform.rotation = tf::createQuaternionMsgFromRollPitchYaw(0,0,0);
00097
00098 this->tfMessage_msg.transforms[1].transform.translation.x = 0.0;
00099 this->tfMessage_msg.transforms[1].transform.translation.y = 0.0;
00100 this->tfMessage_msg.transforms[1].transform.translation.z = 0.3;
00101
00102 for(uint i=2;i<tfMessage_msg.transforms.size();i+=2){
00103 this->tfMessage_msg.transforms[i].header.stamp = ros::Time::now();
00104 this->tfMessage_msg.transforms[i].header.frame_id = "central";
00105 std::ostringstream oss;
00106 oss << targetname << i/2;
00107 this->tfMessage_msg.transforms[i].child_frame_id = oss.str();
00108 this->tfMessage_msg.transforms[i].transform.rotation = tf::createQuaternionMsgFromRollPitchYaw(angles[(i+1)/2%5],0,0);
00109 this->tfMessage_msg.transforms[i].transform.translation.x = 0.0;
00110 this->tfMessage_msg.transforms[i].transform.translation.y = 0.0;
00111 this->tfMessage_msg.transforms[i].transform.translation.z = 0.0;
00112
00113 this->tfMessage_msg.transforms[i+1].header.stamp = ros::Time::now();
00114 this->tfMessage_msg.transforms[i+1].header.frame_id = oss.str();
00115 oss << "b";
00116 this->tfMessage_msg.transforms[i+1].child_frame_id = oss.str();
00117 this->tfMessage_msg.transforms[i+1].transform.rotation = tf::createQuaternionMsgFromRollPitchYaw(0,0,0);
00118
00119 this->tfMessage_msg.transforms[i+1].transform.translation.x = 0.0;
00120 this->tfMessage_msg.transforms[i+1].transform.translation.y = 0.0;
00121 this->tfMessage_msg.transforms[i+1].transform.translation.z = 0.3;
00122 }
00123
00124 tf::tfMessage tfMessage_msgaux(this->tfMessage_msg);
00125 this->tf_publisher.publish(tfMessage_msgaux);
00126
00127 oss3 << targetname << targetid << "b";
00128 calculate_error(oss3.str());
00129
00130 if(gocenter){
00131 gocenter = false;
00132 ROS_INFO("Going to central");
00133 try{
00134 listener.lookupTransform("wam0", "central", ros::Time(0), transform);
00135 tf::transformStampedTFToMsg(transform,msg);
00136
00138 pose_move_srv.request.pose.orientation.y = msg.transform.rotation.x;
00139 pose_move_srv.request.pose.orientation.z = msg.transform.rotation.y;
00140 pose_move_srv.request.pose.orientation.w = msg.transform.rotation.z;
00141 pose_move_srv.request.pose.orientation.x = msg.transform.rotation.w;
00142
00143 pose_move_srv.request.pose.position.x = msg.transform.translation.x;
00144 pose_move_srv.request.pose.position.y = msg.transform.translation.y;
00145 pose_move_srv.request.pose.position.z = msg.transform.translation.z;
00146 std::cout << "moving to:" << msg << std::endl;
00147 sleep(1);
00148
00149 if (pose_move2_client.call(pose_move_srv)) {
00150 ROS_INFO("pose_move2: %d", pose_move_srv.response.success);
00151 calculate_error("central");
00152 } else {
00153 ROS_ERROR("Failed to call service pose_move2");
00154 }
00155 } catch (tf::TransformException ex){
00156 ROS_ERROR("%s",ex.what());
00157 }
00158 }else{
00159 gocenter = true;
00160 targetid++;
00161 targetid = targetid%6;
00162 oss2 << targetname << targetid << "b";
00163 ROS_INFO("Going to %s",oss2.str().c_str());
00164 try{
00165 listener.lookupTransform("wam0", oss2.str(), ros::Time(0), transform);
00166
00167
00168
00169 tf::transformStampedTFToMsg(transform,msg);
00170 pose_move_srv.request.pose.orientation.y = msg.transform.rotation.x;
00171 pose_move_srv.request.pose.orientation.z = msg.transform.rotation.y;
00172 pose_move_srv.request.pose.orientation.w = msg.transform.rotation.z;
00173 pose_move_srv.request.pose.orientation.x = msg.transform.rotation.w;
00174
00175 pose_move_srv.request.pose.position.x = msg.transform.translation.x;
00176 pose_move_srv.request.pose.position.y = msg.transform.translation.y;
00177 pose_move_srv.request.pose.position.z = msg.transform.translation.z;
00178 std::cout << "moving to:" << msg << std::endl;
00179 sleep(1);
00180
00181 if (pose_move2_client.call(pose_move_srv)) {
00182 ROS_INFO("pose_move2: %d", pose_move_srv.response.success);
00183 } else {
00184 ROS_ERROR("Failed to call service pose_move2");
00185 }
00186 } catch (tf::TransformException ex){
00187 ROS_ERROR("%s",ex.what());
00188 }
00189 }
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206 }
00207
00208
00209 void WamTest::pose_callback(const geometry_msgs::PoseStamped::ConstPtr& msg)
00210 {
00211
00212
00213 }
00214 void WamTest::joint_states_callback(const sensor_msgs::JointState::ConstPtr& msg)
00215 {
00216
00217
00218
00219 }
00220
00221
00222
00223
00224
00225
00226
00227 void WamTest::calculate_error(std::string target) {
00228
00229 tf::StampedTransform transform;
00230 geometry_msgs::TransformStamped msg;
00231 try{
00232 listener.lookupTransform("wam7", target, ros::Time(0), transform);
00233 tf::transformStampedTFToMsg(transform,msg);
00234 std::cout << "transform error " << msg << std::endl;
00235 } catch (tf::TransformException ex){
00236 ROS_ERROR("%s",ex.what());
00237 }
00238 }
00239
00240
00241 int main(int argc, char** argv) {
00242 ros::init(argc, argv, "wam_test");
00243 WamTest wam_test;
00244 ros::Rate loop_rate(10);
00245 while(ros::ok()){
00246
00247 ros::spinOnce();
00248 loop_rate.sleep();
00249 }
00250 }