Enable fan pin 20 through raspi-config
```
-sudo apt install -y cmake build-essential checkinstall zlib1g-dev libssl-dev python3 python3-pip ninja-build git ufw python3-picamera2 libspdlog-dev libeigen3-dev --no-install-recommends
+sudo apt install -y cmake build-essential checkinstall zlib1g-dev libssl-dev python3 python3-pip ninja-build git ufw python3-picamera2 libspdlog-dev libeigen3-dev libx264-dev libjpeg-dev --no-install-recommends
```
based a bit on [example](https://github.com/mavlink/mavlink/blob/master/examples/c/udp_example.c).
void Complementary_filter::update(const vec3d &gyro_meas, const vec3d &accel_meas,
double dt_sec, unsigned int gyro_range, unsigned int accel_range)
{
- /*
- // Crude check for new data
- if (last_accel_meas == accel_meas)
- {
- logger->warn("Last accel measurement indentical to new.");
- }
- if (last_gyro_meas == gyro_meas)
- {
- logger->warn("Last gyro measurement identical to new.");
- }
- last_accel_meas = accel_meas;
- last_gyro_meas = gyro_meas;
- */
-
auto accel_est = accel_to_pitch_roll(accel_meas);
auto gyro_est = pqr_to_euler(gyro_meas, current_state);
{
THREAD_SLEEP(CLICK_READ_SPI_PERIOD);
+ /* __________________________________________________________ */
std::lock_guard<std::mutex> lk{data_lock};
logger->debug("Controlling!");
accel_vec = struct_to_vec_scaled(accel_data, (GRAVITY * 16.0) / 32768.0);
comp_filter.update(gyro_vec, accel_vec, time_d);
+
+ /* __________________________________________________________ */
}
close(sendpipe_fd);
while (true)
{
THREAD_SLEEP(CONTROLLER_MAVLINK_PERIOD);
- std::lock_guard<std::mutex> lk{data_lock};
-
logger->debug("Sending IMU Mavlink.");
-
+
+ /* __________________________________________________________ */
+ data_lock.lock();
+
// Pack data into MAVLINK packages
attitude.time_boot_ms = system_uptime_ms();
attitude.roll = comp_filter.get_state()[1];
scaled_imu.ymag = INT16_MAX;
scaled_imu.zmag = INT16_MAX;
+ data_lock.unlock();
+ /* __________________________________________________________ */
+
mavlink_msg_attitude_encode(
MAV_SYS_ID,
MAV_COMP_ID,