Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add dronecan pmw module #24

Merged
merged 45 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
b0e9c64
add circuit status
AsiiaPine Mar 13, 2024
121f61d
clean up
AsiiaPine Mar 13, 2024
0f3376d
rm legacy
AsiiaPine Mar 13, 2024
e87250a
upd libparams
AsiiaPine Mar 13, 2024
3665467
upd libparams branch
AsiiaPine Mar 15, 2024
87c8e22
Merge pull request #1 from AsiiaPine/pr-add-curcuit-status
AsiiaPine Mar 15, 2024
ce86edb
chanhged trigger action on pull_request
AsiiaPine Mar 15, 2024
01f3842
restore prev tools version
AsiiaPine Mar 15, 2024
5cab4f4
fix last-row issue
AsiiaPine Mar 15, 2024
d68dbdb
add circuit status driver
AsiiaPine Mar 15, 2024
5348a4c
fix cyphal
AsiiaPine Mar 18, 2024
9be5149
upd circuit_periphery and dlt dronecan tokens
AsiiaPine Mar 18, 2024
67e7934
upd Cyphal submodule
AsiiaPine Mar 18, 2024
84277c3
add pwm Module
AsiiaPine Apr 15, 2024
2d35951
upd module structure for multiple pwms
AsiiaPine Apr 17, 2024
4a6336b
add ch<0 case processing
AsiiaPine Apr 17, 2024
452de53
replace msg publishing to esc status
AsiiaPine Apr 18, 2024
e5e8ca2
upd publishing msgs
AsiiaPine Apr 18, 2024
2cd1c67
add dbg parameter to change pwm Status pub frequency
AsiiaPine Apr 18, 2024
37d50fd
ci: update actions/checkout from v3 to v4, add missed build cyphal bi…
PonomarevDA Mar 7, 2024
029f1fc
update readme
PonomarevDA Mar 7, 2024
6548491
ci: add dronecan submodule instead of using private repo
PonomarevDA Mar 7, 2024
a9dfc30
add circuit status (#19)
AsiiaPine Mar 20, 2024
06bba50
add v3 version (stm32g0) (#21)
PonomarevDA Mar 20, 2024
456ba7f
clean up cyphal application
PonomarevDA Mar 20, 2024
c16de88
update license
PonomarevDA Mar 20, 2024
0c772e7
add cpplint for cyphal
PonomarevDA Apr 2, 2024
e2ecc5f
add cpplint for dronecan
PonomarevDA Apr 2, 2024
c3d5f55
add cpplint for periphery
PonomarevDA Apr 2, 2024
fef4498
fix a few sonarcloud issues
PonomarevDA Apr 2, 2024
21788a3
fix sitl pwm, removed duplications after big rebase
AsiiaPine Apr 18, 2024
c3e7e7f
add endline to git files
AsiiaPine Apr 18, 2024
ac40056
Merge branch 'main' into pr-new-pmw-module
AsiiaPine Apr 18, 2024
879af92
add health status update, applied cpplint suggestions
AsiiaPine Apr 19, 2024
ad48b8f
applied cpplint suggestions
AsiiaPine Apr 19, 2024
709cb1e
rep verbose+dbg params with pwm.*_feedback
AsiiaPine Apr 22, 2024
c138352
resolve cpplint suggestions
AsiiaPine Apr 24, 2024
488ba05
fixed bugs with cmd subscriptions
AsiiaPine Apr 24, 2024
858fef8
fixed min/max pwm vals
AsiiaPine Apr 24, 2024
a553597
fix bug
AsiiaPine Apr 25, 2024
c9fccbf
upd dronecan (#26)
AsiiaPine Apr 25, 2024
a06b11e
add actuator status publication
AsiiaPine Apr 27, 2024
67f11fe
resolve params fix suggestions
AsiiaPine Apr 27, 2024
f6483b3
add to actuator.Status publish_delay
AsiiaPine Apr 27, 2024
82cfa45
fix params typo
AsiiaPine Apr 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/dronecan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ jobs:
run: make sitl_dronecan

- name: Run SITL for 5 seconds
run: timeout 5s make run || res=$?; if [[ $res -ne 124 && $res -ne 0 ]]; then exit $res; fi
run: timeout 5s make run || res=$?; if [[ $res -ne 124 && $res -ne 0 ]]; then exit $res; fi
2 changes: 1 addition & 1 deletion .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ jobs:
- name: Run sonar-scanner
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: sonar-scanner
run: sonar-scanner
2 changes: 2 additions & 0 deletions Src/dronecan_application/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ set(applicationSourceCode
${DRONECAN_SOURCES}
${ROOT_DIR}/Src/dronecan_application/application.cpp
${ROOT_DIR}/Src/dronecan_application/modules/CircuitStatusModule.cpp
${ROOT_DIR}/Src/dronecan_application/modules/PWMModule.cpp
${ROOT_DIR}/Src/dronecan_application/logger.cpp
${ROOT_DIR}/Src/dronecan_application/algorithms.cpp

)
set(applicationHeaders
Expand Down
23 changes: 23 additions & 0 deletions Src/dronecan_application/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@ The node has the following registers:
| -- | ----------------------- | ----------- |
| 1 | uavcan.node.id | Defines a node-ID. Allowed values [0,127]. |
| 2 | system.name | Defines custom node name. If empty, the node will use the default name. |
| 3 | pwm.cmd_ttl_ms | TTL of specified by pwm.cmd_type commands [ms]. |
| 4 | pwm.frequency | PWM frequency [Hz]. |
| 5 | pwm.cmd_type | 0 means RawCommand, 1 means ArrayCommand, 2 is reserved for hardpoint.Command. |
| 6 | pwm.1_ch | Index of setpoint channel. [-1; 255]. -1 means disabled, |
| 7 | pwm.1_min | PWM duration when setpoint is min (RawCommand is 0 or Command is -1.0) |
| 8 | pwm.1_max | PWM duration when setpoint is max (RawCommand is 8191 or Command is 1.0) |
| 9 | pwm.1_def | PWM duration when setpoint is negative or there is no setpoint at all. |
| 10 | pwm.1_feedback | Indicates the operational mode of the node. 0 means disabled. When set to 1, the command of corresponding Status type for cmd_type will be transmitted (esc.RawCommand - esc.Status, actuator.ArrayCommand - actuator.Status) with frequency 1 Hz. When set to 2 - 10 Hz. |
| 11 | pwm.2_ch | Index of setpoint channel. [-1; 255]. -1 means disabled, |
| 12 | pwm.2_min | PWM duration when setpoint is min (RawCommand is 0 or Command is -1.0) |
| 13 | pwm.2_max | PWM duration when setpoint is max (RawCommand is 8191 or Command is 1.0) |
| 14 | pwm.2_def | PWM duration when setpoint is negative or there is no setpoint at all. |
| 15 | pwm.2_feedback | Indicates the operational mode of the node. 0 means disabled. When set to 1, the command of corresponding Status type for cmd_type will be transmitted (esc.RawCommand - esc.Status, actuator.ArrayCommand - actuator.Status) with frequency 1 Hz. When set to 2 - 10 Hz. |
| 16 | pwm.3_ch | Index of setpoint channel. [-1; 255]. -1 means disabled, |
| 17 | pwm.3_min | PWM duration when setpoint is min (RawCommand is 0 or Command is -1.0) |
| 18 | pwm.3_max | PWM duration when setpoint is max (RawCommand is 8191 or Command is 1.0) |
| 19 | pwm.3_def | PWM duration when setpoint is negative or there is no setpoint at all. |
| 20 | pwm.3_feedback | Indicates the operational mode of the node. 0 means disabled. When set to 1, the command of corresponding Status type for cmd_type will be transmitted (esc.RawCommand - esc.Status, actuator.ArrayCommand - actuator.Status) with frequency 1 Hz. When set to 2 - 10 Hz. |
| 21 | pwm.4_ch | Index of setpoint channel. [-1; 255]. -1 means disabled, |
| 22 | pwm.4_min | PWM duration when setpoint is min (RawCommand is 0 or Command is -1.0) |
| 23 | pwm.4_max | PWM duration when setpoint is max (RawCommand is 8191 or Command is 1.0) |
| 24 | pwm.4_def | PWM duration when setpoint is negative or there is no setpoint at all. |
| 25 | pwm.4_feedback | Indicates the operational mode of the node. 0 means disabled. When set to 1, the command of corresponding Status type for cmd_type will be transmitted (esc.RawCommand - esc.Status, actuator.ArrayCommand - actuator.Status) with frequency 1 Hz. When set to 2 - 10 Hz. |

> This docs was automatically generated. Do not edit it manually.

74 changes: 74 additions & 0 deletions Src/dronecan_application/algorithms.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (C) 2022-2023 Dmitry Ponomarev <[email protected]>
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#include "algorithms.hpp"


static const RawCommand RAW_COMMAND_MIN = 0;
static const RawCommand RAW_COMMAND_MAX = 8191;


static const ActuatorCommandValue ACT_COMMAND_MIN = -1.0f;
static const ActuatorCommandValue ACT_COMMAND_MAX = 1.0f;

PwmDurationUs mapRawCommandToPwm(RawCommand command,
PwmDurationUs min_pwm,
PwmDurationUs max_pwm,
PwmDurationUs def_pwm) {
PwmDurationUs pwm;
if (command < RAW_COMMAND_MIN || command > RAW_COMMAND_MAX) {
pwm = def_pwm;
} else {
pwm = (PwmDurationUs)mapFloat(command, RAW_COMMAND_MIN, RAW_COMMAND_MAX, min_pwm, max_pwm);
}
return pwm;
}


PwmDurationUs mapActuatorCommandToPwm(ActuatorCommandValue command,
PwmDurationUs min_pwm,
PwmDurationUs max_pwm,
PwmDurationUs def_pwm) {
PwmDurationUs pwm;
if (command < ACT_COMMAND_MIN || command > ACT_COMMAND_MAX) {
pwm = def_pwm;
} else {
pwm = (PwmDurationUs)mapFloat(command, ACT_COMMAND_MIN, ACT_COMMAND_MAX, min_pwm, max_pwm);
}
return pwm;
}

float mapPwmToPct(uint16_t pwm_val, int16_t pwm_min, int16_t pwm_max) {
auto max = pwm_max;
auto min = pwm_min;
if (pwm_min > pwm_max) {
max = pwm_min;
min = pwm_max;
}
auto scaled_val = (pwm_val - min) * 100.0f / (max - min);
auto val = std::clamp(scaled_val, 0.f, 100.f);
return val;
}

float mapFloat(float value, float in_min, float in_max, float out_min, float out_max) {
float output;
if (value <= in_min && in_min <= in_max) {
output = out_min;
} else if (value >= in_max && in_min <= in_max) {
output = out_max;
} else if (out_min == out_max) {
output = out_min;
} else {
output = out_min + (value - in_min) / (in_max - in_min) * (out_max - out_min);
if (out_min <= out_max) {
output = std::clamp(output, out_min, out_max);
} else {
output = std::clamp(output, out_max, out_min);
}
}
return output;
}
59 changes: 59 additions & 0 deletions Src/dronecan_application/algorithms.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (C) 2022-2023 Dmitry Ponomarev <[email protected]>
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#ifndef DEVICES_SERVOS_COMMON_H_
#define DEVICES_SERVOS_COMMON_H_

#include <stdbool.h>
#include <stdint.h>

#include <algorithm>

#ifdef __cplusplus
extern "C" {
#endif

typedef uint16_t PwmDurationUs;
typedef int16_t RawCommand;
typedef float ActuatorCommandValue;

/**
* @brief Map raw command value (in interval from 0 to 8191)
* to PWM duration in us (in interval from min to max)
* @return pwm_duration if input is correct,
* def_pwm if raw_command value is less than min or higher than max
*/

PwmDurationUs mapRawCommandToPwm(RawCommand rc_value, PwmDurationUs min_pwm,
PwmDurationUs max_pwm, PwmDurationUs def_pwm);

/**
* @brief Map array command value (in interval from -1.0 to 1.0)
* to PWM duration in us (in interval from min to max)
* @return pwm_duration if input is correct,
* def_pwm if raw_command value is less than min or higher than max
*/

PwmDurationUs mapActuatorCommandToPwm(ActuatorCommandValue ac_value,
PwmDurationUs min_pwm, PwmDurationUs max_pwm,
PwmDurationUs def_pwm);

/**
* @brief Map PWM duration in us (in interval from min to max) to pct
* @return pwm_duration in pct
*/

float mapPwmToPct(uint16_t pwm_val, int16_t pwm_min, int16_t pwm_max);

float mapFloat(float value, float in_min, float in_max, float out_min,
float out_max);

#ifdef __cplusplus
}
#endif

#endif // DEVICES_SERVOS_COMMON_H_
5 changes: 5 additions & 0 deletions Src/dronecan_application/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "params.hpp"
#include "periphery/led/led.hpp"
#include "periphery/iwdg/iwdg.hpp"
#include "modules/PWMModule.hpp"
#include "modules/CircuitStatusModule.hpp"


Expand All @@ -29,14 +30,18 @@ void application_entry_point() {
uavcanInitApplication(node_id);

CircuitStatusModule& status_module = CircuitStatusModule::get_instance();
PWMModule& pwm_module = PWMModule::get_instance();
LedColor color = LedColor::BLUE_COLOR;

if (!status_module.instance_initialized) {
color = LedColor::RED_COLOR;
}

while(true) {
LedPeriphery::toggle(color);
status_module.spin_once();
pwm_module.spin_once();
uavcanSetNodeHealth((NodeStatusHealth_t) pwm_module.module_status);
uavcanSpinOnce();

WatchdogPeriphery::refresh();
Expand Down
Loading
Loading