54 const std::string& controller_state_topic)
55 : joint_trajectory_action_(joint_trajectory_action)
56 , controller_state_topic_(controller_state_topic)
73 const control_msgs::JointTrajectoryControllerState::ConstPtr& state)
81 std::copy(point.positions.begin(), point.positions.end(), std::ostream_iterator<double>(std::cout,
" "));
82 std::cout << std::endl;
91 std::ifstream input_file;
98 control_msgs::FollowJointTrajectoryGoal pre_goal;
99 control_msgs::FollowJointTrajectoryGoal goal;
102 goal.trajectory.joint_names.push_back(
"joint_a1");
103 goal.trajectory.joint_names.push_back(
"joint_a2");
104 goal.trajectory.joint_names.push_back(
"joint_a3");
105 goal.trajectory.joint_names.push_back(
"joint_a4");
106 goal.trajectory.joint_names.push_back(
"joint_a5");
107 goal.trajectory.joint_names.push_back(
"joint_a6");
108 goal.trajectory.joint_names.push_back(
"joint_a7");
109 pre_goal.trajectory.joint_names = goal.trajectory.joint_names;
110 double num_joints = goal.trajectory.joint_names.size();
113 std::getline(input_file, line);
116 while (std::getline(input_file, line))
118 std::stringstream lineStream(line);
120 trajectory_msgs::JointTrajectoryPoint point;
123 if (!std::getline(lineStream, cell,
','))
129 for (std::size_t i = 0; i < num_joints; ++i)
132 if (!std::getline(lineStream, cell,
','))
137 if (!std::getline(lineStream, cell,
','))
142 if (!std::getline(lineStream, cell,
','))
144 point.positions.push_back(atof(cell.c_str()));
147 if (!std::getline(lineStream, cell,
','))
149 point.velocities.push_back(atof(cell.c_str()));
152 if (!std::getline(lineStream, cell,
','))
157 goal.trajectory.points.push_back(point);
167 trajectory_msgs::JointTrajectoryPoint last_point;
171 std::cout <<
"Current State:" << std::endl;
174 std::cout <<
"^^ Goal point " << std::endl;
175 pre_goal.trajectory.points.push_back(last_point);
179 double max_velocity = 0.1;
180 double frequency = 200;
181 double q_delta = max_velocity / frequency;
182 double t_delta = 1/frequency;
187 trajectory_msgs::JointTrajectoryPoint new_point = last_point;
191 new_point.time_from_start = time_from_start;
194 for (std::size_t i = 0; i < num_joints; ++i)
197 if (new_point.positions[i] < goal.trajectory.points.front().positions[i])
200 new_point.positions[i] = std::min(new_point.positions[i] + q_delta,
201 goal.trajectory.points.front().positions[i]);
202 new_point.velocities[i] = max_velocity;
206 new_point.velocities[i] = 0;
209 pre_goal.trajectory.points.push_back(new_point);
210 last_point = new_point;
223 for (std::size_t i = 0; i < goal.trajectory.points.size(); ++i)
bool waitForServer(const ros::Duration &timeout=ros::Duration(0, 0)) const
void stateCB(const control_msgs::JointTrajectoryControllerState::ConstPtr &state)
Callback from ROS message.
#define ROS_ERROR_STREAM_NAMED(name, args)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
#define ROS_INFO_STREAM_NAMED(name, args)
std::string controller_state_topic_
control_msgs::JointTrajectoryControllerState current_state_
CSVToController(const std::string &joint_trajectory_action, const std::string &controller_state_topic)
Constructor.
void printPoint(trajectory_msgs::JointTrajectoryPoint &point)
actionlib::SimpleActionClient< control_msgs::FollowJointTrajectoryAction > joint_trajectory_action_
void sendGoal(const Goal &goal, SimpleDoneCallback done_cb=SimpleDoneCallback(), SimpleActiveCallback active_cb=SimpleActiveCallback(), SimpleFeedbackCallback feedback_cb=SimpleFeedbackCallback())
ROSCPP_DECL void spinOnce()
ros::Subscriber state_sub_
void loadAndRunCSV(const std::string &file_name)