Go to the documentation of this file.00001
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 #include <Eigen/Geometry>
00052
00053 namespace tulip_controller_namespace {
00054
00055 bool tulip_controller_class::getXyzPar(std::string xyz_name, xyz& xyz_var, ros::NodeHandle &n) {
00056 if (n.getParam(xyz_name + "/x", xyz_var.x) &&
00057 n.getParam(xyz_name + "/y", xyz_var.y) &&
00058 n.getParam(xyz_name + "/z", xyz_var.z) )
00059 { return true;} else { return false;}
00060 }
00061
00062 bool tulip_controller_class::getExpPar(std::string exp_name, exp_properties& exp_var, ros::NodeHandle &n) {
00063
00064 if (tulip_controller_class::getXyzPar(exp_name + "/init_model_state/pose/position", exp_var.init_model_state.pose.position, n) &&
00065 n.getParam(exp_name + "/init_model_state/pose/orientation/roll", exp_var.init_model_state.pose.orientation.rpy.roll) &&
00066 n.getParam(exp_name + "/init_model_state/pose/orientation/pitch", exp_var.init_model_state.pose.orientation.rpy.pitch) &&
00067 n.getParam(exp_name + "/init_model_state/pose/orientation/yaw", exp_var.init_model_state.pose.orientation.rpy.yaw) &&
00068 tulip_controller_class::getXyzPar(exp_name + "/init_model_state/twist/linear", exp_var.init_model_state.twist.linear, n) &&
00069 tulip_controller_class::getXyzPar(exp_name + "/init_model_state/twist/angular", exp_var.init_model_state.twist.angular, n) &&
00070 tulip_controller_class::getXyzPar(exp_name + "/push/force", exp_var.push.force, n) &&
00071 n.getParam(exp_name + "/push/time", exp_var.push.time) &&
00072 n.getParam(exp_name + "/push/duration", exp_var.push.duration) )
00073 {
00074
00075 tf::Quaternion q;
00076 q = tf::createQuaternionFromRPY(exp_var.init_model_state.pose.orientation.rpy.roll,exp_var.init_model_state.pose.orientation.rpy.pitch,exp_var.init_model_state.pose.orientation.rpy.yaw);
00077
00078 exp_var.init_model_state.pose.orientation.quaternion.x = q.x();
00079 exp_var.init_model_state.pose.orientation.quaternion.y = q.y();
00080 exp_var.init_model_state.pose.orientation.quaternion.z = q.z();
00081 exp_var.init_model_state.pose.orientation.quaternion.w = q.w();
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 return true;
00108
00109 } else {
00110 return false;
00111 }
00112 }
00113
00114 bool tulip_controller_class::setExpState(exp_properties exp_var, ros::NodeHandle &n) {
00115
00116
00117
00118
00119 ros::service::waitForService("/gazeborver/set_model_state");
00120 ros::ServiceClient client_initstate = n.serviceClient<gazebo_msgs::SetModelState>("/gazeborver/set_model_state");
00121 gazebo_msgs::SetModelState srv_initstate;
00122
00123 srv_initstate.request.model_state.model_name = "tulip";
00124
00125 srv_initstate.request.model_state.pose.position.x = exp_var.init_model_state.pose.position.x;
00126 srv_initstate.request.model_state.pose.position.y = exp_var.init_model_state.pose.position.y;
00127 srv_initstate.request.model_state.pose.position.z = exp_var.init_model_state.pose.position.z;
00128 srv_initstate.request.model_state.pose.orientation.x = exp_var.init_model_state.pose.orientation.quaternion.x;
00129 srv_initstate.request.model_state.pose.orientation.y = exp_var.init_model_state.pose.orientation.quaternion.y;
00130 srv_initstate.request.model_state.pose.orientation.z = exp_var.init_model_state.pose.orientation.quaternion.z;
00131 srv_initstate.request.model_state.pose.orientation.w = exp_var.init_model_state.pose.orientation.quaternion.w;
00132 srv_initstate.request.model_state.twist.linear.x = exp_var.init_model_state.twist.linear.x;
00133 srv_initstate.request.model_state.twist.linear.y = exp_var.init_model_state.twist.linear.y;
00134 srv_initstate.request.model_state.twist.linear.z = exp_var.init_model_state.twist.linear.z;
00135 srv_initstate.request.model_state.twist.angular.x = exp_var.init_model_state.twist.angular.x;
00136 srv_initstate.request.model_state.twist.angular.y = exp_var.init_model_state.twist.angular.y;
00137 srv_initstate.request.model_state.twist.angular.z = exp_var.init_model_state.twist.angular.z;
00138 srv_initstate.request.model_state.reference_frame = "world";
00139
00140 if (client_initstate.call(srv_initstate))
00141 {
00142 ROS_INFO("Succesfully set initial state");
00143 return true;
00144 }
00145 else
00146 {
00147 ROS_ERROR("Failed to set initial state: %s",srv_initstate.response.status_message.c_str());
00148 return false;
00149 }
00150 }
00151
00152 bool tulip_controller_class::getRobotState(gazebo_msgs::GetModelState &srv_getstate, rpy_prop &cur_orient_rpy, ros::NodeHandle &n) {
00153
00154
00155 ros::service::waitForService("/gazeborver/get_model_state");
00156 ros::ServiceClient client_getstate = n.serviceClient<gazebo_msgs::GetModelState>("/gazeborver/get_model_state");
00157 srv_getstate.request.model_name = "tulip";
00158
00159 if (client_getstate.call(srv_getstate))
00160 {
00161
00162
00163 tf::Quaternion q;
00164 tf::quaternionMsgToTF(srv_getstate.response.pose.orientation, q);
00165 tf::Matrix3x3(q).getRPY(cur_orient_rpy.roll, cur_orient_rpy.pitch, cur_orient_rpy.yaw);
00166
00167 return true;
00168 }
00169 else
00170 {
00171 ROS_ERROR("Failed to get robot state: %s",srv_getstate.response.status_message.c_str());
00172 return false;
00173 }
00174 }
00175
00176 bool tulip_controller_class::applyForcetoRobot(gazebo_msgs::ApplyBodyWrench &srv_wrench, ros::NodeHandle &n) {
00177
00178 ros::service::waitForService("/gazeborver/apply_body_wrench");
00179 ros::ServiceClient client_wrench = n.serviceClient<gazebo_msgs::ApplyBodyWrench>("/gazeborver/apply_body_wrench");
00180 srv_wrench.request.body_name = "tulip::base_link";
00181
00182
00183 if (client_wrench.call(srv_wrench))
00184 {
00185
00186 return true;
00187 }
00188 else
00189 {
00190 ROS_ERROR("Failed to apply push force: %s",srv_wrench.response.status_message.c_str());
00191 return false;
00192 }
00193
00194 }
00195
00196 }