Skip to content

Commit

Permalink
Set up CI/CD and pre commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
NidasioAlberto committed Feb 1, 2022
1 parent 1b75f95 commit 22c46e7
Show file tree
Hide file tree
Showing 134 changed files with 2,361 additions and 2,109 deletions.
103 changes: 86 additions & 17 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,93 @@
# This file is a template, and might need editing before it works on your project.
# see https://docs.gitlab.com/ce/ci/yaml/README.html for all available options

# you can delete this line if you're not using Docker
#image: busybox:latest
# Copyright (c) 2021 Skyward Experimental Rocketry
# Authors: Luca Erbetta, Luca Conterio, Alberto Nidasio, Damiano Amatruda
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

variables:
GIT_SUBMODULE_STRATEGY: recursive


build1:
stage: build
stages:
- build-release
- build-debug
- test
- lint
- documentation

# Stage build-release

build-release:
stage: build-release
tags:
- miosix
script:
- ./sbs --jobs 2

# Stage build-debug

build-debug:
stage: build-debug
tags:
- miosix
script:
- ./sbs --jobs 2 --debug

# Stage test

test:
stage: test
script:
- ./sbs --jobs 2 --test catch-tests-entry

# Stage lint

cppcheck:
stage: lint
script:
- ./skyward-boardcore/scripts/linter.py --cppcheck src

format:
stage: lint
script:
- ./skyward-boardcore/scripts/linter.py --format src

copyright:
stage: lint
script:
- ./skyward-boardcore/scripts/linter.py --copyright src

find:
stage: lint
script:
- ./skyward-boardcore/scripts/linter.py --find src

# Stage documentation

documentation:
stage: documentation
only:
- master
- testing
tags:
- copyright
script:
- echo "Building r2a-hermes-obsw..."
- ./skyward-boardcore/sbs

test1:
stage: test
script:
- echo "Running Linter"
- skyward-boardcore/scripts/linter.sh
- echo "Generate documentation to https://documentation.skywarder.eu/${CI_PROJECT_NAME}/${CI_COMMIT_REF_NAME}"
- rm -rf doc/output
- doxygen doc/Doxyfile
- rm -rf /srv/code_documentation/${CI_PROJECT_NAME}/${CI_COMMIT_REF_NAME}
- mkdir -p /srv/code_documentation/${CI_PROJECT_NAME}/
- mv doc/output/html /srv/code_documentation/${CI_PROJECT_NAME}/${CI_COMMIT_REF_NAME}
51 changes: 51 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://gitlab.com/daverona/pre-commit/cpp
rev: 0.8.0
hooks:
- id: cppcheck
args: [
--quiet,
--language=c++,
--enable=all,
--inline-suppr,
--suppress=unmatchedSuppression,
--suppress=unusedFunction,
--suppress=missingInclude
]
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v13.0.0
hooks:
- id: clang-format
args: [
-style=file,
--dry-run,
--Werror
]
- repo: local
hooks:
- id: copyright
name: Copyright
entry: skyward-boardcore/scripts/linter.py
args: [
--copyright,
src
]
pass_filenames: false
language: python
- repo: local
hooks:
- id: find
name: Find
entry: skyward-boardcore/scripts/linter.py
args: [
--find,
src
]
pass_filenames: false
language: python
19 changes: 18 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,23 @@
"dense": "cpp",
"unordered_set": "cpp",
"hash_map": "cpp",
"valarray": "cpp"
"valarray": "cpp",
"core": "cpp",
"superlusupport": "cpp",
"*.evaluator": "cpp",
"*.traits": "cpp",
"adolcforward": "cpp",
"alignedvector3": "cpp",
"autodiff": "cpp",
"bvh": "cpp",
"eulerangles": "cpp",
"fft": "cpp",
"kroneckerproduct": "cpp",
"mprealsupport": "cpp",
"numericaldiff": "cpp",
"openglsupport": "cpp",
"specialfunctions": "cpp",
"splines": "cpp",
"matrixfunctions": "cpp"
}
}
2 changes: 1 addition & 1 deletion skyward-boardcore
66 changes: 38 additions & 28 deletions src/boards/DeathStack/AirBrakes/AirBrakesAlgorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@
* Total computation time: | 25.557320 ms | 181.001143 ms
*/

using namespace DeathStackBoard::AirBrakesConfigs;

