use rtos signals in wait_for_control_iteration

This commit is contained in:
Samuel Sadok
2020-11-13 18:45:49 +01:00
parent 69897ece9c
commit 6f99ce478e
3 changed files with 14 additions and 5 deletions
+6 -4
View File
@@ -104,10 +104,12 @@ void Axis::start_thread() {
* @brief Blocks until at least one complete control loop has been executed.
*/
bool Axis::wait_for_control_iteration() {
uint16_t control_iteration_num = odrv.n_evt_control_loop_;
while (odrv.n_evt_control_loop_ == control_iteration_num) {
osDelay(1);
}
osSignalWait(0x0001, osWaitForever); // this might return instantly
osSignalWait(0x0001, osWaitForever); // this might be triggered at the
// end of a control loop iteration
// which was started before we entered
// this function
osSignalWait(0x0001, osWaitForever);
return true;
}
+1 -1
View File
@@ -172,7 +172,7 @@ public:
MechanicalBrake& mechanical_brake_;
TaskTimes task_times_;
osThreadId thread_id_;
osThreadId thread_id_ = 0;
const uint32_t stack_size_ = 2048; // Bytes
volatile bool thread_id_valid_ = false;
+7
View File
@@ -378,6 +378,13 @@ void ODrive::control_loop_cb(uint32_t timestamp) {
axis.motor_.current_control_.update(timestamp); // uses the output of controller_ or open_loop_contoller_ and encoder_ or sensorless_estimator_ or async_estimator_
}
// Tell the axis threads that the control loop has finished
for (auto& axis: axes) {
if (axis.thread_id_) {
osSignalSet(axis.thread_id_, 0x0001);
}
}
get_gpio(odrv.config_.error_gpio_pin).write(odrv.any_error());
}