Skip to content

Commit 691604a

Browse files
committed
fix attempt, adding new handler for motor disable
1 parent ba6255f commit 691604a

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/network/MissionControlProtocol.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,20 @@ void MissionControlProtocol::handleOperationModeRequest(const json& j) {
7272
_autonomous_task.kill();
7373
// if we have left autonomous mode, we need to start the power repeater again.
7474
_power_repeat_task.start();
75-
}
75+
}
76+
}
77+
78+
static bool validateMotorsDisableRequest(const json& j) {
79+
return util::validateKey(j, "motors", val_t::boolean);
80+
}
81+
82+
void MissionControlProtocol::handleMotorsDisableRequest(const json& j) {
83+
bool motors = j["motors"];
84+
85+
if (!motors) {
86+
LOG_F(INFO, "Disabling motors...");
87+
this->stopAndShutdownPowerRepeat(true);
88+
}
7689
}
7790

7891
static bool validateDriveRequest(const json& j) {
@@ -314,6 +327,10 @@ MissionControlProtocol::MissionControlProtocol(SingleClientWSServer& server)
314327
validateOperationModeRequest);
315328
// drive and joint power handlers need the class for context since they must modify
316329
// _last_joint_power and _last_cmd_vel (for the repeater thread)
330+
this->addMessageHandler(
331+
"disableMotors",
332+
std::bind(&MissionControlProtocol::handleMotorsDisableRequest, this, _1),
333+
validateMotorsDisableRequest);
317334
this->addMessageHandler(
318335
DRIVE_REQ_TYPE,
319336
std::bind(&MissionControlProtocol::handleDriveRequest, this, _1),

src/network/MissionControlProtocol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class MissionControlProtocol : public WebSocketProtocol { // TODO: add documenta
4949

5050
void handleEmergencyStopRequest(const json& j);
5151
void handleOperationModeRequest(const json& j);
52+
void handleMotorsDisableRequest(const json& j);
5253
void handleTankDriveRequest(const json& j);
5354
void handleCameraStreamOpenRequest(const json& j);
5455
void handleCameraStreamCloseRequest(const json& j);

0 commit comments

Comments
 (0)