Skip to content

Commit

Permalink
[modules] Rotating wing better ADC sensor integration (#3251)
Browse files Browse the repository at this point in the history
* Make adc sensor mappable from the airframe. Better interface for adc in the rotwing state.

* Added parameters to v3b airframe

* Addressed the comments

* Removed external variable
  • Loading branch information
tmldeponti committed Apr 9, 2024
1 parent 25ec862 commit afa9378
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
5 changes: 4 additions & 1 deletion conf/airframes/tudelft/rot_wing_v3b.xml
Expand Up @@ -40,7 +40,10 @@
<configure name="USE_TFMINI_AGL" value="TRUE"/>
</module>

<module name="wing_rotation_adc_sensor"/>
<module name="wing_rotation_adc_sensor">
<define name="ADC_WING_ROT_SCALE" value="0.00247111"/>
<define name="ADC_WING_ROT_OFFSET" value="-25.635294"/>
</module>

<!-- <module name="mavlink">
<configure name="MAVLINK_BAUD" value="B115200"/>
Expand Down
1 change: 1 addition & 0 deletions conf/modules/wing_rotation_adc_sensor.xml
Expand Up @@ -13,6 +13,7 @@
<configure name="ADC_CHANNEL_WING_ROTATION_CONTROLLER_POSITION" default="ADC_5" case="lower|upper"/>
<define name="ADC_CHANNEL_WING_ROTATION_CONTROLLER_POSITION" value="$(ADC_CHANNEL_WING_ROTATION_CONTROLLER_POSITION_UPPER)"/>
<define name="USE_$(ADC_CHANNEL_WING_ROTATION_CONTROLLER_POSITION_UPPER)"/>
<define name="ADC_WING_ROTATION" value="TRUE"/>
<file name="wing_rotation_adc_sensor.c"/>
</makefile>
</module>
7 changes: 7 additions & 0 deletions sw/airborne/modules/rot_wing_drone/rotwing_state.c
Expand Up @@ -105,6 +105,13 @@
#define ROTWING_STATE_FW_PREF_PITCH 8.0
#endif

// stream ADC data if ADC rotation sensor
#ifndef ADC_WING_ROTATION
#define ADC_WING_ROTATION FALSE
#endif
#if ADC_WING_ROTATION
#include "wing_rotation_adc_sensor.h"
#endif
/** ABI binding feedback data.
*/
#ifndef ROTWING_STATE_ACT_FEEDBACK_ID
Expand Down
22 changes: 18 additions & 4 deletions sw/airborne/modules/rot_wing_drone/wing_rotation_adc_sensor.c
Expand Up @@ -39,21 +39,35 @@
#define ADC_CHANNEL_WING_ROTATION_CONTROLLER_POSITION_NB_SAMPLES 16
#endif

static struct adc_buf buf_wing_rot_pos;
#ifndef ADC_WING_ROT_OFFSET
#error "ADC_WING_ROT_OFFSET not defined"
#endif

#ifndef ADC_WING_ROT_SCALE
#error "ADC_WING_ROT_SCALE not defined"
#endif

#ifdef ADC_WING_ROT_OFFSET
static float adc_offset = ADC_WING_ROT_OFFSET;
#endif

#ifdef ADC_WING_ROT_SCALE
static float adc_scale = ADC_WING_ROT_SCALE;
#endif

static struct adc_buf buf_wing_rot_pos;
// Initialization
void wing_rotation_adc_init(void)
{
// ADC init
adc_buf_channel(ADC_CHANNEL_WING_ROTATION_CONTROLLER_POSITION, &buf_wing_rot_pos,
ADC_CHANNEL_WING_ROTATION_CONTROLLER_POSITION_NB_SAMPLES);
ADC_CHANNEL_WING_ROTATION_CONTROLLER_POSITION_NB_SAMPLES);
}

void wing_rotation_adc_to_deg(void)
{
float adc_wing_rotation = buf_wing_rot_pos.sum / buf_wing_rot_pos.av_nb_sample;
float wing_angle_deg = 0.00247111 * adc_wing_rotation - 25.635294;

float wing_angle_deg = adc_scale * adc_wing_rotation + adc_offset;

// SEND ABI Message to ctr_eff_sched and other modules that want Actuator position feedback
struct act_feedback_t feedback = {0};
Expand Down

0 comments on commit afa9378

Please sign in to comment.