00001 #include "ros/ros.h"
00002 #include "std_msgs/UInt8MultiArray.h"
00003 #include "std_srvs/Empty.h"
00004 #include "visualization_msgs/MarkerArray.h"
00005 #include "visualization_msgs/Marker.h"
00006 #include "geometry_msgs/PoseWithCovarianceStamped.h"
00007 #include "tf/transform_broadcaster.h"
00008 #include "tf/transform_listener.h"
00009 #include "bipedRobin_msgs/StepTarget3DService.h"
00010 #include "bipedRobin_msgs/SetModeService.h"
00011 #include "bipedRobin_msgs/SetParamService.h"
00012
00013
00014
00015
00016
00017 #define DEFAULT_VARIABLE_NUMBER 150
00018 #define DEFAULT_WORDLENGTH 40
00019
00020
00021 struct DataPoint
00022 {
00023 char name[DEFAULT_WORDLENGTH];
00024 long timestamp;
00025 double value;
00026 };
00027
00028 struct DataPointArray
00029 {
00030 struct DataPoint dataPoint[DEFAULT_VARIABLE_NUMBER];
00031 int length;
00032 };
00033
00034 ros::Publisher rtai_data;
00035 int old_left_right = 1;
00036 unsigned int stepCounter = 0;
00037
00038
00039 bool sendParameterToRobot (const char* name, double value) {
00040 struct DataPointArray data;
00041
00042 ROS_INFO("Robot Parameter \"%s\" will be set to value: %f.", name, value);
00043
00044
00045 strcpy(data.dataPoint[0].name, name); data.dataPoint[0].value = value;
00046
00047 data.length = 1;
00048
00049 for (int i=0; i<data.length; i++) data.dataPoint[i].timestamp = 0xffff;
00050
00051
00052 std_msgs::UInt8MultiArray msgOut;
00053
00054 for (unsigned int i=0; i<sizeof(DataPointArray); i++) {
00055 msgOut.data.push_back(((char*)&data)[i]);
00056 }
00057 rtai_data.publish(msgOut);
00058
00059 return true;
00060 }
00061
00062 bool footstepCallback(bipedRobin_msgs::StepTarget3DService::Request &req, bipedRobin_msgs::StepTarget3DService::Response &res) {
00063 struct DataPointArray data;
00064
00065 double roll = 0;
00066 double pitch = 0;
00067 double yaw = 0;
00068 btMatrix3x3(btQuaternion(req.step.pose.orientation.x, req.step.pose.orientation.y, req.step.pose.orientation.z, req.step.pose.orientation.w)).getEulerYPR(yaw, pitch, roll);
00069
00070 strcpy(data.dataPoint[0].name, "srv_desiredStep_flag"); data.dataPoint[0].value = 2;
00071
00072 if(old_left_right%2 == req.step.leg){
00073 ROS_ERROR("Wrong foot received");
00074 return 0;
00075 }
00076
00077 if(req.step.leg == 0){
00078 strcpy(data.dataPoint[1].name, "srv_desiredStep_feet"); data.dataPoint[1].value = 2;
00079 old_left_right = 2;
00080 } else {
00081 strcpy(data.dataPoint[1].name, "srv_desiredStep_feet"); data.dataPoint[1].value = 1;
00082 old_left_right = 1;
00083 }
00084 strcpy(data.dataPoint[2].name, "srv_desiredStep_x"); data.dataPoint[2].value = req.step.pose.position.x;
00085 strcpy(data.dataPoint[3].name, "srv_desiredStep_y"); data.dataPoint[3].value = req.step.pose.position.y;
00086 strcpy(data.dataPoint[4].name, "srv_desiredStep_z"); data.dataPoint[4].value = req.step.pose.position.z;
00087 strcpy(data.dataPoint[5].name, "srv_desiredStep_alpha"); data.dataPoint[5].value = roll;
00088 strcpy(data.dataPoint[6].name, "srv_desiredStep_beta"); data.dataPoint[6].value = pitch;
00089 strcpy(data.dataPoint[7].name, "srv_desiredStep_gamma"); data.dataPoint[7].value = yaw;
00090
00091 data.length = 8;
00092
00093
00094 for (int i=0; i<data.length; i++) data.dataPoint[i].timestamp = 0xffff;
00095
00096
00097 std_msgs::UInt8MultiArray msgOut;
00098
00099 for (unsigned int i=0; i<sizeof(DataPointArray); i++) {
00100 msgOut.data.push_back(((char*)&data)[i]);
00101 }
00102 rtai_data.publish(msgOut);
00103
00104 return true;
00105 }
00106
00107 bool footstepIncCallback(bipedRobin_msgs::StepTarget3DService::Request &req, bipedRobin_msgs::StepTarget3DService::Response &res) {
00108 ROS_INFO("Passing incremental step to robot");
00109 struct DataPointArray data;
00110
00111 double roll;
00112 double pitch;
00113 double yaw;
00114 btMatrix3x3(btQuaternion(req.step.pose.orientation.x, req.step.pose.orientation.y, req.step.pose.orientation.z, req.step.pose.orientation.w)).getEulerYPR(yaw, pitch, roll);
00115
00116 if(req.step.leg == 0){
00117 strcpy(data.dataPoint[0].name, "srv_desiredStepInc_feet"); data.dataPoint[0].value = 2;
00118 } else {
00119 strcpy(data.dataPoint[0].name, "srv_desiredStepInc_feet"); data.dataPoint[0].value = 1;
00120 }
00121 strcpy(data.dataPoint[1].name, "srv_desiredStepInc_x"); data.dataPoint[1].value = req.step.pose.position.x;
00122 strcpy(data.dataPoint[2].name, "srv_desiredStepInc_y"); data.dataPoint[2].value = req.step.pose.position.y;
00123 strcpy(data.dataPoint[3].name, "srv_desiredStepInc_z"); data.dataPoint[3].value = req.step.pose.position.z;
00124 strcpy(data.dataPoint[4].name, "srv_desiredStepInc_alpha"); data.dataPoint[4].value = roll;
00125 strcpy(data.dataPoint[5].name, "srv_desiredStepInc_beta"); data.dataPoint[5].value = pitch;
00126 strcpy(data.dataPoint[6].name, "srv_desiredStepInc_gamma"); data.dataPoint[6].value = yaw;
00127
00128 strcpy(data.dataPoint[7].name, "srv_executeStep"); data.dataPoint[7].value = ++stepCounter;
00129 ROS_INFO("This was Step Number %d", stepCounter);
00130
00131 data.length = 8;
00132
00133
00134 for (int i=0; i<data.length; i++) data.dataPoint[i].timestamp = 0xffff;
00135
00136
00137 std_msgs::UInt8MultiArray msgOut;
00138
00139 for (unsigned int i=0; i<sizeof(DataPointArray); i++) {
00140 msgOut.data.push_back(((char*)&data)[i]);
00141 }
00142 rtai_data.publish(msgOut);
00143
00144 return true;
00145 }
00146
00147 bool acknowledgeCallback(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res) {
00148 ROS_INFO("Acknowledge Service called");
00149 return sendParameterToRobot("srv_acknowledgement", rand()%100);
00150 }
00151
00152 bool referenceCallback(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res) {
00153 ROS_INFO("Reference Service called");
00154 return sendParameterToRobot("srv_referenceDrives", rand()%100);
00155 }
00156
00157 bool stopCallback(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res) {
00158 ROS_INFO("Stop Service called");
00159 return sendParameterToRobot("srv_emergencyStop", rand()%100);
00160 }
00161
00162 bool resetCallback(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res) {
00163 ROS_INFO("Reset Internal State Service called");
00164 return sendParameterToRobot("srv_resetInternalState", rand()%100);
00165 }
00166
00167 bool setModeCallback(bipedRobin_msgs::SetModeService::Request &req, bipedRobin_msgs::SetModeService::Response &res) {
00168 ROS_INFO("Set Mode Service called. Desired Mode is set to %d", req.desiredMode);
00169 return sendParameterToRobot("srv_setDesiredMotionMode", req.desiredMode);
00170 }
00171
00172 bool setParamCallback(bipedRobin_msgs::SetParamService::Request &req, bipedRobin_msgs::SetParamService::Response &res) {
00173 ROS_INFO("Set Parameter Service called.");
00174 return sendParameterToRobot(req.parameterName.c_str(), req.parameterValue);
00175 }
00176
00177 bool initialstep0Callback(std_srvs::Empty::Request &req, std_srvs::Empty::Request &res) {
00178 ROS_INFO("Initialstep Service called");
00179 struct DataPointArray data;
00180 strcpy(data.dataPoint[0].name, "srv_desiredStep_flag"); data.dataPoint[0].value = 1;
00181 strcpy(data.dataPoint[1].name, "srv_desiredStep_feet"); data.dataPoint[1].value = 1;
00182 strcpy(data.dataPoint[2].name, "srv_desiredStep_x"); data.dataPoint[2].value = 0;
00183 strcpy(data.dataPoint[3].name, "srv_desiredStep_y"); data.dataPoint[3].value = 0;
00184 strcpy(data.dataPoint[4].name, "srv_desiredStep_z"); data.dataPoint[4].value = 0;
00185 strcpy(data.dataPoint[5].name, "srv_desiredStep_alpha"); data.dataPoint[5].value = 0;
00186 strcpy(data.dataPoint[6].name, "srv_desiredStep_beta"); data.dataPoint[6].value = 0;
00187 strcpy(data.dataPoint[7].name, "srv_desiredStep_gamma"); data.dataPoint[7].value = 0;
00188 data.length = 8;
00189
00190 for (int i=0; i<data.length; i++) data.dataPoint[i].timestamp = 0xffff;
00191
00192 std_msgs::UInt8MultiArray msgOut;
00193
00194 for (unsigned int i=0; i<sizeof(DataPointArray); i++) {
00195 msgOut.data.push_back(((char*)&data)[i]);
00196 }
00197 rtai_data.publish(msgOut);
00198 return true;
00199 }
00200
00201 bool initialstepCallback(bipedRobin_msgs::StepTarget3DService::Request &req, bipedRobin_msgs::StepTarget3DService::Response &res) {
00202 ROS_INFO("Initialstep Service called");
00203 struct DataPointArray data;
00204 double roll = 0;
00205 double pitch = 0;
00206 double yaw = 0;
00207 btMatrix3x3(btQuaternion(req.step.pose.orientation.x, req.step.pose.orientation.y, req.step.pose.orientation.z, req.step.pose.orientation.w)).getEulerYPR(yaw, pitch, roll);
00208 strcpy(data.dataPoint[0].name, "srv_desiredStep_flag"); data.dataPoint[0].value = 1;
00209 strcpy(data.dataPoint[1].name, "srv_desiredStep_feet"); data.dataPoint[1].value = 1;
00210 strcpy(data.dataPoint[2].name, "srv_desiredStep_x"); data.dataPoint[2].value = req.step.pose.position.x;
00211 strcpy(data.dataPoint[3].name, "srv_desiredStep_y"); data.dataPoint[3].value = req.step.pose.position.y;
00212 strcpy(data.dataPoint[4].name, "srv_desiredStep_z"); data.dataPoint[4].value = req.step.pose.position.z;
00213 strcpy(data.dataPoint[5].name, "srv_desiredStep_alpha"); data.dataPoint[5].value = roll;
00214 strcpy(data.dataPoint[6].name, "srv_desiredStep_beta"); data.dataPoint[6].value = pitch;
00215 strcpy(data.dataPoint[7].name, "srv_desiredStep_gamma"); data.dataPoint[7].value = yaw;
00216 data.length = 8;
00217 for (int i=0; i<data.length; i++) data.dataPoint[i].timestamp = 0xffff;
00218 std_msgs::UInt8MultiArray msgOut;
00219 for (unsigned int i=0; i<sizeof(DataPointArray); i++) {
00220 msgOut.data.push_back(((char*)&data)[i]);
00221 }
00222 rtai_data.publish(msgOut);
00223 return true;
00224 }
00225
00226
00227 int main(int argc, char **argv)
00228 {
00229
00230
00231 ros::init(argc, argv, "biped_serializer");
00232 ros::NodeHandle n;
00233 ros::NodeHandle pn("~");
00234
00235 rtai_data = n.advertise<std_msgs::UInt8MultiArray>("data_to_rtai", 1000);
00236
00237
00238 ros::ServiceServer footstep3D_srv = n.advertiseService("footstep3D_srv", footstepCallback);
00239 ros::ServiceServer footstep3DInc_srv = n.advertiseService("footstep3DInc_srv", footstepIncCallback);
00240 ros::ServiceServer acknowledge_srv = n.advertiseService("acknowledge_srv", acknowledgeCallback);
00241 ros::ServiceServer reference_srv = n.advertiseService("reference_srv", referenceCallback);
00242 ros::ServiceServer stop_srv = n.advertiseService("stop_srv", stopCallback);
00243 ros::ServiceServer reset_srv = n.advertiseService("resetState_srv", resetCallback);
00244 ros::ServiceServer setMode_srv = n.advertiseService("setMode_srv", setModeCallback);
00245 ros::ServiceServer initialstep_srv = n.advertiseService("initialstep0_srv", initialstep0Callback);
00246 ros::ServiceServer initialstep0_srv = n.advertiseService("initialstep_srv", initialstepCallback);
00247 ros::ServiceServer setParam_srv = n.advertiseService("setParam_srv", setParamCallback);
00248
00249 ros::Duration(2.0).sleep();
00250 ros::spinOnce();
00251
00252 bool isReal;
00253 n.param("/par_isRealEnvironment", isReal, false);
00254 if (isReal) {
00255 ROS_INFO("The Robot is present in reality");
00256 } else {
00257 ROS_INFO("The Robot is just simulated");
00258 }
00259 sendParameterToRobot("par_isRealEnvironment", isReal);
00260
00261 ros::spin();
00262
00263 return 0;
00264 }
00265
00266