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 "adept_common/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
00037 using namespace industrial::smpl_msg_connection;
00038 using namespace industrial::joint_data;
00039 using namespace industrial::joint_traj_pt;
00040 using namespace industrial::joint_traj_pt_message;
00041 using namespace industrial::simple_message;
00042
00043
00044 namespace adept
00045 {
00046 namespace joint_trajectory_downloader
00047 {
00048 JointTrajectoryDownloader::JointTrajectoryDownloader()
00049 {
00050 }
00051
00052 JointTrajectoryDownloader::JointTrajectoryDownloader(ros::NodeHandle &n,
00053 SmplMsgConnection* robotConnecton) : node_(n)
00054 {
00055 ROS_INFO("Constructor joint trajectory downloader node");
00056
00057 this->sub_joint_trajectory_ = this->node_.subscribe("command",
00058 0, &JointTrajectoryDownloader::jointTrajectoryCB, this);
00059 this->robot_ = robotConnecton;
00060 ROS_INFO("Joint trajectory downloader node initialized");
00061 }
00062
00063 JointTrajectoryDownloader::~JointTrajectoryDownloader()
00064 {
00065
00066 this->sub_joint_trajectory_.shutdown();
00067 }
00068
00069 void JointTrajectoryDownloader::jointTrajectoryCB(
00070 const trajectory_msgs::JointTrajectoryConstPtr &msg)
00071 {
00072 ROS_INFO("Receiving joint trajectory message");
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 for (int i = 0; i < msg->points.size(); i++)
00089 {
00090 ROS_INFO("Sending joints trajectory point[%d]", i);
00091
00092 JointTrajPt jPt;
00093 JointTrajPtMessage jMsg;
00094 SimpleMessage topic;
00095 trajectory_msgs::JointTrajectoryPoint pt;
00096
00097 pt = msg->points[i];
00098
00099
00100
00101 if (0 == i)
00102 {
00103 ROS_DEBUG("First trajectory point, setting special sequence value");
00104 jPt.setSequence(SpecialSeqValues::START_TRAJECTORY_DOWNLOAD);
00105 }
00106 else if (msg->points.size() - 1 == i)
00107 {
00108 ROS_DEBUG("Last trajectory point, setting special sequence value");
00109 jMsg.point_.setSequence(SpecialSeqValues::END_TRAJECTORY);
00110 }
00111 else
00112 {
00113 jMsg.point_.setSequence(i);
00114 }
00115
00116
00117 JointData data;
00118 for (int j = 0; j < msg->joint_names.size(); j++)
00119 {
00120 pt = msg->points[j];
00121 data.setJoint(j, pt.positions[j]);
00122 }
00123
00124
00125 jPt.setJointPosition(data);
00126
00127 jMsg.init(jPt);
00128 jMsg.toTopic(topic);
00129
00130 ROS_DEBUG("Sending joint trajectory point");
00131 if (this->robot_->sendMsg(topic))
00132 {
00133 ROS_INFO("Point[%d] sent to controller", i);
00134 }
00135 else
00136 {
00137 ROS_WARN("Failed sent joint point, skipping point");
00138 }
00139 }
00140 }
00141
00142 }
00143 }
00144