Skip to content

Commit

Permalink
Merge pull request #170 from rosflight/157-update-board-interface
Browse files Browse the repository at this point in the history
157 update board interface
  • Loading branch information
iandareid authored Jun 21, 2024
2 parents 4e8daa7 + aaebb4a commit a200e9c
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 152 deletions.
1 change: 0 additions & 1 deletion rosflight_sim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ endif()
# rosflight_firmware
add_library(rosflight_firmware
include/rosflight_sim/rosflight_firmware/src/rosflight.cpp
include/rosflight_sim/rosflight_firmware/src/nanoprintf.cpp
include/rosflight_sim/rosflight_firmware/src/estimator.cpp
include/rosflight_sim/rosflight_firmware/src/mixer.cpp
include/rosflight_sim/rosflight_firmware/src/controller.cpp
Expand Down
2 changes: 1 addition & 1 deletion rosflight_sim/include/rosflight_sim/rosflight_firmware
Submodule rosflight_firmware updated 67 files
+63 −48 .clang-format
+0 −19 .github/workflows/f4_firmware.yml
+5 −4 .github/workflows/lint.yml
+4 −7 .github/workflows/pre-release.yml
+15 −18 .github/workflows/release.yml
+9 −10 .github/workflows/unit_tests.yml
+3 −3 .github/workflows/varmint_firmware.yml
+11 −2 .gitignore
+3 −6 .gitmodules
+62 −0 CMakeLists.txt
+0 −86 Makefile
+3 −5 README.md
+0 −221 boards/airbourne/Makefile
+0 −1 boards/airbourne/airbourne
+0 −487 boards/airbourne/airbourne_board.cpp
+0 −212 boards/airbourne/airbourne_board.h
+0 −158 boards/airbourne/main.cpp
+0 −157 boards/breezy/Makefile
+0 −437 boards/breezy/breezy_board.cpp
+0 −181 boards/breezy/breezy_board.h
+0 −1 boards/breezy/breezystm32
+0 −86 boards/breezy/flash.c
+0 −78 boards/breezy/flash.h
+0 −51 boards/breezy/main.cpp
+1 −0 boards/varmint
+238 −262 comms/mavlink/mavlink.cpp
+40 −54 comms/mavlink/mavlink.h
+29 −25 include/board.h
+20 −26 include/comm_manager.h
+11 −9 include/command_manager.h
+5 −7 include/controller.h
+11 −12 include/estimator.h
+38 −56 include/interface/comm_link.h
+77 −48 include/mixer.h
+0 −127 include/nanoprintf.h
+20 −20 include/param.h
+2 −2 include/rc.h
+4 −4 include/rosflight.h
+23 −10 include/sensors.h
+12 −8 include/state_manager.h
+8 −9 include/util.h
+142 −184 lib/turbomath/turbomath.cpp
+27 −36 lib/turbomath/turbomath.h
+2 −2 scripts/fix-code-style.sh
+0 −110 scripts/rosflight.mk
+14 −16 scripts/run_tests.sh
+209 −273 src/comm_manager.cpp
+61 −99 src/command_manager.cpp
+75 −78 src/controller.cpp
+29 −52 src/estimator.cpp
+77 −0 src/main.cpp
+43 −86 src/mixer.cpp
+0 −261 src/nanoprintf.cpp
+21 −63 src/param.cpp
+102 −153 src/rc.cpp
+24 −22 src/rosflight.cpp
+192 −243 src/sensors.cpp
+169 −185 src/state_manager.cpp
+5 −31 test/CMakeLists.txt
+20 −34 test/command_manager_test.cpp
+12 −14 test/common.cpp
+32 −31 test/common.h
+28 −35 test/estimator_test.cpp
+24 −24 test/state_machine_test.cpp
+49 −142 test/test_board.cpp
+25 −27 test/test_board.h
+71 −79 test/turbotrig_test.cpp
132 changes: 77 additions & 55 deletions rosflight_sim/include/rosflight_sim/sil_board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#ifndef ROSFLIGHT_SIM_SIL_BOARD_H
#define ROSFLIGHT_SIM_SIL_BOARD_H

#include "sensors.h"
#include <cmath>
#include <cstdbool>
#include <cstddef>
Expand All @@ -47,6 +48,7 @@

#include <rclcpp/rclcpp.hpp>
#include <geometry_msgs/msg/twist_stamped.hpp>
#include <rosflight_msgs/msg/detail/gnss_full__struct.hpp>
#include <rosflight_msgs/msg/rc_raw.hpp>

#include <rosflight_sim/gz_compat.hpp>
Expand All @@ -65,6 +67,13 @@ class SILBoard : public UDPBoard
GazeboVector inertial_magnetic_field_;

double imu_update_rate_ = 0;
double mag_update_rate_ = 0;
double gnss_update_rate_ = 0;
double baro_update_rate_ = 0;
double diff_pressure_update_rate_ = 0;
double sonar_update_rate_ = 0;
double rc_update_rate_ = 0;
double battery_update_rate_ = 0;

long serial_delay_ns_ = 0;
std::queue<std::tuple<long, uint8_t>> serial_delay_queue_;
Expand Down Expand Up @@ -137,7 +146,21 @@ class SILBoard : public UDPBoard
// Time variables
gazebo::common::Time boot_time_;
uint64_t next_imu_update_time_us_ = 0;
uint64_t next_mag_update_time_us_ = 0;
uint64_t next_gnss_update_time_us_ = 0;
uint64_t next_baro_update_time_us_ = 0;
uint64_t next_diff_pressure_update_time_us_ = 0;
uint64_t next_sonar_update_time_us_ = 0;
uint64_t next_rc_update_time_us_ = 0;
uint64_t next_battery_update_time_us_ = 0;
uint64_t imu_update_period_us_ = 0;
uint64_t mag_update_period_us_ = 0;
uint64_t gnss_update_period_us_ = 0;
uint64_t baro_update_period_us_ = 0;
uint64_t diff_pressure_update_period_us_ = 0;
uint64_t sonar_update_period_us_ = 0;
uint64_t rc_update_period_us_ = 0;
uint64_t battery_update_period_us_ = 0;

/**
* @brief Callback function to update RC values when new values are received.
Expand Down Expand Up @@ -231,7 +254,7 @@ class SILBoard : public UDPBoard
*
* @return true if unprocessed IMU data exists.
*/
bool new_imu_data() override;
bool imu_has_new_data() override;
/**
* @brief Generates simulated IMU data from truth data from Gazebo. Utilizes noise, bias, and walk
* parameters provided. All data is returned through the values given as the function arguments.
Expand All @@ -255,15 +278,16 @@ class SILBoard : public UDPBoard
bool mag_present() override;
/**
* @brief Generates magnetometer data based on Gazebo orientation and given noise/bias parameters.
* Returns through function arguments.
*
* @param mag Magnetometer values to populate.
* @return true if successful.
*/
void mag_read(float mag[3]) override;
bool mag_read(float mag[3]) override;
/**
* @brief Function required to be overridden, but not used by sim.
* @brief Checks to see if it has been enough time to warrant new data.
* @return true if mag has new data.
*/
void mag_update() override{};
bool mag_has_new_data() override;

/**
* @brief Function used to check if a barometer is present. Currently returns true.
Expand All @@ -273,16 +297,18 @@ class SILBoard : public UDPBoard
bool baro_present() override;
/**
* @brief Generates barometer measurement based on Gazebo altitude and noise/bias parameters.
* Returns output through function arguments.
*
* @param pressure Pressure value to populate.
* @param temperature Temperature value to populate.
*
* @return true if successful.
*/
void baro_read(float * pressure, float * temperature) override;
bool baro_read(float * pressure, float * temperature) override;
/**
* @brief Function required to be overridden, but not used by sim.
* @brief Checks to see if it has been enough time to warrant new data.
* @return true if baro has new data.
*/
void baro_update() override{};
bool baro_has_new_data() override;

/**
* @brief Checks if a pitot tube sensor is present. Returns true if sim is a fixedwing sim.
Expand All @@ -292,16 +318,20 @@ class SILBoard : public UDPBoard
bool diff_pressure_present() override;
/**
* @brief Generates a differential pressure measurement based on Gazebo speed and noise/bias
* parameters. Return output through function arguments.
* parameters.
*
* @param diff_pressure Differential pressure value to populate.
* @param temperature Temperature value to populate.
*
* @return true if successful.
*/
void diff_pressure_read(float * diff_pressure, float * temperature) override;
bool diff_pressure_read(float * diff_pressure, float * temperature) override;
/**
* @brief Function required to be overridden, but not used by sim.
* @brief Checks to see if it has been enough time to warrant new data.
*
* @return true if diff_pressure sensor has new data.
*/
void diff_pressure_update() override{};
bool diff_pressure_has_new_data() override;

/**
* @brief Function used to see if a sonar altitude sensor is present. Currently returns true.
Expand All @@ -313,15 +343,19 @@ class SILBoard : public UDPBoard
* @brief Generates sonar reading based on min/max range and noise parameters. Based on Gazebo
* altitude value.
*
* @param range measurement to update.
*
* @note Currently does not take UAV attitude into account, only absolute altitude.
*
* @return Sonar reading.
* @return true if successful.
*/
float sonar_read() override;
bool sonar_read(float * range) override;
/**
* @brief Function required to be overridden, but not used by sim.
* @brief Checks to see if it has been enough time to warrant new data.
*
* @return true if sonar sensor has new data.
*/
void sonar_update() override{};
bool sonar_has_new_data() override;

// PWM
// TODO make these deal in normalized (-1 to 1 or 0 to 1) values (not pwm-specific)
Expand Down Expand Up @@ -356,7 +390,7 @@ class SILBoard : public UDPBoard
* @param channel Channel to read value from.
* @return 0.5
*/
float rc_read(uint8_t channel) override;
float rc_read(uint8_t chan) override;
/**
* @brief Function required to be overridden, but not used by sim.
*/
Expand All @@ -368,6 +402,12 @@ class SILBoard : public UDPBoard
* @return False if /RC has had a message published, true otherwise.
*/
bool rc_lost() override;
/**
* @brief Checks to see if it has been enough time to warrant new data.
*
* @return true if rc has new data.
*/
bool rc_has_new_data() override;

// non-volatile memory
/**
Expand Down Expand Up @@ -446,77 +486,59 @@ class SILBoard : public UDPBoard
* @param len Length of data to clear.
*/
void backup_memory_clear(size_t len) override;

/**
* @brief Function used to check if GNSS is present. Currenlty returns true.
*
* @return true
*/
bool gnss_present() override;
/**
* @brief Function required to be overridden, but not used by sim.
*/
void gnss_update() override{};

/**
* @brief Generates GNSS data based on Gazebo truth and noise/bias parameters.
*
* @return Populated GNSSData object
* @param gnss GNSSData object to update.
* @param gnss_full GNSSFull object to update.
*
* @return true if successful.
*/
rosflight_firmware::GNSSData gnss_read() override;
bool gnss_read(rosflight_firmware::GNSSData * gnss, rosflight_firmware::GNSSFull * gnss_full) override;
/**
* @brief Function used to check if gnss has new data to read. Currently returns true.
* @brief Checks to see if it has been enough time to warrant new data.
*
* @return true
*/
bool gnss_has_new_data() override;
/**
* @brief Generates GNSSFull data based on Gazebo truth and noise/bias parameters.
* @brief Function used to check if a battery is present. Currenlty returns true.
*
* @return Populated GNSSFull object
* @return true
*/
rosflight_firmware::GNSSFull gnss_full_read() override;

bool battery_present() override;
/**
* @brief Function used to check if battery volt meter is present. Currently returns true.
* @brief Checks to see if it has been enough time to warrant new data.
*
* @return true
* @return true if battery has new data.
*/
bool battery_voltage_present() const override;
bool battery_has_new_data() override;
/**
* @brief Checks battery voltage. Currently just returns constant value.
* @brief Creates battery data based on sim model.
*
* @note No battery simulation exists, function returns constant value.
* @param voltage The voltage float to update
* @param current The current float to update
*
* @return Battery voltage
* @return true if successful.
*/
float battery_voltage_read() const override;
bool battery_read(float * voltage, float * current) override;
/**
* @brief Sets battery voltage calibration constant.
*
* @param multiplier Voltage calibration constant
*/
void battery_voltage_set_multiplier(double multiplier) override;

/**
* @brief Function used to check if current meter is present. Currently returns true.
* @brief Sets battery current calibration constant.
*
* @return true
* @param multiplier Current calibration constant
*/
bool battery_current_present() const override;
/**
* @brief Checks battery current draw. Currently just returns constant value.
*
* @note No battery simulation exists, function returns constant value.
*
* @return Battery current draw
*/
float battery_current_read() const override;
/**
* @brief Sets battery current calibration constant.
*
* @param multiplier Current calibration constant
*/
void battery_current_set_multiplier(double multiplier) override;

// Gazebo stuff
Expand Down
2 changes: 1 addition & 1 deletion rosflight_sim/include/rosflight_sim/udp_board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class UDPBoard : public rosflight_firmware::Board
~UDPBoard();

void serial_init(uint32_t baud_rate, uint32_t dev) override;
void serial_write(const uint8_t * src, size_t len) override;
void serial_write(const uint8_t * src, size_t len, uint8_t qos) override;
uint16_t serial_bytes_available() override;
uint8_t serial_read() override;
void serial_flush() override;
Expand Down
Loading

0 comments on commit a200e9c

Please sign in to comment.