20 static constexpr struct {
26 .velocity =
"v %d %.3f %.f\n",
27 .current =
"c %d %.3f\n",
31 enum CMDS { VELO, CURR, GET, CLR };
42 if (_alive && q.
full()) {
57 if (!
drive->alive()) {
62 cmd.
len = snprintf((
char*)cmd.buf, cmd.
size, cmds.velocity,
side, speed, 0);
66 .out = std::move(cmd),
72 if (!
drive->alive()) {
77 cmd.
len = snprintf((
char*)cmd.buf, cmd.
size, cmds.get,
side);
81 .out = std::move(cmd),
86 assert(req.m ==
this);
87 if (req.cmd != GET)
return;
89 pos = strtod((
char*)resp.buf, &next);
91 vel = strtod(next,
nullptr);
99 double volt = strtod((
char*)resp.buf,
nullptr);
100 if (23. < volt && volt < 25.) {
103 }
else if (k.
time % 500 == 0) {
104 out.
trypush({(
const uint8_t*)
"r vbus_voltage\n", 16});
108 while (!in.
empty()) {
110 auto resp = in.
pop();
112 req.m->callback(req, resp);
116 if (q.
front().cmd != GET) {
const uint32_t & time
const access to global uptime
Definition kern.h:30
simple Buffer backed queue implementation
Definition queue.h:12
T pop() override
remove front of queue and return it
Definition queue.h:65
bool empty() override
check if queue is empty
Definition queue.h:83
bool full() override
return true if queue is full
Definition queue.h:87
T & front()
return reference to first element in queue
Definition queue.h:55
dynamically allocated, but fixed-size buffer template
Definition buffer.h:18
size_t size
total capacity of buffer
Definition buffer.h:23
size_t len
number of items stored in buffer
Definition buffer.h:21
single motor controlled by the ODrive interface
Definition ODrive.h:50
double pos
last measured position
Definition ODrive.h:53
void measure()
get new measurements from motor
Definition ODrive.h:71
void setSpeed(double speed)
set speed in rot/s
Definition ODrive.h:56
ODrive * drive
pointer to controlling ODrive
Definition ODrive.h:51
double vel
last measured velocity [rot/s]
Definition ODrive.h:54
uint8_t side
the ODrive hardware supports 2 Motors
Definition ODrive.h:52
support for the odriverobotics.com v3 Motor Driver UART interface
Definition ODrive.h:14
void poll()
call this regularly to check for updates
Definition ODrive.h:95
generic object sink, i.e.
Definition streams.h:15
void trypush(T &&t)
use this if you don't care if it's going to be successful. data gets discarded if sink is full.
Definition streams.h:28
generic object source, i.e.
Definition streams.h:40
virtual T pop()=0
pull object from source does not check for data. guard by using 'if (!empty) { ......
virtual bool empty()=0
check if source is empty