Skip to content

Commit f0f1ae8

Browse files
committed
Fixed rework crashing bug
1 parent 31edcbd commit f0f1ae8

File tree

8 files changed

+53
-24
lines changed

8 files changed

+53
-24
lines changed

crs_application/config/main/motion_planning/MP_config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
general:
22
use_trajopt_freespace: true
33
use_trajopt_surface: true
4-
default_to_descartes: true
4+
default_to_descartes: false
55
default_to_ompl: true
66
simplify_start_end_freespace: true
77
manipulator: "manipulator"

crs_application/include/crs_application/task_managers/process_execution_manager.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,11 @@ class ProcessExecutionManager
9494
void resetIndexes();
9595
bool changeActiveController(const bool turn_on_cart);
9696
bool toggleSander(const bool turn_on_sander);
97+
common::ActionResult moveRobotIfNotAtStart(const trajectory_msgs::msg::JointTrajectory& traj);
9798
common::ActionResult execTrajectory(const trajectory_msgs::msg::JointTrajectory& traj);
9899
common::ActionResult execSurfaceTrajectory(const cartesian_trajectory_msgs::msg::CartesianTrajectory& traj,
99-
const crs_motion_planning::cartesianTrajectoryConfig& traj_config);
100+
const crs_motion_planning::cartesianTrajectoryConfig& traj_config,
101+
const trajectory_msgs::msg::JointTrajectory& joint_traj);
100102
common::ActionResult checkPreReq();
101103

102104
void jointCallback(const sensor_msgs::msg::JointState::SharedPtr joint_msg);

crs_application/src/crs_executive.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ bool CRSExecutive::setupScanAcquisitionStates()
540540
async : false,
541541
exit_cb : nullptr,
542542
on_done_action : "",
543-
on_failed_action: ""
543+
on_failed_action : ""
544544
};
545545

546546
st_callbacks_map[scan::CAPTURE] = StateCallbackInfo{

crs_application/src/task_managers/motion_planning_manager.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,11 @@ common::ActionResult MotionPlanningManager::planMediaChanges()
438438
const trajectory_msgs::msg::JointTrajectory& next_traj = result_.process_plans[i + 1].process_motions.front();
439439
if (!next_traj.points.empty())
440440
{
441+
if (!result_.process_plans[i + 1].start.points.empty())
442+
{
443+
result_.process_plans[i + 1].start.points.clear();
444+
result_.process_plans[i + 1].start.joint_names.clear();
445+
}
441446
req->goal_position.position = next_traj.points.front().positions;
442447
req->goal_position.name = next_traj.joint_names;
443448
}

crs_application/src/task_managers/process_execution_manager.cpp

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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

496510
common::ActionResult
497511
ProcessExecutionManager::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;

crs_application/src/task_managers/scan_acquisition_manager.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ common::ActionResult ScanAcquisitionManager::moveRobot()
187187
freespace_motion_request->goal_pose = scan_poses_.at(scan_index_);
188188
freespace_motion_request->execute = true;
189189

190-
191190
auto result_future = call_freespace_motion_client_->async_send_request(freespace_motion_request);
192191

193192
std::future_status status = result_future.wait_for(std::chrono::duration<double>(WAIT_MOTION_COMPLETION));

crs_motion_planning/src/motion_planning_server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ class MotionPlanningServer : public rclcpp::Node
210210
}
211211
std::vector<double> last_pose = returned_plans[last_success_i].process_motions.back().points.back().positions;
212212
std::vector<std::string> last_joint_names = returned_plans[last_success_i].process_motions.back().joint_names;
213-
motion_planner_config->use_start = false;
213+
motion_planner_config->use_start = true;
214214
motion_planner_config->start_pose =
215215
std::make_shared<tesseract_motion_planners::JointWaypoint>(last_pose, last_joint_names);
216216
returned_plans[last_success_i].end.points.clear();

crs_motion_planning/src/path_planning_utils.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,7 @@ bool crsMotionPlanner::generateOMPLSeed(const tesseract_motion_planners::JointWa
836836
ompl_planner_config->n_output_states = config_->ompl_config.n_output_states;
837837
ompl_planner_config->longest_valid_segment_fraction = config_->ompl_config.longest_valid_segment_fraction;
838838
ompl_planner_config->longest_valid_segment_length = config_->ompl_config.longest_valid_segment_length;
839+
// ompl_planner_config->
839840
RCLCPP_INFO(logger_, "OUTPUT STATES: %i", config_->ompl_config.n_output_states);
840841
std::cout << "GENERATING OMPL SEED FROM \n"
841842
<< start_pose->getPositions().matrix() << "\nTO\n"

0 commit comments

Comments
 (0)