Basic_Frame_TypeC_2023_Omni
Loading...
Searching...
No Matches
apps_interfaces.h
1#ifndef __APPS_INTERFACES_H
2#define __APPS_INTERFACES_H
3
4#include "uarm_os.hpp"
5
6// TODO: Add startup events for apps so certain apps will start after certain events.
7// e.g. Chassis and Gimbal Apps only start when motors are detected to be online.
8// TODO: Add another template parameter for task period with getter function to access it.
9template <class Derived>
11 public:
12 void run(const void* argument) {
13 // TODO: Implement static asserts to check if derived has the following defined:
14 // - Derived::LOOP_PERIOD_MS
15 // - void init()
16 // - void calibrate()
17 // - bool exit_calibrate_cond()
18 // - void after_calibrate()
19 // - bool exit_loop_prepare_cond()
20 // - void loop_prepare()
21 // - void after_loop_prepare()
22 // - void loop()
23
24 (void) argument;
25 Derived* derived = static_cast<Derived*>(this);
26 TickType_t xLastWakeTime;
27 static_assert(Derived::LOOP_PERIOD_MS != 0);
28 const TickType_t xFrequency = pdMS_TO_TICKS(Derived::LOOP_PERIOD_MS);
29 xLastWakeTime = xTaskGetTickCount();
30 derived->init();
31 for (;;) {
32 if (derived->exit_calibrate_cond()) {
33 break;
34 } else {
35 derived->calibrate();
36 }
37 vTaskDelayUntil(&xLastWakeTime, xFrequency);
38 }
39
40 for (;;) {
41 derived->loop();
42 vTaskDelayUntil(&xLastWakeTime, xFrequency);
43 }
44 }
45};
46
47template <class Derived>
48class RTOSApp : public ExtendedRTOSApp<Derived> {
49 public:
50 void calibrate() {}
51 bool exit_calibrate_cond() { return true; }
52};
53
54// TODO Make policies sub-folder and move ChassisDrive into that folder.
55template <class Derived>
57 public:
58 void init() {
59 Derived* derived = static_cast<Derived*>(this);
60 derived->init_impl();
61 }
62
63 void drive(float vx, float vy, float wz) {
64 Derived* derived = static_cast<Derived*>(this);
65 derived->get_motor_feedback();
66 derived->calc_motor_outputs(vx, vy, wz);
67 derived->send_motor_messages();
68 }
69
70 float get_power_consumption() {
71 Derived* derived = static_cast<Derived*>(this);
72 return derived->calc_power_consumption();
73 }
74
75 void set_max_power(float new_max_power) {
76 Derived* derived = static_cast<Derived*>(this);
77 derived->set_max_power_impl(new_max_power);
78 }
79};
80
81#endif
Definition apps_interfaces.h:56
Definition apps_interfaces.h:10
Definition apps_interfaces.h:48