10 if (!gnh.
hasParam(
"move_group/controller_list"))
16 gnh.
getParam(
"move_group/controller_list", controller_list);
17 for (
int i = 0; i < controller_list.
size(); i++)
19 if (!controller_list[i].hasMember(
"name"))
21 ROS_ERROR(
"name must be specifed for each controller.");
24 if (!controller_list[i].hasMember(
"joints"))
26 ROS_ERROR(
"joints must be specifed for each controller.");
32 std::string name = std::string(controller_list[i][
"name"]);
34 std::string action_ns = std::string(
"");
35 if (controller_list[i].hasMember(
"action_ns"))
37 action_ns = std::string(controller_list[i][
"action_ns"]);
42 ROS_ERROR_STREAM(
"joints for controller " << name <<
" is not specified as an array");
45 auto joints = controller_list[i][
"joints"];
47 std::string type = std::string(
"FollowJointTrajectory");
48 if (!controller_list[i].hasMember(
"type"))
50 ROS_WARN_STREAM(
"type is not specifed for controller " << name <<
", using default FollowJointTrajectory");
52 type = std::string(controller_list[i][
"type"]);
53 if (type !=
"FollowJointTrajectory")
61 for (
int j = 0; j <
cinfo_map_[name].joints.size(); ++j)
63 cinfo_map_[name].joints[j] = std::string(joints[j]);
68 ROS_ERROR_STREAM(
"Caught unknown exception while parsing controller information");
83 if (not use_action_ && intermittent_)
85 ROS_WARN(
"'intermittent' param should be true with 'use_action'. Assuming to use action'");
90 ROS_ERROR(
"get_controller_list faild. Aborted.");
97 auto cinfo = it->second;
99 for (
int i=0; i<cinfo.joints.size(); i++)
117 auto controller_name = it->first;
118 auto controller_info = it->second;
119 auto action_name = controller_name +
"/" + controller_info.action_ns;
125 auto controller_name = it->first;
126 auto controller_info = it->second;
127 auto action_name = controller_name +
"/" + controller_info.action_ns;
145 auto controller_name = it->first;
146 traj_pubs_[controller_name] = gnh.
advertise<trajectory_msgs::JointTrajectory>(controller_name +
"/command", 1);
158 if (msg->joint_names.size() != msg->deltas.size())
160 ROS_ERROR(
"Size mismatch of joint_names and deltas");
168 auto controller_name = it->first;
180 ROS_INFO(
"start joint state updated");
202 auto controller_name = it->first;
203 auto joint_names = it->second.joints;
205 trajectory_msgs::JointTrajectory traj;
206 trajectory_msgs::JointTrajectoryPoint point;
209 for (
int i=0; i<joint_names.size(); i++)
211 size_t jog_index = std::distance(msg->joint_names.begin(),
212 std::find(msg->joint_names.begin(),
213 msg->joint_names.end(), joint_names[i]));
214 if (jog_index == msg->joint_names.size())
219 size_t state_index = std::distance(
joint_state_.name.begin(),
224 ROS_ERROR_STREAM(
"Cannot find joint " << joint_names[i] <<
" in joint_states_");
228 joint_state_.position[state_index] += msg->deltas[jog_index];
230 traj.joint_names.push_back(joint_names[i]);
231 point.positions.push_back(
joint_state_.position[state_index]);
232 point.velocities.push_back(0.0);
233 point.accelerations.push_back(0.0);
237 traj.header.frame_id =
"base_link";
238 traj.points.push_back(point);
241 control_msgs::FollowJointTrajectoryGoal goal;
242 goal.trajectory = traj;
261 if (msg->name.empty() || msg->name.size() != msg->position.size())
263 ROS_WARN(
"Invalid JointState message");
266 for (
int i=0; i<msg->name.size(); i++)
277 int main(
int argc,
char **argv)
actionlib::SimpleActionClient< control_msgs::FollowJointTrajectoryAction > TrajClient
void publish(const boost::shared_ptr< M > &message) const
ros::Subscriber jog_joint_sub_
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
int get_controller_list()
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
std::map< std::string, ros::Publisher > traj_pubs_
void jog_joint_cb(jog_msgs::JogJointConstPtr msg)
Callback function for the topic jog_joint.
ros::Publisher joint_state_pub_
int main(int argc, char **argv)
Main function of the node.
std::map< std::string, TrajClient * > traj_clients_
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
std::map< std::string, double > joint_map_
#define ROS_WARN_STREAM(args)
void joint_state_cb(sensor_msgs::JointStateConstPtr msg)
Callback function for the topic joint_state.
#define ROS_INFO_STREAM(args)
bool getParam(const std::string &key, std::string &s) const
std::map< std::string, Controller > cinfo_map_
ROSCPP_DECL void shutdown()
bool hasParam(const std::string &key) const
ros::Subscriber joint_state_sub_
#define ROS_ERROR_STREAM(args)
ROSCPP_DECL void spinOnce()
sensor_msgs::JointState joint_state_