Skip to content

Commit

Permalink
Robot firmware release 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
ersaraujo committed Nov 22, 2024
0 parents commit ce19eda
Show file tree
Hide file tree
Showing 80 changed files with 10,875 additions and 0 deletions.
83 changes: 83 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# using clang-format 10

Language: Cpp
Standard: c++14
# BasedOnStyle: LLVM

UseTab: Never
IndentWidth: 2
ColumnLimit: 100

# class preferences
AccessModifierOffset: -1

# aligns
AlignEscapedNewlines: Right
AlignAfterOpenBracket: Align
AlignOperands: true
AlignTrailingComments: true
AlignConsecutiveMacros: true

# allows
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: true

# AllowShortEnumsOnASingleLine: false # clang-format 12 option.

AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: None
AllowShortLoopsOnASingleLine: false

# always
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true

# bin packs
BinPackArguments: false
BinPackParameters: false

# breaks
BreakStringLiterals: false
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: false
BreakConstructorInitializers: AfterColon
BreakConstructorInitializersBeforeComma: true

ConstructorInitializerAllOnOneLineOrOnePerLine: true

MaxEmptyLinesToKeep: 1

PointerAlignment: Left

SortIncludes: false
SortUsingDeclarations: false

# spaces
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInConditionalStatement: false
SpacesInParentheses: false
SpacesInSquareBrackets: false

CompactNamespaces: false
NamespaceIndentation: All

IndentCaseLabels: true

IndentPPDirectives: BeforeHash
21 changes: 21 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## Description

Please include a summary of the change and if applicable the issue is fixed. Please also include the context of the PR.

## Type of change

Please delete options that are not relevant.

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that expects additional changes)
- [ ] This change requires a documentation update

## How Has This Been Tested?

Please describe the tests that you ran to verify your changes.
Also, check the steps you've tested below:
**Test Septs**:
* Custom tested:
* Locally tested (tested in robot's firmware):
* Online tested (tested in SSL full network):
47 changes: 47 additions & 0 deletions .github/workflows/build_firmware.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# This is a basic workflow to help you get started with Actions

name: PlatformIO CI

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [ master, validation ]
pull_request:
branches: [ master ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:

build:
# The type of runner that the job will run on
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]

# Steps represent a sequence of tasks that will be executed as part of the job
steps:

# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
with:
token: ${{ secrets.RC_PAT_TOKEN_ACTIONS_ONLY }}
submodules: recursive

# Install Python
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.9'

# Installing pip and platformIO
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install platformio
- name: Run PlatformIO
run: |
platformio run
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_Store
.pio/*
.vscode/*
.pyc
**/*.csv
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "lib/nRF24Communication"]
path = lib/nRF24Communication
url = [email protected]:robocin/communication-embedded.git
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# ssl-embedded

![PlatformIO CI](https://github.com/robocin/ssl-embedded/workflows/PlatformIO%20CI/badge.svg?branch=master)

<img src="./assets/graph.png" height="180">

- Firmware
- Robot codes with folder for which version.
- Board: [NUCLEO-F767ZI](https://os.mbed.com/platforms/ST-Nucleo-F767ZI/)
- API: [MbedOS](https://os.mbed.com/docs/v5.10/apis/index.html)
- Software IDE: [Visual Studio Code](https://code.visualstudio.com/)
- Programming Extension: [PlatformIO](https://platformio.org/platformio-ide), installed with VS Code package manager.
- Updating Firmware: [instructions here](https://os.mbed.com/teams/ST/wiki/Nucleo-Firmware)

- Tests
- Folder with all tests and auxiliar softwares.

## Dependencies
### - nRF24Communication lib
It's submodule of [communication-embedded](https://github.com/robocin/communication-embedded/).
- So, to clone this repository please use:

git clone --recurse-submodules -j8 <link>
- Whener you want to update the nRF24Communication lib to the latest version on [communication-embedded](https://github.com/robocin/communication-embedded/) (master), use:

git submodule update --init --recursive

### - ST STM32 Platform
The [ST STM32](https://docs.platformio.org/en/latest/platforms/ststm32.html) is a device platform responsible for interface mbed to ARM boards, so it's necessary to install at the PlatformIO extension.

Binary file added assets/graph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions lib/CurrentSensor/CurrentSensor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "CurrentSensor.h"

CurrentSensor::CurrentSensor(){};

void CurrentSensor::setMuxWiremap(Wiremap& wiremap) {
this->A2.write(wiremap.a2);
this->A1.write(wiremap.a1);
this->A0.write(wiremap.a0);
}

double CurrentSensor::calculateCurrentFromVoltage(Voltage voltage) {
double vref = voltage.first * 3.3;
double vout = voltage.second * 3.3;

return (vout - vref) / SENSITIVITY;
}

Voltage CurrentSensor::readVoltageFromMuxOutput() {
return std::make_pair(vReference.read(), vOut.read());
}

Motors CurrentSensor::getMotorsCurrent() {
Voltage voltage;
Motors motorCurrent;

// Motor 1
this->setMuxWiremap(this->motorOneWiremap);
voltage = this->readVoltageFromMuxOutput();
motorCurrent.m1 = this->calculateCurrentFromVoltage(voltage);

// Motor 2
this->setMuxWiremap(this->motorTwoWiremap);
voltage = this->readVoltageFromMuxOutput();
motorCurrent.m2 = this->calculateCurrentFromVoltage(voltage);

// Motor 3
this->setMuxWiremap(this->motorThreeWiremap);
voltage = this->readVoltageFromMuxOutput();
motorCurrent.m3 = this->calculateCurrentFromVoltage(voltage);

// Motor 4
this->setMuxWiremap(this->motorFourWiremap);
voltage = this->readVoltageFromMuxOutput();
motorCurrent.m4 = this->calculateCurrentFromVoltage(voltage);

return motorCurrent;
}

double CurrentSensor::getDribblerCurrent() {
// Setup wiremap to dribbler output
this->setMuxWiremap(this->dribblerWiremap);

// Read output
Voltage voltage = this->readVoltageFromMuxOutput();

// Do not use utils getCurrent, refactor this later on
return this->calculateCurrentFromVoltage(voltage);
}
42 changes: 42 additions & 0 deletions lib/CurrentSensor/CurrentSensor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef CURRENT_SENSOR_H
#define CURRENT_SENSOR_H

#include <utils.h>

#define SENSITIVITY 0.025

using Voltage = std::pair<double, double>;

class CurrentSensor {
public:
class Wiremap {
public:
int a0;
int a1;
int a2;

Wiremap(int a0, int a1, int a2) : a0(a0), a1(a1), a2(a2){};
};

CurrentSensor();
double getDribblerCurrent();
Motors getMotorsCurrent();

private:
DigitalOut A2 = CURRENT_SENSOR_A2;
DigitalOut A1 = CURRENT_SENSOR_A1;
DigitalOut A0 = CURRENT_SENSOR_A0;
AnalogIn vReference = PIN_CURR_REF;
AnalogIn vOut = PIN_CURR_OUT;
Wiremap motorOneWiremap{0, 0, 1};
Wiremap motorTwoWiremap{0, 1, 1};
Wiremap motorThreeWiremap{1, 1, 1};
Wiremap motorFourWiremap{1, 0, 0};
Wiremap dribblerWiremap{0, 1, 0};

void setMuxWiremap(Wiremap& wiremap);
double calculateCurrentFromVoltage(Voltage voltage);
Voltage readVoltageFromMuxOutput();
};

#endif // CURRENT_SENSOR_H
Loading

0 comments on commit ce19eda

Please sign in to comment.