namespace DeathStackBoard
{

Expand All @@ -64,7 +62,8 @@ class AirBrakesControlAlgorithm : public Algorithm
{

public:
AirBrakesControlAlgorithm(Sensor<T>& sensor, ServoInterface* actuator);
AirBrakesControlAlgorithm(Boardcore::Sensor<T>& sensor,
ServoInterface* actuator);

float getEstimatedCd() { return ab_data.estimated_cd; }

Expand Down Expand Up @@ -152,8 +151,8 @@ class AirBrakesControlAlgorithm : public Algorithm
/**
* @brief Compute the necessary airbrakes surface to match the
* given the drag force from the Pid. The possible surface values are
* discretized in (S_MIN, S_MAX) with a
* step of S_STEP. For every possible deltaS the
* discretized in (AirBrakesConfigs::S_MIN, AirBrakesConfigs::S_MAX) with a
* step of AirBrakesConfigs::S_STEP. For every possible deltaS the
* correspondig drag force is computed with @see getDrag method and the one
* that gives lowest error with respect to Pid output is returned.
*
Expand Down Expand Up @@ -220,7 +219,7 @@ class AirBrakesControlAlgorithm : public Algorithm

Trajectory chosenTrajectory;
ServoInterface* actuator;
Sensor<T>& sensor;
Boardcore::Sensor<T>& sensor;
PIController pid;

AirBrakesAlgorithmData algo_data;
Expand All @@ -237,8 +236,9 @@ class AirBrakesControlAlgorithm : public Algorithm

template <class T>
AirBrakesControlAlgorithm<T>::AirBrakesControlAlgorithm(
Sensor<T>& sensor, ServoInterface* actuator)
: actuator(actuator), sensor(sensor), pid(Kp, Ki),
Boardcore::Sensor<T>& sensor, ServoInterface* actuator)
: actuator(actuator), sensor(sensor),
pid(AirBrakesConfigs::Kp, AirBrakesConfigs::Ki),
logger(LoggerService::getInstance())
{
}
Expand All @@ -253,7 +253,7 @@ void AirBrakesControlAlgorithm<T>::begin()

running = true;

begin_ts = TimestampTimer::getInstance().getTimestamp();
begin_ts = Boardcore::TimestampTimer::getInstance().getTimestamp();

last_input_ts = (sensor.getLastSample()).timestamp;

Expand All @@ -275,14 +275,15 @@ void AirBrakesControlAlgorithm<T>::step()
alpha = computeAlpha(input, false);
}

uint64_t curr_ts = TimestampTimer::getInstance().getTimestamp();
uint64_t curr_ts = Boardcore::TimestampTimer::getInstance().getTimestamp();

#ifdef EUROC
if (curr_ts - begin_ts < AIRBRAKES_ACTIVATION_AFTER_SHADOW_MODE * 1000)
if (curr_ts - begin_ts <
AirBrakesConfigs::AIRBRAKES_ACTIVATION_AFTER_SHADOW_MODE * 1000)
{
// limit control to half of the airbrakes surface
// this should correspond to a maximum of 17.18° angle on the servo
actuator->set(AB_SERVO_HALF_AREA_POS, true);
actuator->set(AirBrakesConfigs::AB_SERVO_HALF_AREA_POS, true);
}
else
{
Expand Down Expand Up @@ -352,7 +353,7 @@ TrajectoryPoint AirBrakesControlAlgorithm<T>::chooseTrajectory(float z,
for (uint8_t trajectoryIndex = 0; trajectoryIndex < TOT_TRAJECTORIES;
trajectoryIndex++)
{
Trajectory trajectory(trajectoryIndex, S_MAX);
Trajectory trajectory(trajectoryIndex, AirBrakesConfigs::S_MAX);

for (uint32_t pointIndex = 0; pointIndex < trajectory.length();
pointIndex++)
Expand All @@ -373,7 +374,8 @@ TrajectoryPoint AirBrakesControlAlgorithm<T>::chooseTrajectory(float z,
logger.log(
AirBrakesChosenTrajectory{chosenTrajectory.getTrajectoryIndex()});

PrintLogger log = Logging::getLogger("deathstack.fsm.abk");
Boardcore::PrintLogger log =
Boardcore::Logging::getLogger("deathstack.fsm.abk");
LOG_INFO(log, "Chosen trajectory : {:d} \n",
chosenTrajectory.getTrajectoryIndex());

Expand All @@ -388,8 +390,9 @@ TrajectoryPoint AirBrakesControlAlgorithm<T>::getSetpoint(float z, float vz)
TrajectoryPoint currentPoint(z, vz);
float minDistance = INFINITY;

uint32_t start = std::max(indexMinVal + START_INDEX_OFFSET, 0);
uint32_t end = chosenTrajectory.length();
uint32_t start =
std::max(indexMinVal + AirBrakesConfigs::START_INDEX_OFFSET, 0);
uint32_t end = chosenTrajectory.length();

for (uint32_t pointIndex = start; pointIndex < end; pointIndex++)
{
Expand Down Expand Up @@ -419,14 +422,14 @@ float AirBrakesControlAlgorithm<T>::pidStep(float z, float vz, float vMod,
// cd minimum if abk surface is 0
float cd_min = getDrag(vMod, z, 0);
// cd maximum if abk surface is maximum
float cd_max = getDrag(vMod, z, S_MAX);
float cd_max = getDrag(vMod, z, AirBrakesConfigs::S_MAX);

float u_min = 0.5 * rho * cd_min * S0 * vz * vMod;
float u_max = 0.5 * rho * cd_max * S0 * vz * vMod;
float u_min = 0.5 * rho * cd_min * AirBrakesConfigs::S0 * vz * vMod;
float u_max = 0.5 * rho * cd_max * AirBrakesConfigs::S0 * vz * vMod;

// get reference CD and control action, according to the chosen trajectory
float cd_ref = getDrag(vMod, z, chosenTrajectory.getRefSurface());
float u_ref = 0.5 * rho * cd_ref * S0 * vz * vMod;
float u_ref = 0.5 * rho * cd_ref * AirBrakesConfigs::S0 * vz * vMod;

float error = vz - setpoint.getVz();
ab_data.pid_error = error; // for logging
Expand All @@ -447,10 +450,12 @@ float AirBrakesControlAlgorithm<T>::getSurface(float z, float vz, float vMod,
float selected_s = 0;
float best_du = INFINITY;

for (float s = S_MIN; s < S_MAX + S_STEP; s += S_STEP)
for (float s = AirBrakesConfigs::S_MIN;
s < AirBrakesConfigs::S_MAX + AirBrakesConfigs::S_STEP;
s += AirBrakesConfigs::S_STEP)
{
float cd = getDrag(vMod, z, s);
float du = abs(u - (0.5 * rho * S0 * cd * vz * vMod));
float du = abs(u - (0.5 * rho * AirBrakesConfigs::S0 * cd * vz * vMod));

if (du < best_du)
{
Expand All @@ -468,31 +473,35 @@ float AirBrakesControlAlgorithm<T>::getSurface(float z, float vz, float vMod,
template <class T>
float AirBrakesControlAlgorithm<T>::getAlpha(float s)
{
float alpha_rad = (-B_DELTAS + sqrt(powf(B_DELTAS, 2) + 4 * A_DELTAS * s)) /
(2 * A_DELTAS);
float alpha_rad = (-AirBrakesConfigs::B_DELTAS +
sqrt(powf(AirBrakesConfigs::B_DELTAS, 2) +
4 * AirBrakesConfigs::A_DELTAS * s)) /
(2 * AirBrakesConfigs::A_DELTAS);

float alpha_deg = alpha_rad * 180.0f / PI;
float alpha_deg = alpha_rad * 180.0f / Boardcore::PI;

return alpha_deg;
}

template <class T>
float AirBrakesControlAlgorithm<T>::getRho(float h)
{
return RHO * expf(-h / Hn);
return AirBrakesConfigs::RHO * expf(-h / AirBrakesConfigs::Hn);
}

template <class T>
float AirBrakesControlAlgorithm<T>::getMach(float vMod, float z)
{
float c = Co + ALPHA * z;
float c = AirBrakesConfigs::Co + AirBrakesConfigs::ALPHA * z;
return vMod / c;
}

template <class T>
float AirBrakesControlAlgorithm<T>::getExtension(float s)
{
return (-B + sqrtf(powf(B, 2) + 4 * A * s)) / (2 * A);
return (-AirBrakesConfigs::B +
sqrtf(powf(AirBrakesConfigs::B, 2) + 4 * AirBrakesConfigs::A * s)) /
(2 * AirBrakesConfigs::A);
}

template <class T>
Expand All @@ -510,6 +519,7 @@ float AirBrakesControlAlgorithm<T>::getDrag(float v, float h, float s)
powf(mach, 5),
powf(mach, 6)};

using AirBrakesConfigs::coeffs;
return coeffs.n000 + coeffs.n100 * pow_mach[1] + coeffs.n200 * pow_mach[2] +
coeffs.n300 * pow_mach[3] + coeffs.n400 * pow_mach[4] +
coeffs.n500 * pow_mach[5] + coeffs.n600 * pow_mach[6] +
Expand Down
Loading

0 comments on commit 22c46e7

Please sign in to comment.