Skip to content

Commit

Permalink
Refactored to remove param listener
Browse files Browse the repository at this point in the history
  • Loading branch information
avtoku committed Nov 27, 2024
1 parent b391037 commit 918c4f9
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 141 deletions.
20 changes: 13 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
### project settings ###

# reminders:
# cmake . -DBOARD_TO_BUILD=varmint
# cmake --build . --target clean -j
# cmake --build . -j
# to run test:
# cmake . -DBOARD_TO_BUILD=test -DCMAKE_BUILD_TYPE=Release
# make
# Building the projects:
# mkdir varmint_build && cd varmint_build && cmake .. -DBOARD_TO_BUILD=varmint && make -j
# mkdir pixracer_pro_build && cd pixracer_pro_build && cmake .. -DBOARD_TO_BUILD=pixracer_pro && make -j
#
# alternate for make -j above is cmake --build . -j (note only one .)
# make -j OR cmake --build . -j
# to clean:
# make clean -j OR make --build . --target clean -j
#
# unit test:
# build:
# mkdir test_build && cd test_build && cmake .. -DBOARD_TO_BUILD=test -DCMAKE_BUILD_TYPE=Release && make -j
# test:
# ./test/unit_tests

cmake_minimum_required(VERSION 3.8)
Expand Down
5 changes: 2 additions & 3 deletions include/comm_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#define ROSFLIGHT_FIRMWARE_COMM_MANAGER_H

#include "interface/comm_link.h"
#include "param_listener.h"

