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

actuators[ ] array of structs with pprz units and driver units #3205

Merged
merged 3 commits into from
May 25, 2024

Conversation

dewagter
Copy link
Member

In simulation / NPS, we would like to simulate all actuators. The actuators[ ] array can not be used because it has different units: e.g. PWM 1100 - 1900.

With the new system of sending actuators to different actuator drivers, the conversion to actuator_driver units is best done when sending to the actuator_driver.

  • this means the separate copy of actuators_pprz is not needed.
  • this allows to simulate actuators directly and remove dependencies on control allocation.

@gautierhattenberger
Copy link
Member

The issue with this (actuators in pprz_t) is that the actuators message is now also in pprz_t. So if you need to read the actuators position to adjust the trim (which should be in "driver" unit), you will have a good chance to make errors doing the conversion or just forgetting to convert it to the correct scale.
An actuator structure could hold the two values, that could be used with proper format when needed...

@dewagter
Copy link
Member Author

Agreed

@dewagter dewagter force-pushed the store_actuators_in_std_pprz_units branch from 3536282 to f461e8c Compare December 17, 2023 09:02
@dewagter dewagter changed the title actuators[ ] array in pprz units actuators[ ] array of structs with pprz units and driver units Dec 17, 2023
@dewagter
Copy link
Member Author

dewagter commented Dec 17, 2023

Changed to actuator struct. If you have naming recommendations let me know.

This should allow us to simulate actuators directly now in nps_autopilot_rotorcraft.c ->
nps_autopilot.commands[i] = (double)actuators[i].pprz_val / MAX_PPRZ;

I didn't change it yet because the actuator indexes often do not match and requires some harmonization (see #3203)

@dewagter dewagter modified the milestone: v7.0 Dec 18, 2023
@dewagter dewagter force-pushed the store_actuators_in_std_pprz_units branch from f461e8c to e495727 Compare December 18, 2023 21:50
@dewagter dewagter force-pushed the store_actuators_in_std_pprz_units branch from e495727 to 6fc2c2c Compare January 10, 2024 08:58
EwoudSmeur
EwoudSmeur previously approved these changes Jan 11, 2024
Copy link
Member

@EwoudSmeur EwoudSmeur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great development!

sw/tools/generators/gen_airframe.ml Outdated Show resolved Hide resolved
@dewagter dewagter force-pushed the store_actuators_in_std_pprz_units branch from 6fc2c2c to d259610 Compare May 23, 2024 20:47
@dewagter
Copy link
Member Author

Sample generatle airframe.h

#define Set_AIL_LEFT_Servo(actuator_value_pprz) { \
  actuators[SERVO_AIL_LEFT_IDX].pprz_val = ClipAbs( actuator_value_pprz, MAX_PPRZ); \
  command_value = actuator_value_pprz * (actuator_value_pprz>0 ? SERVO_AIL_LEFT_TRAVEL_UP_NUM : SERVO_AIL_LEFT_TRAVEL_DOWN_NUM); \
  command_value /= actuator_value_pprz>0 ? SERVO_AIL_LEFT_TRAVEL_UP_DEN : SERVO_AIL_LEFT_TRAVEL_DOWN_DEN; \
  servo_value = SERVO_AIL_LEFT_NEUTRAL + command_value; \
  actuators[SERVO_AIL_LEFT_IDX].driver_val = Clip(servo_value, SERVO_AIL_LEFT_MIN, SERVO_AIL_LEFT_MAX); \
  ActuatorUavcan2CmdSet(SERVO_AIL_LEFT_DRIVER_NO, actuators[SERVO_AIL_LEFT_IDX].driver_val); \
}

@dewagter
Copy link
Member Author

The issue with this (actuators in pprz_t) is that the actuators message is now also in pprz_t. So if you need to read the actuators position to adjust the trim (which should be in "driver" unit), you will have a good chance to make errors doing the conversion or just forgetting to convert it to the correct scale. An actuator structure could hold the two values, that could be used with proper format when needed...

This is now sent in driver_val.

@dewagter dewagter merged commit e6bcd60 into master May 25, 2024
1 check passed
@dewagter dewagter deleted the store_actuators_in_std_pprz_units branch May 25, 2024 07:38
@Fabien-B
Copy link
Contributor

Hi @dewagter, following this PR, I have this error when building the CobraV2 aircraft from ENAC/conf_enac.xml.
Can you look into it please ?

In file included from modules/switching/switch_servo.h:27,
from modules/switching/switch_servo.c:22:
modules/switching/switch_servo.c: In function 'switch_servo_periodic':
/home/fabien/paparazzi/var/aircrafts/CobraV2/ap/generated/airframe.h:162:3: error: 'command_value' undeclared (first use in this function)
162 | command_value = actuator_value_pprz * (actuator_value_pprz>0 ? SERVO_SWITCH_TRAVEL_UP_NUM : SERVO_SWITCH_TRAVEL_DOWN_NUM); \
| ^~~~~~~~~~~~~

@dewagter
Copy link
Member Author

Should be solved in #3280 ...
if someone accepts it, you can merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants