Skip to content

Commit c552d58

Browse files
committed
failure to parse tolerances fails traj execution
This is a temporary implementation, as it would be better to check the goal_tolerance field can be parsed when validating a new goal.
1 parent c52dfa3 commit c552d58

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

src/ActionServer_FJT.c

+24-10
Original file line numberDiff line numberDiff line change
@@ -642,15 +642,19 @@ void Ros_ActionServer_FJT_Goal_Complete(GOAL_END_TYPE goal_end_type)
642642

643643
//'parse' the JointTolerance elements from the goal. Map their 'name:tolerance'
644644
//to the 'joint_index:tolerance' we need
645-
STATUS status = Ros_ActionServer_FJT_Parse_GoalPosTolerances(
645+
STATUS statusParseGoalTolerance = Ros_ActionServer_FJT_Parse_GoalPosTolerances(
646646
&g_actionServer_FJT_SendGoal_Request.goal.goal_tolerance,
647647
&feedback_FollowJointTrajectory.feedback.joint_names,
648648
posTolerance, numAxesToCheck);
649649

650-
if (status != OK)
650+
BOOL bToleranceParseOk = TRUE;
651+
if (statusParseGoalTolerance != OK)
651652
{
652-
Ros_Debug_BroadcastMsg("%s: parsing 'goal_tolerance' field failed: %d", __func__, status);
653-
//TODO(gavanderhoorn): what do we do here?
653+
Ros_Debug_BroadcastMsg("%s: parsing 'goal_tolerance' field failed: %d", __func__, statusParseGoalTolerance);
654+
//TODO(gavanderhoorn): implement tolerance parsing in Ros_ActionServer_FJT_Goal_Received(..) instead
655+
bToleranceParseOk = FALSE;
656+
Ros_Debug_BroadcastMsg("%s: skipping goal tolerance check", __func__);
657+
goto goal_complete_skip_tolerance_comparison;
654658
}
655659

656660
//retrieve the last traj pt from the goal traj and re-order position values such
@@ -660,17 +664,20 @@ void Ros_ActionServer_FJT_Goal_Complete(GOAL_END_TYPE goal_end_type)
660664
bzero(lastTrajPtPositions, sizeof(lastTrajPtPositions));
661665
size_t finalTrajPtIdx = g_actionServer_FJT_SendGoal_Request.goal.trajectory.points.size - 1;
662666

663-
status = Ros_ActionServer_FJT_Reorder_TrajPt_To_Internal_Order(
667+
STATUS statusGoalToleranceReorder = Ros_ActionServer_FJT_Reorder_TrajPt_To_Internal_Order(
664668
&g_actionServer_FJT_SendGoal_Request.goal.trajectory.points.data[finalTrajPtIdx],
665669
&g_actionServer_FJT_SendGoal_Request.goal.trajectory.joint_names,
666670
&feedback_FollowJointTrajectory.feedback.joint_names,
667671
lastTrajPtPositions,
668672
numAxesToCheck);
669673

670-
if (status != OK)
674+
if (statusGoalToleranceReorder != OK)
671675
{
672-
Ros_Debug_BroadcastMsg("%s: reordering final traj pt failed: %d", __func__, status);
673-
//TODO(gavanderhoorn): what do we do here?
676+
Ros_Debug_BroadcastMsg("%s: reordering final traj pt failed: %d", __func__, statusGoalToleranceReorder);
677+
//TODO(gavanderhoorn): check re-ordering in Ros_ActionServer_FJT_Goal_Received(..) instead
678+
bToleranceParseOk = FALSE;
679+
Ros_Debug_BroadcastMsg("%s: skipping goal tolerance check", __func__);
680+
goto goal_complete_skip_tolerance_comparison;
674681
}
675682

676683

@@ -695,6 +702,7 @@ void Ros_ActionServer_FJT_Goal_Complete(GOAL_END_TYPE goal_end_type)
695702
}
696703
}
697704

705+
goal_complete_skip_tolerance_comparison: ;
698706
//-----------------------------------------------------------------------
699707
//check execution time
700708
control_msgs__action__FollowJointTrajectory_SendGoal_Request* ros_goal_request = (control_msgs__action__FollowJointTrajectory_SendGoal_Request*)fjt_active_goal_handle->ros_goal_request;
@@ -718,7 +726,7 @@ void Ros_ActionServer_FJT_Goal_Complete(GOAL_END_TYPE goal_end_type)
718726
BOOL timeOk = (diff <= timeTolerance);
719727

720728
//-----------------------------------------------------------------------
721-
if (positionOk && timeOk)
729+
if (bToleranceParseOk && positionOk && timeOk)
722730
{
723731
Ros_Debug_BroadcastMsg("FJT action successful");
724732
fjt_result_response.status = GOAL_STATE_SUCCEEDED;
@@ -736,7 +744,13 @@ void Ros_ActionServer_FJT_Goal_Complete(GOAL_END_TYPE goal_end_type)
736744

737745
char msgBuffer[500] = { 0 };
738746

739-
if (!positionOk)
747+
if (!bToleranceParseOk)
748+
{
749+
sprintf(msgBuffer, "Parsing goal_tolerance failed (%d; %d). Failing trajectory execution.", statusParseGoalTolerance, statusGoalToleranceReorder);
750+
rosidl_runtime_c__String__assign(&fjt_result_response.result.error_string, msgBuffer);
751+
fjt_result_response.result.error_code = RESULT_REPONSE_ERROR_CODE(control_msgs__action__FollowJointTrajectory_Result__GOAL_TOLERANCE_VIOLATED, FAIL_TRAJ_TOLERANCE_PARSE);
752+
}
753+
else if (!positionOk)
740754
{
741755
sprintf(msgBuffer, "Final position was outside tolerance. Check robot safety-limits that could be inhibiting motion.");
742756
for (int axis = 0; axis < numAxesToCheck; axis += 1)

src/ErrorHandling.h

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ typedef enum
6060
FAIL_TRAJ_POSITION,
6161
FAIL_TRAJ_TIME,
6262
FAIL_TRAJ_ALARM,
63+
FAIL_TRAJ_TOLERANCE_PARSE,
6364
} Failed_Trajectory_Status;
6465

6566
//**********************************************************************

0 commit comments

Comments
 (0)