Skip to content

Commit

Permalink
* Improve message processing in fpga task
Browse files Browse the repository at this point in the history
* Improve management of the emergency stop gpio
  • Loading branch information
goldo31337 committed Apr 1, 2024
1 parent 8fed36d commit dadf0ff
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion goldobot/src/tasks/fpga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void FpgaTask::taskFunction() {
#endif

while (1) {
while (m_message_queue.message_ready()) {
if ((m_cnt%5!=0) && m_message_queue.message_ready()) {
process_message();
}

Expand Down
12 changes: 10 additions & 2 deletions goldobot/src/tasks/propulsion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ void PropulsionTask::doStep() {
m_statistics.max_interval = std::max(interval_cycles, m_statistics.max_interval);

// Process emergency gpio
auto emergency_stop = hal::gpio_get(7) ? true : false;
if (emergency_stop) {
auto gpio_emergency_stop = hal::gpio_get(7) ? true : false;
if (gpio_emergency_stop &&
((m_controller.state() == PropulsionController::State::FollowTrajectory) ||
(m_controller.state() == PropulsionController::State::Rotate))) {
m_controller.emergencyStop();
}

Expand Down Expand Up @@ -604,6 +606,12 @@ void PropulsionTask::onCommandEnd() {

m_is_executing_command = false;
if (m_controller.state() == PropulsionController::State::Error) {
#if 0 /* FIXME : TODO : try to improve the emergency stop sequence */
if ((m_controller.error() == PropulsionController::Error::EmergencyStop)) {
/* FIXME : TODO : is this OK? */
m_controller.clearError();
}
#endif
}
}

Expand Down
7 changes: 5 additions & 2 deletions libs/goldo_propulsion/src/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,18 @@ void PropulsionController::clearError() {

bool PropulsionController::commandFinished() { return m_command_finished; }

/* FIXME : DEBUG */
float debug_emergency_accel = 2.0f;

void PropulsionController::emergencyStop() {
switch (m_state) {
case State::FollowTrajectory:
m_speed_controller.setAccelerationLimits(2, 2);
m_speed_controller.setAccelerationLimits(debug_emergency_accel, debug_emergency_accel);
m_speed_controller.setRequestedSpeed(0);
m_emergency_stop = true;
return;
case State::Rotate:
m_speed_controller.setAccelerationLimits(2, 2);
m_speed_controller.setAccelerationLimits(debug_emergency_accel, debug_emergency_accel);
m_speed_controller.setRequestedSpeed(0);
m_emergency_stop = true;
return;
Expand Down

0 comments on commit dadf0ff

Please sign in to comment.