@@ -147,12 +147,10 @@ common::ActionResult ProcessExecutionManager::execProcess()
147147 for (std::size_t i = 0 ; i < process_plan.process_motions .size (); i++)
148148 {
149149 RCLCPP_INFO (node_->get_logger (), " %s Executing process path %i" , MANAGER_NAME.c_str (), i);
150- std::chrono::duration<double > sleep_dur (WAIT_ROBOT_STOP);
151- RCLCPP_INFO (node_->get_logger (), " Waiting %f seconds for robot to fully stop" , WAIT_ROBOT_STOP);
152- rclcpp::sleep_for (std::chrono::duration_cast<std::chrono::seconds>(sleep_dur));
153150 if (config_->force_controlled_trajectories )
154151 {
155- if (!execSurfaceTrajectory (process_plan.force_controlled_process_motions [i], cartesian_traj_config))
152+ if (!execSurfaceTrajectory (
153+ process_plan.force_controlled_process_motions [i], cartesian_traj_config, process_plan.process_motions [i]))
156154 {
157155 common::ActionResult res;
158156 res.err_msg = boost::str (boost::format (" %s failed to execute process motion %i" ) % MANAGER_NAME.c_str () % i);
@@ -435,30 +433,27 @@ bool ProcessExecutionManager::toggleSander(const bool turn_on_sander)
435433 return true ;
436434}
437435
438- common::ActionResult ProcessExecutionManager::execTrajectory (const trajectory_msgs::msg::JointTrajectory& traj)
436+ common::ActionResult ProcessExecutionManager::moveRobotIfNotAtStart (const trajectory_msgs::msg::JointTrajectory& traj)
439437{
440- using namespace control_msgs ::action ;
441- static const double GOAL_ACCEPT_TIMEOUT_PERIOD = 1.0 ;
438+ // Check if joint state is in correct position before executing, if not then call a freespace motion from current
439+ // joint state to beginning of trajectory
442440
443441 common::ActionResult res = false ;
444442
445- if (config_->force_controlled_trajectories && !ProcessExecutionManager::changeActiveController (false ))
446- {
447- res.succeeded = false ;
448- return res;
449- }
450-
451- // Check if joint state is in correct position before executing, if not then call a freespace motion from current
452- // joint state to beginning of trajectory
453443 sensor_msgs::msg::JointState::SharedPtr curr_joint_state =
454444 crs_application::common::getCurrentState (node_, JOINT_STATES_TOPIC, 1.0 );
455445 if (!crs_motion_planning::checkStartState (traj, *curr_joint_state, config_->joint_tolerance [0 ]))
456446 {
447+ if (!ProcessExecutionManager::changeActiveController (false ))
448+ {
449+ res.succeeded = false ;
450+ return res;
451+ }
457452 RCLCPP_WARN (node_->get_logger (), " Not at the correct joint state to start freespace motion" );
458453 if (!call_freespace_client_->service_is_ready ())
459454 {
460455 RCLCPP_ERROR (node_->get_logger (), " %s Freespace Motion is not ready`" , MANAGER_NAME.c_str ());
461- return false ;
456+ return res ;
462457 }
463458 crs_msgs::srv::CallFreespaceMotion::Request::SharedPtr freespace_req =
464459 std::make_shared<crs_msgs::srv::CallFreespaceMotion::Request>();
@@ -473,17 +468,36 @@ common::ActionResult ProcessExecutionManager::execTrajectory(const trajectory_ms
473468 if (status != std::future_status::ready)
474469 {
475470 RCLCPP_ERROR (node_->get_logger (), " %s Call Freespace Motion service call timedout" , MANAGER_NAME.c_str ());
476- return false ;
471+ return res ;
477472 }
478473 auto result = result_future.get ();
479474
480475 if (!result->success )
481476 {
482477 RCLCPP_ERROR (node_->get_logger (), " %s %s" , MANAGER_NAME.c_str (), result->message .c_str ());
483- return false ;
478+ return res ;
484479 }
485480 }
486481
482+ return true ;
483+ }
484+
485+ common::ActionResult ProcessExecutionManager::execTrajectory (const trajectory_msgs::msg::JointTrajectory& traj)
486+ {
487+ using namespace control_msgs ::action;
488+ static const double GOAL_ACCEPT_TIMEOUT_PERIOD = 1.0 ;
489+
490+ common::ActionResult res = false ;
491+
492+ if (config_->force_controlled_trajectories && !ProcessExecutionManager::changeActiveController (false ))
493+ {
494+ res.succeeded = false ;
495+ return res;
496+ }
497+
498+ if (!ProcessExecutionManager::moveRobotIfNotAtStart (traj))
499+ return res;
500+
487501 res.succeeded = crs_motion_planning::execTrajectory (trajectory_exec_client_, node_->get_logger (), traj);
488502 if (!res)
489503 {
@@ -495,14 +509,22 @@ common::ActionResult ProcessExecutionManager::execTrajectory(const trajectory_ms
495509
496510common::ActionResult
497511ProcessExecutionManager::execSurfaceTrajectory (const cartesian_trajectory_msgs::msg::CartesianTrajectory& traj,
498- const crs_motion_planning::cartesianTrajectoryConfig& traj_config)
512+ const crs_motion_planning::cartesianTrajectoryConfig& traj_config,
513+ const trajectory_msgs::msg::JointTrajectory& joint_traj)
499514{
500515 using namespace control_msgs ::action;
501516 static const double GOAL_ACCEPT_TIMEOUT_PERIOD = 1.0 ;
502517
503518 // rclcpp::Duration traj_dur(traj.points.back().time_from_start);
504519 common::ActionResult res = false ;
505520
521+ if (!ProcessExecutionManager::moveRobotIfNotAtStart (joint_traj))
522+ return res;
523+
524+ std::chrono::duration<double > sleep_dur (WAIT_ROBOT_STOP);
525+ RCLCPP_INFO (node_->get_logger (), " Waiting %f seconds for robot to fully stop" , WAIT_ROBOT_STOP);
526+ rclcpp::sleep_for (std::chrono::duration_cast<std::chrono::seconds>(sleep_dur));
527+
506528 if (config_->force_controlled_trajectories && !ProcessExecutionManager::changeActiveController (true ))
507529 {
508530 res.succeeded = false ;
0 commit comments