diff --git a/conf/airframes/motor_bench.xml b/conf/airframes/motor_bench.xml index 1a151bec33..e4de2c7e6f 100644 --- a/conf/airframes/motor_bench.xml +++ b/conf/airframes/motor_bench.xml @@ -32,7 +32,7 @@ main.srcs += $(SRC_ARCH)/mb_servo.c main.CFLAGS += -DMB_TACHO main.srcs += $(SRC_ARCH)/mb_tacho.c -main.CFLAGS += -DADC -DUSE_ADC_0 +main.CFLAGS += -DADC -DUSE_ADC_0 -DUSE_ADC_1 main.srcs += $(SRC_ARCH)/adc_hw.c main.srcs += $(SRC_ARCH)/mb_current.c diff --git a/conf/autopilot/conf_motor_bench.h b/conf/autopilot/conf_motor_bench.h index 2fabfd1327..0b79017167 100644 --- a/conf/autopilot/conf_motor_bench.h +++ b/conf/autopilot/conf_motor_bench.h @@ -30,4 +30,15 @@ //#define USE_AD0_0 #endif +#define ADC_1 AdcBank0(1) +#ifdef USE_ADC_1 +#ifndef USE_AD0 +#define USE_AD0 +#endif +#define USE_AD0_1 +#endif + + + + #endif /* CONFIG_MOTOR_BENCH_H */ diff --git a/sw/airborne/arm7/adc_hw.c b/sw/airborne/arm7/adc_hw.c index 6dbe17d498..6c68918e4f 100644 --- a/sw/airborne/arm7/adc_hw.c +++ b/sw/airborne/arm7/adc_hw.c @@ -181,6 +181,7 @@ void adc_init( void ) { } #include "led.h" + #include "uart.h" #include "messages.h" #include "downlink.h" @@ -192,7 +193,6 @@ void adcISR0 ( void ) { uint8_t channel = (uint8_t)(tmp >> 24) & 0x07; uint16_t value = (uint16_t)(tmp >> 6) & 0x03FF; adc0_val[channel] = value; - DOWNLINK_SEND_BOOT(&value); struct adc_buf* buf = buffers[channel]; if (buf) { diff --git a/sw/airborne/arm7/mb_current.c b/sw/airborne/arm7/mb_current.c index c62f2378d7..b97b784a51 100644 --- a/sw/airborne/arm7/mb_current.c +++ b/sw/airborne/arm7/mb_current.c @@ -14,6 +14,8 @@ void mb_current_init(void) { void mb_current_periodic(void) { uint16_t cur_int = mb_current_buf.sum / mb_current_buf.av_nb_sample; - // uint16_t cur_int = adc0_val[0]; - mb_current_amp = cur_int * 1.; + // mb_current_amp = (float)mb_current_buf.sum; + // mb_current_amp = (((float)cur_int / 1024 * 5) - 0.77)/ 0.185; + mb_current_amp = (float)mb_current_buf.sum * 0.00113607 - 2.8202; + } diff --git a/sw/airborne/arm7/mb_modes.c b/sw/airborne/arm7/mb_modes.c index 82f7836ca5..62d93db7e5 100644 --- a/sw/airborne/arm7/mb_modes.c +++ b/sw/airborne/arm7/mb_modes.c @@ -1,21 +1,38 @@ #include "mb_modes.h" +#include "adc.h" + uint8_t mb_modes_mode; float mb_modes_throttle; + +static struct adc_buf mb_modes_adc_buf; /* manual mode */ + void mb_mode_init(void) { - mb_modes_mode = MB_MODES_IDLE; + adc_buf_channel(1, &mb_modes_adc_buf, 16); + mb_modes_mode = MB_MODES_MANUAL; mb_modes_throttle = 0.; } void mb_mode_event(void) {} - void mb_mode_periodic(void) { - mb_modes_throttle += 0.0001; - if (mb_modes_throttle > 1.) + + uint16_t poti = mb_modes_adc_buf.sum; + + switch (mb_modes_mode) { + case MB_MODES_MANUAL : + mb_modes_throttle = (float)poti/(16.*1024.); + break; + case MB_MODES_RAMP : + mb_modes_throttle += 0.0001; + if (mb_modes_throttle > 1.) + mb_modes_throttle = 0.; + break; + default: mb_modes_throttle = 0.; + } } diff --git a/sw/airborne/arm7/mb_modes.h b/sw/airborne/arm7/mb_modes.h index a406b353f6..b65b438866 100644 --- a/sw/airborne/arm7/mb_modes.h +++ b/sw/airborne/arm7/mb_modes.h @@ -4,10 +4,11 @@ #include "std.h" -#define MB_MODES_IDLE 0 -#define MB_MODES_RAMP 1 -#define MB_MODES_STEP 2 -#define MB_MODES_PRBS 3 +#define MB_MODES_IDLE 0 +#define MB_MODES_MANUAL 1 +#define MB_MODES_RAMP 2 +#define MB_MODES_STEP 3 +#define MB_MODES_PRBS 4 extern uint8_t mb_modes_mode; extern float mb_modes_throttle; diff --git a/sw/airborne/main_motor_bench.c b/sw/airborne/main_motor_bench.c index 24e2a7b846..df98d2b742 100644 --- a/sw/airborne/main_motor_bench.c +++ b/sw/airborne/main_motor_bench.c @@ -53,6 +53,7 @@ static inline void main_periodic_task( void ) { float throttle = mb_modes_throttle; mb_servo_set(throttle); float rpm = mb_tacho_get_averaged(); + mb_current_periodic(); float amps = mb_current_amp; static uint8_t my_cnt = 0; my_cnt++; diff --git a/sw/in_progress/motor_bench/Makefile b/sw/in_progress/motor_bench/Makefile new file mode 100644 index 0000000000..c07d127fea --- /dev/null +++ b/sw/in_progress/motor_bench/Makefile @@ -0,0 +1,9 @@ +CC = gcc +CFLAGS=-g -O2 -Wall `pkg-config gtk+-2.0 --cflags` +LDFLAGS=`pkg-config gtk+-2.0 --libs` -s `pcre-config --libs` -lglibivy + + +motor_bench : main.c + $(CC) $(CFLAGS) -g -o $@ $^ $(LDFLAGS) + +# -lgtkdatabox \ No newline at end of file diff --git a/sw/in_progress/motor_bench/main.c b/sw/in_progress/motor_bench/main.c new file mode 100644 index 0000000000..08811a4d43 --- /dev/null +++ b/sw/in_progress/motor_bench/main.c @@ -0,0 +1,57 @@ +#include +#include +#include +#include +#include + +#include +#include + +//#include "sliding_plot.h" + + +GtkWidget* build_gui ( void ) { + + GtkWidget *window1; + GtkWidget *vbox1; + + + window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_window_set_title (GTK_WINDOW (window1), "motor_bench"); + + vbox1 = gtk_vbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (window1), vbox1); + + return window1; +} + +#if 0 +void on_scale_value_changed (GtkScale *scale, gpointer user_data) { + gfloat cf = gtk_range_get_value(GTK_RANGE(scale)); + gint c = round(cf); + g_message("foo %d %f", user_data, c); + IvySendMsg("ME RAW_DATALINK 16 SETTING;%d;0;%d", (gint)user_data, c); +} +#endif + + +void on_MOTOR_BENCH_STATUS(IvyClientPtr app, void *user_data, int argc, char *argv[]){ + int time_ticks = atoi(argv[0]); + g_message("foo %d", time_ticks); + +} + +int main (int argc, char** argv) { + + gtk_init(&argc, &argv); + + GtkWidget* window = build_gui(); + gtk_widget_show_all(window); + + IvyInit ("MotorBench", "MotorBench READY", NULL, NULL, NULL, NULL); + IvyBindMsg(on_MOTOR_BENCH_STATUS, NULL, "^\\S* MOTOR_BENCH_STATUS (\\S*) (\\S*) (\\S*) (\\S*),(\\S*),(\\S*)"); + IvyStart("127.255.255.255"); + + gtk_main(); + return 0; +}