Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <dx100/joint_trajectory_downloader.h>
00033 #include "simple_message/joint_traj_pt.h"
00034 #include "simple_message/messages/joint_traj_pt_message.h"
00035 #include "simple_message/smpl_msg_connection.h"
00036 #include <dx100/utils.h>
00037
00038 using namespace industrial::smpl_msg_connection;
00039 using namespace industrial::joint_data;
00040 using namespace industrial::joint_traj_pt;
00041 using namespace industrial::joint_traj_pt_message;
00042 using namespace industrial::simple_message;
00043 using namespace motoman::utils;
00044
00045
00046 namespace motoman
00047 {
00048 namespace joint_trajectory_downloader
00049 {
00050 JointTrajectoryDownloader::JointTrajectoryDownloader()
00051 {
00052 }
00053
00054 JointTrajectoryDownloader::JointTrajectoryDownloader(ros::NodeHandle &n,
00055 SmplMsgConnection* robotConnecton) : node_(n)
00056 {
00057 ROS_INFO("Constructor joint trajectory downloader node");
00058
00059 this->sub_joint_trajectory_ = this->node_.subscribe("command",
00060 0, &JointTrajectoryDownloader::jointTrajectoryCB, this);
00061 this->robot_ = robotConnecton;
00062 this->robot_->makeConnect();
00063 ROS_INFO("Joint trajectory downloader node initialized");
00064 }
00065
00066 JointTrajectoryDownloader::~JointTrajectoryDownloader()
00067 {
00068 trajectoryStop();
00069 this->sub_joint_trajectory_.shutdown();
00070 }
00071
00072 void JointTrajectoryDownloader::jointTrajectoryCB(
00073 const trajectory_msgs::JointTrajectoryConstPtr &msg)
00074 {
00075 ROS_INFO("Receiving joint trajectory message");
00076
00077 if (!checkTrajectory(msg))
00078 {
00079 ROS_ERROR("Joint trajectory check failed, trajectory not downloaded");
00080 return;
00081 }
00082
00083 std::vector<double> joint_velocity_limits;
00084
00085 if (!getVelocityLimits("robot_description", msg, joint_velocity_limits))
00086 {
00087 ROS_ERROR("Failed to get joint velocity limits");
00088 return;
00089 }
00090
00091 if (!this->robot_->isConnected())
00092 {
00093 ROS_WARN("Attempting robot reconnection");
00094 this->robot_->makeConnect();
00095 }
00096
00097 ROS_INFO("Sending trajectory points, size: %d", msg->points.size());
00098
00099 for (int i = 0; i < msg->points.size(); i++)
00100 {
00101 ROS_INFO("Sending joints trajectory point[%d]", i);
00102
00103 JointTrajPt jPt;
00104 JointTrajPtMessage jMsg;
00105 SimpleMessage topic;
00106
00107
00108
00109
00110 std::vector<double> joint_velocities(0.0);
00111 double velocity =0 ;
00112 joint_velocities.resize(msg->joint_names.size(), 0.0);
00113 for (int j = 0; j < joint_velocities.size(); j++)
00114 {
00115 joint_velocities[j] = msg->points[i].velocities[j];
00116 }
00117 ROS_DEBUG("Joint velocities copied");
00118 velocity = toMotomanVelocity(joint_velocity_limits, joint_velocities);
00119
00120 jPt.setVelocity(velocity);
00121
00122
00123
00124 if (0 == i)
00125 {
00126 ROS_DEBUG("First trajectory point, setting special sequence value");
00127 jPt.setSequence(SpecialSeqValues::START_TRAJECTORY_DOWNLOAD);
00128 }
00129 else if (msg->points.size() - 1 == i)
00130 {
00131 ROS_DEBUG("Last trajectory point, setting special sequence value");
00132 jPt.setSequence(SpecialSeqValues::END_TRAJECTORY);
00133 }
00134 else
00135 {
00136 jPt.setSequence(i);
00137 }
00138
00139
00140 JointData data;
00141 for (int j = 0; j < msg->joint_names.size(); j++)
00142 {
00143 data.setJoint(j, msg->points[i].positions[j]);
00144 }
00145
00146
00147 jPt.setJointPosition(data);
00148
00149 jMsg.init(jPt);
00150 jMsg.toTopic(topic);
00151
00152 ROS_DEBUG("Sending joint trajectory point");
00153 if (this->robot_->sendMsg(topic))
00154 {
00155 ROS_INFO("Point[%d] sent to controller", i);
00156 }
00157 else
00158 {
00159 ROS_WARN("Failed sent joint point, skipping point");
00160 }
00161 }
00162 }
00163
00164 void JointTrajectoryDownloader::trajectoryStop()
00165 {
00166 JointTrajPtMessage jMsg;
00167 SimpleMessage msg;
00168 SimpleMessage reply;
00169
00170 ROS_INFO("Joint trajectory downloader: entering stopping state");
00171 jMsg.point_.setSequence(SpecialSeqValues::STOP_TRAJECTORY);
00172 jMsg.toRequest(msg);
00173 ROS_DEBUG("Sending stop command");
00174 this->robot_->sendAndReceiveMsg(msg, reply);
00175 ROS_DEBUG("Stop command sent");
00176 }
00177
00178 }
00179 }
00180