#include <stdarg.h>
#include <stdio.h>
Expand All @@ -45,7 +44,7 @@ namespace rosflight_firmware
{
class ROSflight;

class CommManager : public ParamListenerInterface
class CommManager
{
private:
enum StreamId
Expand Down Expand Up @@ -151,7 +150,7 @@ class CommManager : public ParamListenerInterface
CommManager(ROSflight & rf, CommLinkInterface & comm_link);

void init();
void param_change_callback(uint16_t param_id) override;
void param_change_callback(uint16_t param_id);
void receive(void);
void transmit(got_flags got);
void send_param_value(uint16_t param_id);
Expand Down
6 changes: 2 additions & 4 deletions include/command_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
#ifndef ROSFLIGHT_FIRMWARE_COMMAND_MANAGER_H
#define ROSFLIGHT_FIRMWARE_COMMAND_MANAGER_H

#include "param_listener.h"

#include "rc.h"

#include <cstdbool>
Expand Down Expand Up @@ -67,7 +65,7 @@ typedef struct
control_channel_t F;
} control_t;

class CommandManager : public ParamListenerInterface
class CommandManager
{
private:
typedef struct
Expand Down Expand Up @@ -152,7 +150,7 @@ class CommandManager : public ParamListenerInterface
bool stick_deviated(MuxChannel channel);

public:
void param_change_callback(uint16_t param_id) override;
void param_change_callback(uint16_t param_id);
CommandManager(ROSflight & _rf);
void init();
bool run();
Expand Down
6 changes: 2 additions & 4 deletions include/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
#ifndef ROSFLIGHT_FIRMWARE_CONTROLLER_H
#define ROSFLIGHT_FIRMWARE_CONTROLLER_H

#include "param_listener.h"

#include "command_manager.h"
#include "estimator.h"

Expand All @@ -46,7 +44,7 @@ namespace rosflight_firmware
{
class ROSflight;

class Controller : public ParamListenerInterface
class Controller
{
public:
struct Output
Expand All @@ -65,7 +63,7 @@ class Controller : public ParamListenerInterface
void run();

void calculate_equilbrium_torque_from_rc();
void param_change_callback(uint16_t param_id) override;
void param_change_callback(uint16_t param_id);

private:
class PID
Expand Down
6 changes: 2 additions & 4 deletions include/estimator.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
#ifndef ROSFLIGHT_FIRMWARE_ESTIMATOR_H
#define ROSFLIGHT_FIRMWARE_ESTIMATOR_H

#include "param_listener.h"

#include "turbomath/turbomath.h"

#include <cmath>
Expand All @@ -47,7 +45,7 @@ namespace rosflight_firmware
class ROSflight;


class Estimator : public ParamListenerInterface
class Estimator
{

public:
Expand All @@ -73,7 +71,7 @@ class Estimator : public ParamListenerInterface
inline const turbomath::Vector & gyroLPF() { return gyro_LPF_; }

void init();
void param_change_callback(uint16_t param_id) override;
void param_change_callback(uint16_t param_id);
void run();
void reset_state();
void reset_adaptive_bias();
Expand Down
6 changes: 2 additions & 4 deletions include/mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
#ifndef ROSFLIGHT_FIRMWARE_MIXER_H
#define ROSFLIGHT_FIRMWARE_MIXER_H

#include "param_listener.h"

#include <cstdbool>
#include <cstdint>

Expand All @@ -46,7 +44,7 @@ class ROSflight;

typedef RcStruct MixerStruct;

class Mixer : public ParamListenerInterface
class Mixer
{

public:
Expand Down Expand Up @@ -264,7 +262,7 @@ class Mixer : public ParamListenerInterface
void init_PWM();
void init_mixing();
void mix_output();
void param_change_callback(uint16_t param_id) override;
void param_change_callback(uint16_t param_id);
void set_new_aux_command(aux_command_t new_aux_command);
float * raw_outputs() { return raw_outputs_; }
MixerStruct * get_output_raw(void) { return &output_raw_; }
Expand Down
45 changes: 16 additions & 29 deletions include/param.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
// #pragma message( "GIT_VERSION_HASH: " STRINGIFY(GIT_VERSION_HASH))
// #pragma message( "GIT_VERSION_STRING: " GIT_VERSION_STRING)

#include "param_listener.h"

#include <cstddef>
#include <cstdint>

Expand Down Expand Up @@ -260,9 +258,6 @@ class Params
void init_param_float(uint16_t id, const char name[PARAMS_NAME_LENGTH], float value);
uint8_t compute_checksum(void);

ParamListenerInterface * const * listeners_;
size_t num_listeners_;

public:
Params(ROSflight & _rf);

Expand All @@ -278,14 +273,6 @@ class Params
*/
void set_defaults(void);

/**
* @brief Specify listeners for parameter changes
* @param listeners An array of pointers to objects that implement the ParamListenerInterface
* interface
* @param num_listeners The length of the array passed as the listeners parameter
*/
void set_listeners(ParamListenerInterface * const listeners[], size_t num_listeners);

/**
* @brief Read parameter values from non-volatile memory
* @return True if successful, false otherwise
Expand Down Expand Up @@ -358,22 +345,22 @@ class Params
*/
bool set_param_float(uint16_t id, float value);

/**
* @brief Sets the value of a parameter by name and calls the parameter change callback
* @param name The name of the parameter
* @param value The new value
* @return True if a parameter value was changed, false otherwise
*/
bool set_param_by_name_int(const char name[PARAMS_NAME_LENGTH], int32_t value);

/**
* @brief Sets the value of a floating point parameter by name and calls the parameter change
* callback
* @param name The name of the parameter
* @param value The new value
* @return True if a parameter value was changed, false otherwise
*/
bool set_param_by_name_float(const char name[PARAMS_NAME_LENGTH], float value);
// /**
// * @brief Sets the value of a parameter by name and calls the parameter change callback
// * @param name The name of the parameter
// * @param value The new value
// * @return True if a parameter value was changed, false otherwise
// */
// bool set_param_by_name_int(const char name[PARAMS_NAME_LENGTH], int32_t value);
//
// /**
// * @brief Sets the value of a floating point parameter by name and calls the parameter change
// * callback
// * @param name The name of the parameter
// * @param value The new value
// * @return True if a parameter value was changed, false otherwise
// */
// bool set_param_by_name_float(const char name[PARAMS_NAME_LENGTH], float value);
};

} // namespace rosflight_firmware
Expand Down
47 changes: 0 additions & 47 deletions include/param_listener.h

This file was deleted.

6 changes: 2 additions & 4 deletions include/rc.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
#ifndef ROSFLIGHT_FIRMWARE_RC_H
#define ROSFLIGHT_FIRMWARE_RC_H

#include "param_listener.h"

#include <cstdbool>
#include <cstdint>

Expand All @@ -43,7 +41,7 @@ namespace rosflight_firmware
{
class ROSflight;

class RC : public ParamListenerInterface
class RC
{
public:
enum Stick
Expand Down Expand Up @@ -72,7 +70,7 @@ class RC : public ParamListenerInterface
bool switch_mapped(Switch channel);
bool run();
bool new_command();
void param_change_callback(uint16_t param_id) override;
void param_change_callback(uint16_t param_id);

RcStruct * get_rc(void);
float read_chan(uint8_t chan);
Expand Down
5 changes: 0 additions & 5 deletions include/rosflight.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#define ROSFLIGHT_FIRMWARE_ROSFLIGHT_H

#include "interface/comm_link.h"
#include "param_listener.h"

#include "board.h"
#include "comm_manager.h"
Expand Down Expand Up @@ -82,10 +81,6 @@ class ROSflight

uint32_t get_loop_time_us();

private:
static constexpr size_t num_param_listeners_ = 7;
ParamListenerInterface * const param_listeners_[num_param_listeners_] = {
&comm_manager_, &command_manager_, &controller_, &estimator_, &mixer_, &rc_, &sensors_};
};

} // namespace rosflight_firmware
Expand Down
5 changes: 2 additions & 3 deletions include/sensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#ifndef ROSFLIGHT_FIRMWARE_SENSORS_H
#define ROSFLIGHT_FIRMWARE_SENSORS_H

#include "param_listener.h"

#include "turbomath/turbomath.h"

Expand All @@ -49,7 +48,7 @@ namespace rosflight_firmware
{
class ROSflight;

class Sensors : public ParamListenerInterface
class Sensors
{
public:
PressureStruct * get_diff_pressure(void) { return &diff_pressure_; }
Expand All @@ -64,7 +63,7 @@ class Sensors : public ParamListenerInterface

void init();
got_flags run();
void param_change_callback(uint16_t param_id) override;
void param_change_callback(uint16_t param_id);

// Calibration Functions
bool start_imu_calibration(void);
Expand Down
Loading

0 comments on commit 918c4f9

Please sign in to comment.