-
Notifications
You must be signed in to change notification settings - Fork 0
/
state.cpp
36 lines (31 loc) · 1.09 KB
/
state.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <stdio.h>
#include "comm/encoders_comm_data.h"
#include "comm/imu_comm_data.h"
#include "state.h"
void State::read_LSM9DS1_data(void *message_buf)
{
LSM9DS1_Message *message = static_cast<LSM9DS1_Message *>(message_buf);
if (this->check_need_imu_calibration(message))
{
if(*imu_pid) {
imu_calibrating = true;
kill(*imu_pid, SIGUSR1);
} else {
printf("Could not trigger recalibration: missing PID\n");
}
}
printf("Message from %c: %f at time %lu\n", message->sensor, message->acc_x, message->timestamp);
}
void State::read_encoder_data(void *message_buf)
{
Encoders_Message *message = static_cast<Encoders_Message *>(message_buf);
printf("Message from %c: %i at time %lu\n", message->sensor, message->left_ticks, message->timestamp);
}
bool State::check_need_imu_calibration(LSM9DS1_Message *message)
{
return message->timestamp - last_timestamp_imu > 5e6 && (message->acc_x > RECALIBRATION_THRESHOLD || -message->gyro_z < RECALIBRATION_THRESHOLD);
}
State::~State() {
delete imu_pid;
delete encoders_pid;
}