Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • avn/swd/skyward-boardcore
  • emilio.corigliano/skyward-boardcore
  • nicolo.caruso/skyward-boardcore
  • ettore.pane/skyward-boardcore
  • giulia.facchi/skyward-boardcore
  • valerio.flamminii/skyward-boardcore
6 results
Show changes
Showing
with 415 additions and 431 deletions
......@@ -27,8 +27,8 @@
// The PARSING_FROM_IDE is because Netbeans gets confused by this, it is never
// defined when compiling the code.
#ifndef PARSING_FROM_IDE
//#error This error is a reminder that you have not edited miosix_settings.h
// yet.
// #error This error is a reminder that you have not edited miosix_settings.h
// yet.
#endif // PARSING_FROM_IDE
/**
......@@ -70,14 +70,14 @@ namespace miosix
// Uncomment only *one* of those
#define SCHED_TYPE_PRIORITY
//#define SCHED_TYPE_CONTROL_BASED
//#define SCHED_TYPE_EDF
// #define SCHED_TYPE_CONTROL_BASED
// #define SCHED_TYPE_EDF
/// \def WITH_CPU_TIME_COUNTER
/// Allows to enable/disable CPUTimeCounter to save code size and remove its
/// overhead from the scheduling process. By default it is not defined
/// (CPUTimeCounter is disabled).
//#define WITH_CPU_TIME_COUNTER
// #define WITH_CPU_TIME_COUNTER
//
// Filesystem options
......@@ -110,7 +110,7 @@ const unsigned char MAX_OPEN_FILES = 8;
/// This enables the dynamic loader to load elf programs, the extended system
/// call service and, if the hardware supports it, the MPU to provide memory
/// isolation of processes
//#define WITH_PROCESSES
// #define WITH_PROCESSES
#if defined(WITH_PROCESSES) && defined(__NO_EXCEPTIONS)
#error Processes require C++ exception support
......@@ -145,7 +145,7 @@ const unsigned char MAX_OPEN_FILES = 8;
/// \def WITH_DEEP_SLEEP
/// Adds interfaces and required variables to support deep sleep state switch
/// automatically when peripherals are not required
//#define WITH_DEEP_SLEEP
// #define WITH_DEEP_SLEEP
/**
* \def JTAG_DISABLE_SLEEP
......
......@@ -49,8 +49,7 @@ void program_startup()
// enabled
__disable_irq();
miosix::IRQconfigureCache((const unsigned int *)0xd0000000,
8 * 1024 * 1024);
miosix::IRQconfigureCache((const unsigned int*)0xd0000000, 8 * 1024 * 1024);
// These are defined in the linker script
extern unsigned char _etext asm("_etext");
......@@ -60,11 +59,11 @@ void program_startup()
extern unsigned char _bss_end asm("_bss_end");
// Initialize .data section, clear .bss section
unsigned char *etext = &_etext;
unsigned char *data = &_data;
unsigned char *edata = &_edata;
unsigned char *bss_start = &_bss_start;
unsigned char *bss_end = &_bss_end;
unsigned char* etext = &_etext;
unsigned char* data = &_data;
unsigned char* edata = &_edata;
unsigned char* bss_start = &_bss_start;
unsigned char* bss_end = &_bss_end;
memcpy(data, etext, edata - data);
memset(bss_start, 0, bss_end - bss_start);
......
......@@ -233,9 +233,9 @@ void configureBackupSram()
extern unsigned char _preserve_end asm("_preserve_end");
extern unsigned char _preserve_load asm("_preserve_load");
unsigned char *preserve_start = &_preserve_start;
unsigned char *preserve_end = &_preserve_end;
unsigned char *preserve_load = &_preserve_load;
unsigned char* preserve_start = &_preserve_start;
unsigned char* preserve_end = &_preserve_end;
unsigned char* preserve_load = &_preserve_load;
// Load the .preserve section from flash if not a software reset
if (miosix::lastResetReason() != miosix::ResetReason::SOFTWARE)
......@@ -257,80 +257,80 @@ void IRQbspInit()
userLed4::mode(Mode::OUTPUT);
// RIG stuff
interfaces::spi1::sck::mode(Mode::ALTERNATE);
interfaces::spi1::sck::alternateFunction(5);
interfaces::spi1::miso::mode(Mode::ALTERNATE);
interfaces::spi1::sck::mode(Mode::ALTERNATE);
interfaces::spi1::miso::alternateFunction(5);
interfaces::spi1::mosi::mode(Mode::ALTERNATE);
interfaces::spi1::miso::mode(Mode::ALTERNATE);
interfaces::spi1::mosi::alternateFunction(5);
interfaces::spi1::mosi::mode(Mode::ALTERNATE);
interfaces::spi2::sck::mode(Mode::ALTERNATE);
interfaces::spi2::sck::alternateFunction(5);
interfaces::spi2::miso::mode(Mode::ALTERNATE);
interfaces::spi2::sck::mode(Mode::ALTERNATE);
interfaces::spi2::miso::alternateFunction(5);
interfaces::spi2::mosi::mode(Mode::ALTERNATE);
interfaces::spi2::miso::mode(Mode::ALTERNATE);
interfaces::spi2::mosi::alternateFunction(5);
interfaces::spi2::mosi::mode(Mode::ALTERNATE);
interfaces::spi3::sck::mode(Mode::ALTERNATE);
interfaces::spi3::sck::alternateFunction(6);
interfaces::spi3::miso::mode(Mode::ALTERNATE);
interfaces::spi3::sck::mode(Mode::ALTERNATE);
interfaces::spi3::miso::alternateFunction(6);
interfaces::spi3::mosi::mode(Mode::ALTERNATE);
interfaces::spi3::miso::mode(Mode::ALTERNATE);
interfaces::spi3::mosi::alternateFunction(5);
interfaces::spi3::mosi::mode(Mode::ALTERNATE);
/* Do not enable Flavio's bullshit
interfaces::spi4::sck::mode(Mode::ALTERNATE);
interfaces::spi4::sck::alternateFunction(5);
interfaces::spi4::miso::mode(Mode::ALTERNATE);
interfaces::spi4::sck::mode(Mode::ALTERNATE);
interfaces::spi4::miso::alternateFunction(5);
interfaces::spi4::mosi::mode(Mode::ALTERNATE);
interfaces::spi4::miso::mode(Mode::ALTERNATE);
interfaces::spi4::mosi::alternateFunction(5);
interfaces::spi4::mosi::mode(Mode::ALTERNATE);
*/
interfaces::spi6::sck::mode(Mode::ALTERNATE);
interfaces::spi6::sck::alternateFunction(5);
interfaces::spi6::miso::mode(Mode::ALTERNATE);
interfaces::spi6::sck::mode(Mode::ALTERNATE);
interfaces::spi6::miso::alternateFunction(5);
interfaces::spi6::mosi::mode(Mode::ALTERNATE);
interfaces::spi6::miso::mode(Mode::ALTERNATE);
interfaces::spi6::mosi::alternateFunction(5);
interfaces::spi6::mosi::mode(Mode::ALTERNATE);
// We do not need to setup the miosix usart
interfaces::uart4::tx::mode(Mode::ALTERNATE);
interfaces::uart4::tx::alternateFunction(8);
interfaces::uart4::rx::mode(Mode::ALTERNATE);
interfaces::uart4::tx::mode(Mode::ALTERNATE);
interfaces::uart4::rx::alternateFunction(8);
interfaces::uart4::rx::mode(Mode::ALTERNATE);
interfaces::can1::tx::mode(Mode::ALTERNATE);
interfaces::can1::tx::alternateFunction(9);
interfaces::can1::rx::mode(Mode::ALTERNATE);
interfaces::can1::tx::mode(Mode::ALTERNATE);
interfaces::can1::rx::alternateFunction(9);
interfaces::can1::rx::mode(Mode::ALTERNATE);
interfaces::can2::tx::mode(Mode::ALTERNATE);
interfaces::can2::tx::alternateFunction(9);
interfaces::can2::rx::mode(Mode::ALTERNATE);
interfaces::can2::tx::mode(Mode::ALTERNATE);
interfaces::can2::rx::alternateFunction(9);
interfaces::can2::rx::mode(Mode::ALTERNATE);
interfaces::timers::tim1ch1::mode(Mode::ALTERNATE);
interfaces::timers::tim1ch1::alternateFunction(1);
interfaces::timers::tim3ch3::mode(Mode::ALTERNATE);
interfaces::timers::tim1ch1::mode(Mode::ALTERNATE);
interfaces::timers::tim3ch3::alternateFunction(2);
interfaces::timers::tim4ch1::mode(Mode::ALTERNATE);
interfaces::timers::tim3ch3::mode(Mode::ALTERNATE);
interfaces::timers::tim4ch1::alternateFunction(2);
interfaces::timers::tim5ch3::mode(Mode::ALTERNATE);
interfaces::timers::tim4ch1::mode(Mode::ALTERNATE);
interfaces::timers::tim5ch3::alternateFunction(2);
interfaces::timers::tim8ch1::mode(Mode::ALTERNATE);
interfaces::timers::tim5ch3::mode(Mode::ALTERNATE);
interfaces::timers::tim8ch1::alternateFunction(3);
interfaces::timers::tim8ch2::mode(Mode::ALTERNATE);
interfaces::timers::tim8ch1::mode(Mode::ALTERNATE);
interfaces::timers::tim8ch2::alternateFunction(3);
interfaces::timers::tim9ch2::mode(Mode::ALTERNATE);
interfaces::timers::tim8ch2::mode(Mode::ALTERNATE);
interfaces::timers::tim9ch2::alternateFunction(3);
interfaces::timers::tim10ch1::mode(Mode::ALTERNATE);
interfaces::timers::tim9ch2::mode(Mode::ALTERNATE);
interfaces::timers::tim10ch1::alternateFunction(3);
interfaces::timers::tim11ch1::mode(Mode::ALTERNATE);
interfaces::timers::tim10ch1::mode(Mode::ALTERNATE);
interfaces::timers::tim11ch1::alternateFunction(3);
interfaces::timers::tim12ch2::mode(Mode::ALTERNATE);
interfaces::timers::tim11ch1::mode(Mode::ALTERNATE);
interfaces::timers::tim12ch2::alternateFunction(9);
interfaces::timers::tim12ch2::mode(Mode::ALTERNATE);
interfaces::adcs::adc12in9::mode(Mode::INPUT_ANALOG);
interfaces::adcs::adc123in11::mode(Mode::INPUT_ANALOG);
......
......@@ -242,4 +242,4 @@ using nitrogen = miosix::interfaces::relays::relay2;
using armLight = miosix::interfaces::relays::relay3;
} // namespace relays
} // namespace miosix
\ No newline at end of file
} // namespace miosix
......@@ -238,8 +238,8 @@ void calibrateAccelerometer()
{
bmx160->sample();
uint8_t fifoSize = bmx160->getLastFifoSize();
auto& fifo = bmx160->getLastFifo();
uint16_t fifoSize;
const auto fifo = bmx160->getLastFifo(fifoSize);
for (uint8_t ii = 0; ii < fifoSize; ii++)
{
......@@ -333,9 +333,8 @@ void calibrateMagnetometer()
[&]()
{
bmx160->sample();
uint8_t fifoSize = bmx160->getLastFifoSize();
auto& fifo = bmx160->getLastFifo();
uint16_t fifoSize;
const auto fifo = bmx160->getLastFifo(fifoSize);
for (uint8_t i = 0; i < fifoSize; i++)
{
......@@ -409,8 +408,8 @@ void calibrateGyroscope()
{
bmx160->sample();
uint8_t fifoSize = bmx160->getLastFifoSize();
auto& fifo = bmx160->getLastFifo();
uint16_t fifoSize;
const auto fifo = bmx160->getLastFifo(fifoSize);
for (uint8_t i = 0; i < fifoSize; i++)
{
......
......@@ -33,10 +33,10 @@ using namespace miosix;
struct PinDef
{
GpioPin pin;
const char *gpio_name;
const char *conan_name;
const char* gpio_name;
const char* conan_name;
// ADRIANOOOOOOOOOOOOOOOO
const char *breakout_v1_name;
const char* breakout_v1_name;
};
std::array<PinDef, 53> PIN_DEFS{{
......@@ -271,7 +271,7 @@ void sd_test()
puts("*** Starting SD test...");
bool ok = true;
FILE *f = fopen("/sd/test.bin", "wb");
FILE* f = fopen("/sd/test.bin", "wb");
if (f == NULL)
{
puts("Failed to open test.bin");
......@@ -299,9 +299,7 @@ void sd_test()
}
if (f != NULL)
{
fclose(f);
}
if (ok)
{
......@@ -344,37 +342,29 @@ void sd_test()
}
if (f != NULL)
{
fclose(f);
}
if (ok)
{
puts("*** SD test succesfull!");
}
else
{
puts("*** SD test failed!");
}
}
void xram_test()
{
volatile uint16_t *const START = (volatile uint16_t *)0xd0000000;
volatile uint16_t *const END = START + (16 * 1024 * 1024);
volatile uint16_t* const START = (volatile uint16_t*)0xd0000000;
volatile uint16_t* const END = START + (16 * 1024 * 1024);
// First clear the whole RAM
for (volatile uint16_t *iter = START; iter != END; iter++)
{
for (volatile uint16_t* iter = START; iter != END; iter++)
*iter = 0;
}
__DMB(); // Flush cache
puts("*** Starting basic XRAM test...");
bool ok = true;
for (volatile uint16_t *iter = START; iter != END; iter++)
for (volatile uint16_t* iter = START; iter != END; iter++)
{
// Set a marker value at this address
*iter = 0xffff;
......@@ -392,13 +382,9 @@ void xram_test()
}
if (ok)
{
puts("*** XRAM basic test succesfull!");
}
else
{
puts("*** XRAM basic test failed!");
}
puts("*** Starting XRAM mirroring test...");
ok = true;
......@@ -406,20 +392,18 @@ void xram_test()
// Generate addresses to test every line
for (int i = 1; i < 25; i++)
{
volatile uint16_t *other =
(volatile uint16_t *)((size_t)START | (1 << i));
volatile uint16_t* other =
(volatile uint16_t*)((size_t)START | (1 << i));
// Write something
*other = 0xdead;
__DMB(); // Flush cache
for (volatile uint16_t *iter = START; iter != END; iter++)
for (volatile uint16_t* iter = START; iter != END; iter++)
{
// Skip the written address
if (iter == other)
{
continue;
}
// Check for mirroring
if (*iter == 0xdead)
......@@ -435,31 +419,25 @@ void xram_test()
}
if (ok)
{
puts("*** XRAM mirror test succesfull!");
}
else
{
puts("*** XRAM mirror test failed!");
}
}
void pin_continuity_test()
{
for (auto &a : PIN_DEFS)
{
for (auto& a : PIN_DEFS)
a.pin.mode(Mode::INPUT_PULL_DOWN);
}
puts("*** Starting pin continuity test...");
bool ok = true;
// Ok now start testing
for (auto &a : PIN_DEFS)
for (auto& a : PIN_DEFS)
{
a.pin.mode(Mode::OUTPUT);
a.pin.high();
for (auto &b : PIN_DEFS)
for (auto& b : PIN_DEFS)
{
if (a.pin.getNumber() == b.pin.getNumber() &&
a.pin.getPort() == b.pin.getPort())
......@@ -479,18 +457,14 @@ void pin_continuity_test()
}
if (ok)
{
puts("*** Pin continuity test succesfull!");
}
else
{
puts("*** Pin continuity test failed!");
}
}
void pin_semi_test()
{
for (auto &a : PIN_DEFS)
for (auto& a : PIN_DEFS)
{
a.pin.mode(Mode::OUTPUT);
a.pin.low();
......@@ -523,7 +497,7 @@ void pin_semi_test()
for (size_t i = 0; i < PIN_DEFS.size(); i++)
{
PinDef &a = PIN_DEFS[i];
PinDef& a = PIN_DEFS[i];
// Pause waiting for keys
while (getchar() != '\n')
......
......@@ -85,13 +85,9 @@ int main()
bool configStatus = gamma.configure(newConf);
if (configStatus == true)
{
printf("New configuration set!\n");
}
else
{
printf("Failed to set new configuration!\n");
}
Thread::sleep(500);
}
......@@ -104,8 +100,6 @@ int main()
void waitForButton()
{
while (1)
{
if (button::value() == 1)
break; // Wait for button
}
}
This diff is collapsed.
......@@ -47,19 +47,17 @@ int main()
GpioPin tx(GPIOB_BASE, 6);
GpioPin rx(GPIOB_BASE, 7);
tx.mode(Mode::ALTERNATE);
rx.mode(Mode::ALTERNATE);
tx.alternateFunction(7);
rx.alternateFunction(7);
tx.mode(Mode::ALTERNATE);
rx.mode(Mode::ALTERNATE);
USART usart1(USART1, 115200);
Runcam test(usart1);
if (!test.init())
{
return -1;
}
char c;
while (true)
......@@ -72,17 +70,11 @@ int main()
test.selectSetting();
test.openMenu();
if (c == 'd')
{
test.moveDown();
}
else if (c == 'c')
{
test.selectSetting();
}
else if (c == 'o')
{
test.openMenu();
}
}
test.close();
......
......@@ -76,10 +76,14 @@ int main()
for (size_t bufferSize : BUFFER_SIZES)
{
if (benchmark(bufferSize, data))
{
printResults(bufferSize, data);
}
else
{
printf("Error while performing the benchmark (buffer size: %lu)\n",
(unsigned long)bufferSize);
}
}
printf("Test completed\n");
......
......@@ -78,8 +78,8 @@ using sck = radio::sck;
using miso = radio::miso;
using mosi = radio::mosi;
using txen = radio::txEn;
using rxen = radio::rxEn;
using txen = radio::txEn;
using rxen = radio::rxEn;
#define SX1278_SPI SPI4
......@@ -146,10 +146,10 @@ using rst = miosix::radio2::nrst;
#ifdef SX1278_IS_LORA
static constexpr size_t SX1278_MTU = Boardcore::SX1278Lora::MTU;
Boardcore::SX1278Lora *sx1278 = nullptr;
Boardcore::SX1278Lora* sx1278 = nullptr;
#else
static constexpr size_t SX1278_MTU = Boardcore::SX1278Fsk::MTU;
Boardcore::SX1278Fsk *sx1278 = nullptr;
Boardcore::SX1278Fsk* sx1278 = nullptr;
#endif
volatile int dio0_cnt = 0;
......@@ -220,9 +220,7 @@ void sendLoop()
auto serial = miosix::DefaultConsole::instance().get();
int len = serial->readBlock(msg, sizeof(msg), 0);
if (len > 0)
{
sx1278->send(msg, len);
}
}
}
......@@ -239,11 +237,11 @@ int main()
#elif defined SX1278_IS_SKYWARD433
printf("[sx1278] Confuring Skyward 433 frontend...\n");
std::unique_ptr<Boardcore::SX1278::ISX1278Frontend> frontend(
new Boardcore::Skyward433Frontend());
new Boardcore::Skyward433Frontend());
#else
printf("[sx1278] Confuring RA01 frontend...\n");
std::unique_ptr<Boardcore::SX1278::ISX1278Frontend> frontend(
new Boardcore::RA01Frontend());
new Boardcore::RA01Frontend());
#endif
#ifdef SX1278_IS_LORA
......@@ -273,14 +271,14 @@ int main()
config.enable_crc = false;
sx1278 = new Boardcore::SX1278Fsk(sx1278_bus, cs::getPin(), dio0::getPin(),
dio1::getPin(), dio3::getPin(),
Boardcore::SPI::ClockDivider::DIV_256,
std::move(frontend));
dio1::getPin(), dio3::getPin(),
Boardcore::SPI::ClockDivider::DIV_256,
std::move(frontend));
printf("\n[sx1278] Configuring sx1278 fsk...\n");
if ((err = sx1278->init(config)) != Boardcore::SX1278Fsk::Error::NONE)
{
// FIXME: Why does clang-format put this line up here?
// FIXME: Why does clang-format put this line up here?
printf("[sx1278] sx1278->init error\n");
return false;
}
......
......@@ -37,7 +37,6 @@ namespace Boardcore
*/
class ActiveObject
{
public:
/**
* Constructor. This will create the AO, but will NOT start the thread
......@@ -48,7 +47,7 @@ public:
ActiveObject(unsigned int stacksize = miosix::STACK_DEFAULT_FOR_PTHREAD,
miosix::Priority priority = miosix::MAIN_PRIORITY);
virtual ~ActiveObject(){};
virtual ~ActiveObject() {};
/**
* @brief Start the thread associated with this active object.
......@@ -125,9 +124,7 @@ inline bool ActiveObject::start()
miosix::Thread::JOINABLE);
if (thread == nullptr)
{
running = false;
}
return running;
}
......
......@@ -42,7 +42,7 @@ public:
* @param timer Timer used to provide the alternating on and off signal.
* @param channel Timer channel to output the signal.
*/
Buzzer(TIM_TypeDef *timer, TimerUtils::Channel channel);
Buzzer(TIM_TypeDef* timer, TimerUtils::Channel channel);
/**
* @brief Turns on the buzzer.
......@@ -80,7 +80,7 @@ private:
TimerUtils::Channel channel;
};
inline Buzzer::Buzzer(TIM_TypeDef *timer, TimerUtils::Channel channel)
inline Buzzer::Buzzer(TIM_TypeDef* timer, TimerUtils::Channel channel)
: timer(timer), channel(channel)
{
}
......
......@@ -45,26 +45,18 @@ Stepper::Stepper(miosix::GpioPin stepPin, miosix::GpioPin directionPin,
void Stepper::enable()
{
if (pinConfig == PinConfiguration::COMMON_CATHODE)
{
enablePin.low();
}
else
{
enablePin.high();
}
enabled = true;
}
void Stepper::disable()
{
if (pinConfig == PinConfiguration::COMMON_CATHODE)
{
enablePin.high();
}
else
{
enablePin.low();
}
enabled = false;
}
......@@ -138,24 +130,16 @@ void Stepper::move(int16_t steps)
for (int i = 0; i < stepsAbs; i++)
{
if (pinConfig == PinConfiguration::COMMON_CATHODE)
{
stepPin.high();
}
else
{
stepPin.low();
}
miosix::delayUs(halfStepDelay);
if (pinConfig == PinConfiguration::COMMON_CATHODE)
{
stepPin.low();
}
else
{
stepPin.high();
}
miosix::delayUs(halfStepDelay);
}
......@@ -170,4 +154,4 @@ StepperData Stepper::getState(float moveDeg)
speed, moveDeg};
}
} // namespace Boardcore
\ No newline at end of file
} // namespace Boardcore
......@@ -195,4 +195,4 @@ inline int16_t Stepper::getCurrentPosition()
inline float Stepper::getCurrentDegPosition() { return currentPositionDeg; }
} // namespace Boardcore
\ No newline at end of file
} // namespace Boardcore
......@@ -24,7 +24,7 @@
namespace Boardcore
{
StepperPWM::StepperPWM(CountedPWM &pwm, miosix::GpioPin stepPin,
StepperPWM::StepperPWM(CountedPWM& pwm, miosix::GpioPin stepPin,
miosix::GpioPin directionPin, float speed,
float stepAngle, bool revertDirection,
uint16_t microStep, PinConfiguration pinConfiguration,
......@@ -96,4 +96,4 @@ float StepperPWM::getCurrentDegPosition()
currentDirection * pwm.getCurrentCount() * stepAngle / microStep;
}
} // namespace Boardcore
\ No newline at end of file
} // namespace Boardcore
......@@ -49,7 +49,7 @@ public:
* @param revertDirection Whether or not revert the direction signal.
*/
StepperPWM(
CountedPWM &pwm, miosix::GpioPin stepPin, miosix::GpioPin directionPin,
CountedPWM& pwm, miosix::GpioPin stepPin, miosix::GpioPin directionPin,
float speed = 1, float stepAngle = 1.8, bool revertDirection = false,
uint16_t microStep = 1,
PinConfiguration pinConfiguration = PinConfiguration::COMMON_CATHODE,
......@@ -93,12 +93,12 @@ public:
private:
// This class is not copyable!
StepperPWM &operator=(const StepperPWM &) = delete;
StepperPWM(const StepperPWM &p) = delete;
StepperPWM& operator=(const StepperPWM&) = delete;
StepperPWM(const StepperPWM& p) = delete;
void setDirection();
CountedPWM &pwm;
CountedPWM& pwm;
};
} // namespace Boardcore
\ No newline at end of file
} // namespace Boardcore
......@@ -35,9 +35,9 @@ namespace Boardcore
AirBrakesInterp::AirBrakesInterp(
std::function<TimedTrajectoryPoint()> getCurrentPosition,
const TrajectorySet &trajectoryOpenSet,
const TrajectorySet &trajectoryCloseSet,
const AirBrakesInterpConfig &configInterp,
const TrajectorySet& trajectoryOpenSet,
const TrajectorySet& trajectoryCloseSet,
const AirBrakesInterpConfig& configInterp,
std::function<void(float)> setActuator)
: getCurrentPosition(getCurrentPosition), setActuator(setActuator),
trajectoryOpenSet(trajectoryOpenSet),
......@@ -149,12 +149,18 @@ float AirBrakesInterp::controlInterp(TrajectoryPoint currentPosition)
// trjPointOpen.vz);
if (currentPosition.vz <= trjPointClosed.vz)
{
return 0;
}
else if (currentPosition.vz >= trjPointOpen.vz)
{
return 1;
}
else
{
return (currentPosition.vz - trjPointClosed.vz) /
(trjPointOpen.vz - trjPointClosed.vz);
}
}
} // namespace Boardcore
......@@ -37,9 +37,9 @@ class AirBrakesInterp : public Algorithm
{
public:
AirBrakesInterp(std::function<TimedTrajectoryPoint()> getCurrentPosition,
const TrajectorySet &trajectoryOpenSet,
const TrajectorySet &trajectoryCloseSet,
const AirBrakesInterpConfig &configInterp,
const TrajectorySet& trajectoryOpenSet,
const TrajectorySet& trajectoryCloseSet,
const AirBrakesInterpConfig& configInterp,
std::function<void(float)> setActuator);
bool init() override;
......@@ -74,12 +74,12 @@ private:
// Trajectory sets (open and closed) from which the algorithm will choose at
// the beginning the tuple with which interpolate the data. The selection
// depends on the rocket mass.
const TrajectorySet &trajectoryOpenSet;
const TrajectorySet &trajectoryCloseSet;
const TrajectorySet& trajectoryOpenSet;
const TrajectorySet& trajectoryCloseSet;
// Choosen trajectories from the begin function
Trajectory *choosenCloseTrajectory = nullptr;
Trajectory *choosenOpenTrajectory = nullptr;
Trajectory* choosenCloseTrajectory = nullptr;
Trajectory* choosenOpenTrajectory = nullptr;
AirBrakesInterpConfig configInterp; ///< specialized config
float lastPercentage = 0; ///< last opening of the airbrakes
......
......@@ -38,7 +38,7 @@ namespace Boardcore
AirBrakesPI::AirBrakesPI(
std::function<TimedTrajectoryPoint()> getCurrentPosition,
const TrajectorySet &trajectorySet, const AirBrakesPIConfig &config,
const TrajectorySet& trajectorySet, const AirBrakesPIConfig& config,
std::function<void(float)> setActuator)
: getCurrentPosition(getCurrentPosition), config(config),
setActuator(setActuator), pi(config.KP, config.KI, config.TS),
......@@ -81,7 +81,7 @@ float AirBrakesPI::getRho(float z)
return Constants::RHO_0 * expf(-z / Constants::Hn);
}
float AirBrakesPI::getSurface(const TimedTrajectoryPoint &currentPosition,
float AirBrakesPI::getSurface(const TimedTrajectoryPoint& currentPosition,
float rho, float targetDrag)
{
float bestDDrag = numeric_limits<float>::infinity();
......@@ -168,7 +168,7 @@ void AirBrakesPI::chooseTrajectory(TrajectoryPoint currentPosition)
for (uint8_t trjIndex = 0; trjIndex < trajectorySet.length(); trjIndex++)
{
Trajectory &trajectory = trajectorySet.trajectories[trjIndex];
Trajectory& trajectory = trajectorySet.trajectories[trjIndex];
for (uint32_t ptIndex = 0; ptIndex < trajectory.size(); ptIndex++)
{
......