Go to the documentation of this file.00001 #include "wam_controller_driver_node.h"
00002 using namespace Eigen;
00003
00004 WamControllerDriverNode::WamControllerDriverNode(ros::NodeHandle &nh) :
00005 iri_base_driver::IriBaseNodeDriver<WamControllerDriver>(nh),
00006 follow_joint_trajectory_aserver_(public_node_handle_, "follow_joint_trajectory")
00007 {
00008
00009
00010
00011 this->JointState_msg_.name.resize(7);
00012 this->JointState_msg_.position.resize(7);
00013
00014
00015 this->libbarrett_link_tcp_publisher_ = this->public_node_handle_.advertise<geometry_msgs::PoseStamped>("libbarrett_link_tcp", 1);
00016 this->joint_states_publisher_ = this->public_node_handle_.advertise<sensor_msgs::JointState>("/joint_states", 1);
00017
00018
00019
00020
00021 this->hold_on_server_ = this->public_node_handle_.advertiseService("hold_on", &WamControllerDriverNode::hold_onCallback, this);
00022 this->joints_move_server_ = this->public_node_handle_.advertiseService("joints_move", &WamControllerDriverNode::joints_moveCallback, this);
00023
00024
00025
00026
00027 follow_joint_trajectory_aserver_.registerStartCallback(boost::bind(&WamControllerDriverNode::follow_joint_trajectoryStartCallback, this, _1));
00028 follow_joint_trajectory_aserver_.registerStopCallback(boost::bind(&WamControllerDriverNode::follow_joint_trajectoryStopCallback, this));
00029 follow_joint_trajectory_aserver_.registerIsFinishedCallback(boost::bind(&WamControllerDriverNode::follow_joint_trajectoryIsFinishedCallback, this));
00030 follow_joint_trajectory_aserver_.registerHasSucceedCallback(boost::bind(&WamControllerDriverNode::follow_joint_trajectoryHasSucceedCallback, this));
00031 follow_joint_trajectory_aserver_.registerGetResultCallback(boost::bind(&WamControllerDriverNode::follow_joint_trajectoryGetResultCallback, this, _1));
00032 follow_joint_trajectory_aserver_.registerGetFeedbackCallback(boost::bind(&WamControllerDriverNode::follow_joint_trajectoryGetFeedbackCallback, this, _1));
00033 follow_joint_trajectory_aserver_.start();
00034
00035
00036 ROS_INFO("Wam node started");
00037
00038 }
00039
00040 void WamControllerDriverNode::mainNodeThread(void)
00041 {
00042
00043
00044
00045 std::vector<double> angles(7,0.1);
00046 std::vector<double> pose(16,0);
00047 Matrix3f rmat;
00048
00049 std::string robot_name = this->driver_.get_robot_name();
00050 std::stringstream ss_tcp_link_name;
00051 ss_tcp_link_name << robot_name << "_link_base";
00052
00053 this->PoseStamped_msg_.header.stamp = ros::Time::now();
00054 this->PoseStamped_msg_.header.frame_id = ss_tcp_link_name.str().c_str();
00055
00056
00057
00058 this->driver_.lock();
00059 this->driver_.get_pose(&pose);
00060 this->driver_.get_joint_angles(&angles);
00061 this->driver_.unlock();
00062
00063 rmat << pose.at(0), pose.at(1), pose.at(2), pose.at(4), pose.at(5), pose.at(6), pose.at(8), pose.at(9), pose.at(10);
00064
00065 {
00066 Quaternion<float> quat(rmat);
00067
00068 this->PoseStamped_msg_.pose.position.x = pose.at(3);
00069 this->PoseStamped_msg_.pose.position.y = pose.at(7);
00070 this->PoseStamped_msg_.pose.position.z = pose.at(11);
00071 this->PoseStamped_msg_.pose.orientation.x = quat.x();
00072 this->PoseStamped_msg_.pose.orientation.y = quat.y();
00073 this->PoseStamped_msg_.pose.orientation.z = quat.z();
00074 this->PoseStamped_msg_.pose.orientation.w = quat.w();
00075 }
00076
00077 JointState_msg_.header.stamp = ros::Time::now();
00078 for(int i=0;i<(int)angles.size();i++){
00079 std::stringstream ss_jname;
00080 ss_jname << robot_name << "_joint_" << i+1;
00081 JointState_msg_.name[i] = ss_jname.str().c_str();
00082 JointState_msg_.position[i] = angles[i];
00083 }
00084
00085
00086
00087
00088
00089
00090 this->libbarrett_link_tcp_publisher_.publish(this->PoseStamped_msg_);
00091 this->joint_states_publisher_.publish(this->JointState_msg_);
00092
00093
00094 this->driver_.unlock();
00095 }
00096
00097
00098
00099
00100 bool WamControllerDriverNode::hold_onCallback(iri_wam_common_msgs::wamholdon::Request &req, iri_wam_common_msgs::wamholdon::Response &res)
00101 {
00102 ROS_INFO("WamControllerDriverNode::hold_onCallback: New Request Received!");
00103
00104
00105 this->driver_.lock();
00106
00107 if(!this->driver_.isRunning())
00108 {
00109 ROS_INFO("WamControllerDriverNode::hold_onCallback: ERROR: driver is not on run mode yet.");
00110 this->driver_.unlock();
00111 res.success = false;
00112 return false;
00113 }
00114
00115 switch (req.holdon)
00116 {
00117 case HOLDON:
00118 this->driver_.hold_on();
00119 break;
00120 case HOLDOFF:
00121 this->driver_.hold_off();
00122 break;
00123 default:
00124 ROS_ERROR("WamControllerDriverNode::hold_onCallback: ERROR: Invalid service call.");
00125 break;
00126 }
00127 this->driver_.unlock();
00128
00129 res.success = true;
00130 return true;
00131 }
00132
00133 bool WamControllerDriverNode::joints_moveCallback(iri_wam_common_msgs::joints_move::Request &req, iri_wam_common_msgs::joints_move::Response &res)
00134 {
00135 ROS_INFO("WamControllerDriverNode::joints_moveCallback: New Request Received!");
00136
00137
00138 this->driver_.lock();
00139
00140
00141 if(!this->driver_.isRunning())
00142 {
00143 ROS_INFO("WamControllerDriverNode::joints_moveCallback: ERROR: driver is not on run mode yet.");
00144 this->driver_.unlock();
00145 res.success = false;
00146 return false;
00147 }
00148
00149
00150 if ((req.velocities.size() == 0) || (req.accelerations.size() == 0))
00151 {
00152 this->driver_.move_in_joints(& req.joints);
00153 }
00154 else
00155 {
00156 this->driver_.move_in_joints(& req.joints, &req.velocities, &req.accelerations);
00157 }
00158
00159
00160 this->driver_.unlock();
00161
00162
00163 this->driver_.wait_move_end();
00164 res.success = true;
00165 return true;
00166 }
00167
00168
00169
00170
00171
00172
00173 void WamControllerDriverNode::follow_joint_trajectoryStartCallback(const control_msgs::FollowJointTrajectoryGoalConstPtr& goal)
00174 {
00175 ROS_DEBUG("[WamDriverNode]: New FollowJointTrajectoryGoal RECEIVED!");
00176 driver_.lock();
00177
00178
00179 driver_.move_trajectory_in_joints(goal->trajectory);
00180 driver_.unlock();
00181 ROS_DEBUG("[WamDriverNode]: FollowJointTrajectoryGoal SENT TO ROBOT!");
00182 }
00183
00184 void WamControllerDriverNode::follow_joint_trajectoryStopCallback(void)
00185 {
00186 ROS_DEBUG("[WamDriverNode]: New CancelFollowJointTrajectoryAction RECEIVED!");
00187 driver_.lock();
00188 driver_.stop_trajectory_in_joints();
00189 driver_.unlock();
00190 ROS_DEBUG("[WamDriverNode]: CancelFollowJointTrajectoryAction SENT TO ROBOT!");
00191 }
00192
00193 bool WamControllerDriverNode::follow_joint_trajectoryIsFinishedCallback(void)
00194 {
00195 bool ret = false;
00196 ROS_DEBUG("[WamDriverNode]: FollowJointTrajectory NOT FINISHED");
00197
00198 sleep(1);
00199
00200 driver_.lock();
00201 if (! driver_.is_moving_trajectory()){
00202 ret = true;
00203 ROS_INFO("[WamDriverNode]: FollowJointTrajectory FINISHED!");
00204 }
00205 driver_.unlock();
00206 return ret;
00207 }
00208
00209 bool WamControllerDriverNode::follow_joint_trajectoryHasSucceedCallback(void)
00210 {
00211 bool ret = false;
00212
00213 driver_.lock();
00214
00215
00216 driver_.unlock();
00217
00218 return ret;
00219 }
00220
00221 void WamControllerDriverNode::follow_joint_trajectoryGetResultCallback(control_msgs::FollowJointTrajectoryResultPtr& result)
00222 {
00223
00224 driver_.lock();
00225 if (driver_.is_joint_trajectory_result_succeeded()) {
00226 result->error_code = 0;
00227 } else {
00228 result->error_code = -1;
00229 }
00230 driver_.unlock();
00231 }
00232
00233 void WamControllerDriverNode::follow_joint_trajectoryGetFeedbackCallback(control_msgs::FollowJointTrajectoryFeedbackPtr& feedback)
00234 {
00235 driver_.lock();
00236
00237 feedback->desired = driver_.get_desired_joint_trajectory_point();
00238
00239 driver_.unlock();
00240 }
00241
00242
00243
00244
00245
00246
00247 void WamControllerDriverNode::postNodeOpenHook(void)
00248 {
00249 }
00250
00251 void WamControllerDriverNode::addNodeDiagnostics(void)
00252 {
00253 }
00254
00255 void WamControllerDriverNode::addNodeOpenedTests(void)
00256 {
00257 }
00258
00259 void WamControllerDriverNode::addNodeStoppedTests(void)
00260 {
00261 }
00262
00263 void WamControllerDriverNode::addNodeRunningTests(void)
00264 {
00265 }
00266
00267 void WamControllerDriverNode::reconfigureNodeHook(int level)
00268 {
00269 }
00270
00271 WamControllerDriverNode::~WamControllerDriverNode(void)
00272 {
00273
00274 }
00275
00276
00277 int main(int argc,char *argv[])
00278 {
00279 return driver_base::main<WamControllerDriverNode>(argc, argv, "wam_controller_driver_node");
00280 }