Skip to content

Commit f00fe31

Browse files
authored
Merge pull request #153 from BCLab-UNM/comments-manual-waypoints
Comments for ManualWaypointController
2 parents aa064c3 + adce062 commit f00fe31

File tree

4 files changed

+74
-3
lines changed

4 files changed

+74
-3
lines changed

src/behaviours/src/LogicController.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ void LogicController::ProcessData()
226226
};
227227
}
228228
else if (processState == PROCESS_STATE_MANUAL) {
229+
// under manual control only the manual waypoint controller is active
229230
prioritizedControllers = {
230231
PrioritizedController{-1, (Controller*)(&searchController)},
231232
PrioritizedController{-1, (Controller*)(&obstacleController)},

src/behaviours/src/LogicController.h

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,36 @@ class LogicController : virtual Controller
4646
void SetMapVelocityData(float linearVelocity, float angularVelocity);
4747
void SetCenterLocationOdom(Point centerLocationOdom);
4848
void SetCenterLocationMap(Point centerLocationMap);
49+
50+
51+
// Passthrough for providing new waypoints to the
52+
// ManualWaypointController.
4953
void AddManualWaypoint(Point wpt, int waypoint_id);
54+
55+
56+
// Passthrough for removing waypoints from the
57+
// ManualWaypointController.
5058
void RemoveManualWaypoint(int waypoint_id);
59+
60+
61+
// Passthrough for getting the list of manual waypoints that have
62+
// been visited.
5163
std::vector<int> GetClearedWaypoints();
5264

65+
66+
// Put the logic controller into manual mode. Changes process state
67+
// to PROCESS_STATE_MANUAL and logic state to LOGIC_STATE_INTERRUPT.
68+
69+
// If the logic controller is already in manual mode this has no
70+
// effect.
5371
void SetModeManual();
72+
73+
74+
// Put the logic controller into autonomous mode. Resets the logic
75+
// controller and clears all manual waypoints.
76+
//
77+
// If the logic controller is already in autonomous mode, then this
78+
// has no effect.
5479
void SetModeAuto();
5580

5681
void SetCurrentTimeInMilliSecs( long int time );
@@ -78,7 +103,7 @@ class LogicController : virtual Controller
78103
PROCCESS_STATE_TARGET_PICKEDUP,
79104
PROCCESS_STATE_DROP_OFF,
80105
_LAST,
81-
PROCESS_STATE_MANUAL
106+
PROCESS_STATE_MANUAL // robot is under manual control
82107
};
83108

84109
LogicState logicState;

src/behaviours/src/ManualWaypointController.h

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,50 @@ class ManualWaypointController : virtual Controller
1111
ManualWaypointController();
1212
~ManualWaypointController();
1313

14+
15+
// Clears the list of waypoints to visit.
16+
17+
// NOTE: this will not stop the robot from driving to a waypoint if
18+
// it was already driving there before this was called.
1419
void Reset() override;
20+
21+
22+
// Returns the next waypoint in the list. The result is set up to
23+
// be used by DriveController for waypoint navigation.
24+
//
1525
Result DoWork() override;
26+
27+
28+
// True if there are waypoints in the list. False otherwise.
1629
bool HasWork() override;
30+
31+
// Interrupts only if the number of waypoints has changed and is
32+
// non-zero.
1733
bool ShouldInterrupt() override;
1834

35+
36+
// Tell the controller the current location of the robot.
1937
void SetCurrentLocation(Point currentLocation);
38+
39+
// Add the provided waypoint to the list of manual waypoints.
40+
41+
// NOTE: Waypoints should have unique ids, it is incumbent on the
42+
// caller to ensure this. Providing the same IDs for multiple
43+
// waypoints may cause undefined behavior in the GUI. Further more
44+
// if the ID is removed using RemoveManualWaypoint() then all
45+
// waypoints with that ID may be removed.
2046
void AddManualWaypoint(Point wpt, int id);
47+
48+
49+
// Remove the waypoint with the given ID from the list of waypoints
50+
// to visit. If no maypoint exists with the given ID, the no action
51+
// is taken.
2152
void RemoveManualWaypoint(int id);
53+
54+
// Get a vector containing all waypoint IDs that have been visited
55+
// since this function was last called.
56+
57+
// This should be called regularly to prevent memory leaks.
2258
std::vector<int> ReachedWaypoints();
2359

2460
protected:
@@ -35,4 +71,4 @@ class ManualWaypointController : virtual Controller
3571
const float waypoint_tolerance = 0.15;
3672
};
3773

38-
#endif // MANUALWAYPOINTCONTROLLER_H
74+
#endif // MANUALWAYPOINTCONTROLLER_H

src/behaviours/src/ROSAdapter.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ ros::Publisher wristAnglePublish;
129129
ros::Publisher infoLogPublisher;
130130
ros::Publisher driveControlPublish;
131131
ros::Publisher heartbeatPublisher;
132+
// Publishes swarmie_msgs::Waypoint messages on "/<robot>/waypooints"
133+
// to indicate when waypoints have been reached.
132134
ros::Publisher waypointFeedbackPublisher;
133135

134136
// Subscribers
@@ -138,6 +140,8 @@ ros::Subscriber targetSubscriber;
138140
ros::Subscriber odometrySubscriber;
139141
ros::Subscriber mapSubscriber;
140142
ros::Subscriber virtualFenceSubscriber;
143+
// manualWaypointSubscriber listens on "/<robot>/waypoints/cmd" for
144+
// swarmie_msgs::Waypoint messages.
141145
ros::Subscriber manualWaypointSubscriber;
142146

143147
// Timers
@@ -382,6 +386,8 @@ void behaviourStateMachine(const ros::TimerEvent&)
382386
// publish current state for the operator to see
383387
stateMachineMsg.data = "WAITING";
384388

389+
// poll the logicController to get the waypoints that have been
390+
// reached.
385391
std::vector<int> cleared_waypoints = logicController.GetClearedWaypoints();
386392

387393
for(std::vector<int>::iterator it = cleared_waypoints.begin();
@@ -395,9 +401,12 @@ void behaviourStateMachine(const ros::TimerEvent&)
395401
result = logicController.DoWork();
396402
if(result.type != behavior || result.b != wait)
397403
{
404+
// if the logic controller requested that the robot drive, then
405+
// drive. Otherwise there are no manual waypoints and the robot
406+
// should sit idle. (ie. only drive according to joystick
407+
// input).
398408
sendDriveCommand(result.pd.left,result.pd.right);
399409
}
400-
//cout << endl;
401410
}
402411

403412
// publish state machine string for user, only if it has changed, though

0 commit comments

Comments
 (0)