Skip to content

Commit

Permalink
Make adc sensor mappable from the airframe. Better interface for adc …
Browse files Browse the repository at this point in the history
…in the rotwing state.
  • Loading branch information
tmldeponti committed Mar 12, 2024
1 parent 12da43e commit 2cf4f78
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions conf/modules/wing_rotation_adc_sensor.xml
Original file line number Diff line number Diff line change
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>
11 changes: 11 additions & 0 deletions sw/airborne/modules/rot_wing_drone/rotwing_state.c
Original file line number Diff line number Diff line change
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 Expand Up @@ -149,7 +156,11 @@ inline void guidance_indi_hybrid_set_wls_settings(float body_v[3], float roll_an
#include "modules/datalink/telemetry.h"
static void send_rotating_wing_state(struct transport_tx *trans, struct link_device *dev)
{
#if ADC_WING_ROTATION
uint16_t adc_dummy = adc_wing_rotation_extern;
#else
uint16_t adc_dummy = 0;
#endif
pprz_msg_send_ROTATING_WING_STATE(trans, dev, AC_ID,
&rotwing_state.current_state,
&rotwing_state.desired_state,
Expand Down
23 changes: 20 additions & 3 deletions sw/airborne/modules/rot_wing_drone/wing_rotation_adc_sensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,38 @@
#define ADC_CHANNEL_WING_ROTATION_CONTROLLER_POSITION_NB_SAMPLES 16
#endif

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

#ifndef ADC_SCALE
#error "ADC_SCALE not defined"
#endif

#ifdef ADC_OFFSET
float adc_offset = ADC_OFFSET;
#endif

#ifdef ADC_SCALE
float adc_scale = ADC_SCALE;
#endif

static struct adc_buf buf_wing_rot_pos;
float adc_wing_rotation_extern;
// 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_wing_rotation_extern = 0;
}

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;
adc_wing_rotation_extern = adc_wing_rotation;

// SEND ABI Message to ctr_eff_sched and other modules that want Actuator position feedback
struct act_feedback_t feedback = {0};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#ifndef WING_ROTATION_ADC_SENSOR_H
#define WING_ROTATION_ADC_SENSOR_H

extern float adc_wing_rotation_extern;
extern void wing_rotation_adc_init(void);
extern void wing_rotation_adc_to_deg(void);

Expand Down

0 comments on commit 2cf4f78

Please sign in to comment.