Skip to content

Commit

Permalink
Merge 51cacb3 into d0f97e1
Browse files Browse the repository at this point in the history
  • Loading branch information
tmldeponti committed Apr 11, 2024
2 parents d0f97e1 + 51cacb3 commit 56dd74d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 32 deletions.
8 changes: 1 addition & 7 deletions conf/modules/oneloop_andi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,7 @@
<init fun="oneloop_andi_init()"/>
<makefile target="ap|nps" firmware="rotorcraft">
<file name="oneloop_andi.c" dir="$(SRC_FIRMWARE)/oneloop"/>
<configure name="ANDI_OUTPUTS" default="4"/>
<configure name="ANDI_NUM_ACT" default="4"/>
<configure name="ANDI_NUM_VIRTUAL_ACT" default="2"/>
<configure name="ANDI_NUM_ACT_TOT" default="6"/>
<configure name="ANDI_OUTPUTS" default="6"/>
<define name="ANDI_OUTPUTS" value="$(ANDI_OUTPUTS)"/>
<define name="ANDI_NUM_ACT" value="$(ANDI_NUM_ACT)"/>
<define name="ANDI_NUM_VIRTUAL_ACT" value="$(ANDI_NUM_VIRTUAL_ACT)"/>
<define name="ANDI_NUM_ACT_TOT" value="$(ANDI_NUM_ACT_TOT)"/>
</makefile>
</module>
22 changes: 0 additions & 22 deletions sw/airborne/firmwares/rotorcraft/oneloop/oneloop_andi.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,28 +95,6 @@
#include <stdio.h>

// Number of real actuators (e.g. motors, servos)
#ifndef ANDI_NUM_ACT
#error "You must specify the number of real actuators"
#define ANDI_NUM_ACT 4
#endif

// Number of virtual actuators (e.g. Phi, Theta). For now 2 and only 2 are supported but in the future this can be further developed.
#if ANDI_NUM_VIRTUAL_ACT < 2
#error "You must specify the number of virtual actuators to be at least 2"
#define ANDI_NUM_VIRTUAL_ACT 2
#endif

// If the total number of actuators is not defined or wrongly defined correct it
#if ANDI_NUM_ACT_TOT != (ANDI_NUM_ACT + ANDI_NUM_VIRTUAL_ACT)
#error "The number of actuators is not equal to the sum of real and virtual actuators"
#define ANDI_NUM_ACT_TOT (ANDI_NUM_ACT + ANDI_NUM_VIRTUAL_ACT)
#endif

#ifndef ANDI_OUTPUTS
#error "You must specify the number of controlled axis (outputs)"
#define ANDI_OUTPUTS 6
#endif

#ifndef ONELOOP_ANDI_NUM_THRUSTERS
float num_thrusters_oneloop = 4.0; // Number of motors used for thrust
#else
Expand Down
21 changes: 21 additions & 0 deletions sw/airborne/firmwares/rotorcraft/oneloop/oneloop_andi.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,28 @@
#include "firmwares/rotorcraft/stabilization.h"
#include "firmwares/rotorcraft/stabilization/stabilization_attitude_common_int.h"
#include "firmwares/rotorcraft/stabilization/stabilization_attitude_ref_quat_int.h"
#include "generated/airframe.h"

#ifndef ANDI_NUM_ACT
#define ANDI_NUM_ACT COMMANDS_NB_REAL
#endif

#ifndef ANDI_NUM_VIRTUAL_ACT
#define ANDI_NUM_VIRTUAL_ACT COMMANDS_NB_VIRTUAL
#endif

// Number of virtual actuators (e.g. Phi, Theta). For now 2 and only 2 are supported but in the future this can be further developed.
#if ANDI_NUM_VIRTUAL_ACT < 2
#error "You must specify the number of virtual actuators to be at least 2"
#define ANDI_NUM_VIRTUAL_ACT 2
#endif

#define ANDI_NUM_ACT_TOT (ANDI_NUM_ACT + ANDI_NUM_VIRTUAL_ACT)

#ifndef ANDI_OUTPUTS
#error "You must specify the number of controlled axis (outputs)"
#define ANDI_OUTPUTS 6
#endif
#define ANDI_G_SCALING 1000.0f

extern float act_state_filt_vect_1l[ANDI_NUM_ACT];
Expand Down
18 changes: 15 additions & 3 deletions sw/tools/generators/gen_airframe.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ open Printf
open Xml2h

type channel = { min : float; max : float; neutral : float }
type control = { failsafe_value : int; foo : int }
type control = { failsafe_value : int; foo : int; actuator_type : string}

let fos = float_of_string
let sof = fun x -> if mod_float x 1. = 0. then Printf.sprintf "%.0f" x else string_of_float x
Expand Down Expand Up @@ -337,9 +337,17 @@ let parse_ap_only_commands = fun out ap_only ->

let parse_command = fun out command no ->
let command_name = "COMMAND_"^ExtXml.attrib command "name" in
define_out out command_name (string_of_int no);
let failsafe_value = int_of_string (ExtXml.attrib command "failsafe_value") in
{ failsafe_value = failsafe_value; foo = 0}
let actuator_type = ExtXml.attrib_or_default command "actuator_type" "REAL" in
define_out out command_name (string_of_int no);
{ failsafe_value = failsafe_value; foo = 0 ; actuator_type = actuator_type }

let count_commands_by_type commands_params =
List.fold_left (fun acc cmd ->
let subtype = cmd.actuator_type in
let count = try List.assoc subtype acc with Not_found -> 0 in
(subtype, count + 1) :: (List.remove_assoc subtype acc)
) [("REAL", 0); ("VIRTUAL", 0); ("PASSIVE", 0); ("OTHER", 0)] commands_params

let parse_heli_curves = fun out heli_curves ->
let a = fun s -> ExtXml.attrib heli_curves s in
Expand Down Expand Up @@ -387,6 +395,10 @@ let rec parse_section = fun out ac_id s ->
| "commands" ->
let commands = Array.of_list (Xml.children s) in
let commands_params = Array.mapi (fun i c -> parse_command out c i) commands in
let commands_counts = count_commands_by_type (Array.to_list commands_params) in
List.iter (fun (subtype, count) ->
define_out out (sprintf "COMMANDS_NB_%s" subtype) (string_of_int count)
) commands_counts;
define_out out "COMMANDS_NB" (string_of_int (Array.length commands));
define_out out "COMMANDS_FAILSAFE" (sprint_float_array (List.map (fun x -> string_of_int x.failsafe_value) (Array.to_list commands_params)));
fprintf out "\n\n"
Expand Down

0 comments on commit 56dd74d

Please sign in to comment.