186 bool publish_twist =
false;
187 bool publish_joint =
false;
189 std::thread{ [
this]() {
return spin(); } }.detach();
191 puts(
"Reading from keyboard");
192 puts(
"---------------------------");
193 puts(
"All commands are in the planning frame");
194 puts(
"Use arrow keys and the '.' and ';' keys to Cartesian jog");
195 puts(
"Use 1|2|3|4|5|6|7 keys to joint jog. 'r' to reverse the direction of jogging.");
196 puts(
"Use 'j' to select joint jog. ");
197 puts(
"Use 't' to select twist ");
198 puts(
"Use 'w' and 'e' to switch between sending command in planning frame or end effector frame");
199 puts(
"'Q' to quit.");
208 catch (
const std::runtime_error&)
214 RCLCPP_DEBUG(nh_->get_logger(),
"value: 0x%02X\n", c);
217 auto twist_msg = std::make_unique<geometry_msgs::msg::TwistStamped>();
218 auto joint_msg = std::make_unique<control_msgs::msg::JointJog>();
220 joint_msg->joint_names.resize(7);
221 joint_msg->joint_names = {
"panda_joint1",
"panda_joint2",
"panda_joint3",
"panda_joint4",
222 "panda_joint5",
"panda_joint6",
"panda_joint7" };
224 joint_msg->velocities.resize(7);
225 std::fill(joint_msg->velocities.begin(), joint_msg->velocities.end(), 0.0);
230 RCLCPP_DEBUG(nh_->get_logger(),
"LEFT");
231 twist_msg->twist.linear.y = -0.5;
232 publish_twist =
true;
235 RCLCPP_DEBUG(nh_->get_logger(),
"RIGHT");
236 twist_msg->twist.linear.y = 0.5;
237 publish_twist =
true;
240 RCLCPP_DEBUG(nh_->get_logger(),
"UP");
241 twist_msg->twist.linear.x = 0.5;
242 publish_twist =
true;
245 RCLCPP_DEBUG(nh_->get_logger(),
"DOWN");
246 twist_msg->twist.linear.x = -0.5;
247 publish_twist =
true;
250 RCLCPP_DEBUG(nh_->get_logger(),
"PERIOD");
251 twist_msg->twist.linear.z = -0.5;
252 publish_twist =
true;
254 case KEYCODE_SEMICOLON:
255 RCLCPP_DEBUG(nh_->get_logger(),
"SEMICOLON");
256 twist_msg->twist.linear.z = 0.5;
257 publish_twist =
true;
260 RCLCPP_DEBUG(nh_->get_logger(),
"1");
261 joint_msg->velocities[0] = joint_vel_cmd_;
262 publish_joint =
true;
265 RCLCPP_DEBUG(nh_->get_logger(),
"2");
266 joint_msg->velocities[1] = joint_vel_cmd_;
267 publish_joint =
true;
270 RCLCPP_DEBUG(nh_->get_logger(),
"3");
271 joint_msg->velocities[2] = joint_vel_cmd_;
272 publish_joint =
true;
275 RCLCPP_DEBUG(nh_->get_logger(),
"4");
276 joint_msg->velocities[3] = joint_vel_cmd_;
277 publish_joint =
true;
280 RCLCPP_DEBUG(nh_->get_logger(),
"5");
281 joint_msg->velocities[4] = joint_vel_cmd_;
282 publish_joint =
true;
285 RCLCPP_DEBUG(nh_->get_logger(),
"6");
286 joint_msg->velocities[5] = joint_vel_cmd_;
287 publish_joint =
true;
290 RCLCPP_DEBUG(nh_->get_logger(),
"7");
291 joint_msg->velocities[6] = joint_vel_cmd_;
292 publish_joint =
true;
295 RCLCPP_DEBUG(nh_->get_logger(),
"r");
296 joint_vel_cmd_ *= -1;
299 RCLCPP_DEBUG(nh_->get_logger(),
"j");
300 request_ = std::make_shared<moveit_msgs::srv::ServoCommandType::Request>();
301 request_->command_type = moveit_msgs::srv::ServoCommandType::Request::JOINT_JOG;
302 if (switch_input_->wait_for_service(std::chrono::seconds(1)))
304 auto result = switch_input_->async_send_request(request_);
305 if (result.get()->success)
307 RCLCPP_INFO_STREAM(nh_->get_logger(),
"Switched to input type: JointJog");
311 RCLCPP_WARN_STREAM(nh_->get_logger(),
"Could not switch input to: JointJog");
316 RCLCPP_DEBUG(nh_->get_logger(),
"t");
317 request_ = std::make_shared<moveit_msgs::srv::ServoCommandType::Request>();
318 request_->command_type = moveit_msgs::srv::ServoCommandType::Request::TWIST;
319 if (switch_input_->wait_for_service(std::chrono::seconds(1)))
321 auto result = switch_input_->async_send_request(request_);
322 if (result.get()->success)
324 RCLCPP_INFO_STREAM(nh_->get_logger(),
"Switched to input type: Twist");
328 RCLCPP_WARN_STREAM(nh_->get_logger(),
"Could not switch input to: Twist");
333 RCLCPP_DEBUG(nh_->get_logger(),
"w");
334 RCLCPP_INFO_STREAM(nh_->get_logger(),
"Command frame set to: " << PLANNING_FRAME_ID);
335 command_frame_id_ = PLANNING_FRAME_ID;
338 RCLCPP_DEBUG(nh_->get_logger(),
"e");
339 RCLCPP_INFO_STREAM(nh_->get_logger(),
"Command frame set to: " << EE_FRAME_ID);
340 command_frame_id_ = EE_FRAME_ID;
343 RCLCPP_DEBUG(nh_->get_logger(),
"quit");
350 twist_msg->header.stamp = nh_->now();
351 twist_msg->header.frame_id = command_frame_id_;
352 twist_pub_->publish(std::move(twist_msg));
353 publish_twist =
false;
355 else if (publish_joint)
357 joint_msg->header.stamp = nh_->now();
358 joint_msg->header.frame_id = PLANNING_FRAME_ID;
359 joint_pub_->publish(std::move(joint_msg));
360 publish_joint =
false;