diff --git a/quad/src/quad_app/control_algorithm.c b/quad/src/quad_app/control_algorithm.c index 7edd1837e8b946809037cad979fb8834c6a75728..5e1ebfd7dd227de54ab2ec80b02896b02d26694b 100644 --- a/quad/src/quad_app/control_algorithm.c +++ b/quad/src/quad_app/control_algorithm.c @@ -97,17 +97,17 @@ int control_algorithm_init(parameter_t * ps) graph_set_source(graph, ps->pitch_r_pid, PID_SETPOINT, ps->pitch_pid, PID_CORRECTION); graph_set_source(graph, ps->pitch_r_pid, PID_CUR_POINT, ps->theta_dot, CONST_VAL); graph_set_source(graph, ps->pitch_r_pid, PID_DT, ps->angle_time, CONST_VAL); - //graph_set_source(graph, ps->pitch_pid, PID_CUR_POINT, ps->cur_pitch, CONST_VAL); - graph_set_source(graph, ps->pitch_pid, PID_CUR_POINT, ps->vrpn_pitch, CONST_VAL); - graph_set_source(graph, ps->pitch_pid, PID_DT, ps->pos_time, CONST_VAL); + graph_set_source(graph, ps->pitch_pid, PID_CUR_POINT, ps->cur_pitch, CONST_VAL); + //graph_set_source(graph, ps->pitch_pid, PID_CUR_POINT, ps->vrpn_pitch, CONST_VAL); + graph_set_source(graph, ps->pitch_pid, PID_DT, ps->angle_time, CONST_VAL); // Connect roll PID chain graph_set_source(graph, ps->roll_r_pid, PID_SETPOINT, ps->roll_pid, PID_CORRECTION); graph_set_source(graph, ps->roll_r_pid, PID_CUR_POINT, ps->phi_dot, CONST_VAL); graph_set_source(graph, ps->roll_r_pid, PID_DT, ps->angle_time, CONST_VAL); - //graph_set_source(graph, ps->roll_pid, PID_CUR_POINT, ps->cur_roll, CONST_VAL); - graph_set_source(graph, ps->roll_pid, PID_CUR_POINT, ps->vrpn_roll, CONST_VAL); - graph_set_source(graph, ps->roll_pid, PID_DT, ps->pos_time, CONST_VAL); + graph_set_source(graph, ps->roll_pid, PID_CUR_POINT, ps->cur_roll, CONST_VAL); + //graph_set_source(graph, ps->roll_pid, PID_CUR_POINT, ps->vrpn_roll, CONST_VAL); + graph_set_source(graph, ps->roll_pid, PID_DT, ps->angle_time, CONST_VAL); // Connect yaw PID chain graph_set_source(graph, ps->yaw_r_pid, PID_SETPOINT, ps->rc_yaw, PID_CORRECTION); diff --git a/quad/src/quad_app/hw_iface.h b/quad/src/quad_app/hw_iface.h index 6e6bbaa0ff99e61531a3daf7753d4d6a09a05f64..bbd6bb6fc14171d0f506151a1b87bffb9b869b21 100644 --- a/quad/src/quad_app/hw_iface.h +++ b/quad/src/quad_app/hw_iface.h @@ -37,7 +37,7 @@ struct TimerDriver { void *state; int (*reset)(struct TimerDriver *self); int (*restart)(struct TimerDriver *self); - int (*read)(struct TimerDriver *self, unsigned long *us); + int (*read)(struct TimerDriver *self, unsigned long long *us); }; struct LEDDriver { diff --git a/quad/src/quad_app/log_data.c b/quad/src/quad_app/log_data.c index db9c7d363286ea56dce71145938b6b50d22f77c6..2c789b1a96a5067b100e03b7e2986bd17b7ab9ab 100644 --- a/quad/src/quad_app/log_data.c +++ b/quad/src/quad_app/log_data.c @@ -170,7 +170,7 @@ void printLogging(hardware_t *hardware_struct, log_t* log_struct, parameter_t* p } char data[1] = {0}; // 1 byte to make compilers happy - send_data(LOG_END_ID, 0, data, 0); + send_data(&hardware_struct->uart, LOG_END_ID, 0, data, 0); } void resetLogging() { diff --git a/quad/src/quad_app/quad_app.c b/quad/src/quad_app/quad_app.c index fd195159c34054309d9c9facb80b0bc1545376cb..22829b5c8d2a6e5247a670f348c4ecad03dc6473 100644 --- a/quad/src/quad_app/quad_app.c +++ b/quad/src/quad_app/quad_app.c @@ -16,6 +16,7 @@ #include "send_actuator_commands.h" #include "update_gui.h" #include "communication.h" +#include "mio7_led.h" //#define BENCH_TEST //#define UART_BENCHMARK @@ -90,7 +91,7 @@ int quad_main(int (*setup_hardware)(hardware_t *hardware_struct)) send_actuator_commands(&(structs.hardware_struct.pwm_outputs), &(structs.log_struct), &(structs.actuator_command_struct)); } else { - pwm_kill(); + kill_motors(&(structs.hardware_struct.pwm_outputs)); } // update the GUI update_GUI(&(structs.log_struct)); @@ -135,7 +136,7 @@ int quad_main(int (*setup_hardware)(hardware_t *hardware_struct)) last_kill_condition = this_kill_condition; } - kill_motors(); + kill_motors(&(structs.hardware_struct.pwm_outputs)); flash_MIO_7_led(10, 100); diff --git a/quad/src/quad_app/timer.c b/quad/src/quad_app/timer.c index ce6333e40b37a16e14fa80251c79369020120422..ea41a03793ff6d50554300a796ddceec20af4a78 100644 --- a/quad/src/quad_app/timer.c +++ b/quad/src/quad_app/timer.c @@ -1,7 +1,7 @@ #include "timer.h" -u32 before = 0, after = 0; -float LOOP_TIME; +u64 before = 0, after = 0; +float LOOP_TIME; // microseconds float time_stamp = 0; struct TimerDriver *global_timer; @@ -24,7 +24,7 @@ int timer_start_loop() int timer_end_loop(log_t *log_struct) { // get number of useconds its taken to run the loop thus far - u32 usec_loop; + u64 usec_loop; axi_timer->read(axi_timer, &usec_loop); // attempt to make each loop run for the same amount of time @@ -44,11 +44,11 @@ int timer_end_loop(log_t *log_struct) } float get_last_loop_time() { - return LOOP_TIME; + return (float)LOOP_TIME / 1000000; } u32 timer_get_count() { - u32 time; + u64 time; return axi_timer->read(axi_timer, &time); return time; } diff --git a/quad/src/quad_app/type_def.h b/quad/src/quad_app/type_def.h index 1dad790da9f3c65d7e4c46153cf033ae2bcbd765..8d6363cfa70c9eeff3bb0aa8dbac7cafefd466a1 100644 --- a/quad/src/quad_app/type_def.h +++ b/quad/src/quad_app/type_def.h @@ -16,6 +16,7 @@ typedef unsigned char u8; typedef unsigned short u16; typedef unsigned long u32; +typedef unsigned long long u64; typedef signed char i8; typedef signed short i16; typedef signed long i32; diff --git a/quad/src/quad_app/util.h b/quad/src/quad_app/util.h index 0a6bd21c727cca4f27ec44da1dd640e269dce66b..0d06e5fe0075b5c0808a2bca4e8746e57ecf7dcf 100644 --- a/quad/src/quad_app/util.h +++ b/quad/src/quad_app/util.h @@ -14,7 +14,7 @@ void read_rec_all(struct PWMInputDriver *pwm_input, u32 *mixer); int read_kill(int gear); int read_flap(int flap); -void kill_motors(); +void kill_motors(struct PWMOutputDriver *pwm_outputs); int build_int(u8 *buff); float build_float(u8 *buff); diff --git a/quad/xsdk_workspace/modular_quad_pid/src/hw_impl_zybo.h b/quad/xsdk_workspace/modular_quad_pid/src/hw_impl_zybo.h index 7be77d63491dd07e0cf8e6f187f4118b90f5ae34..c721307bc08674e414683630564a2f7adf0dd2da 100644 --- a/quad/xsdk_workspace/modular_quad_pid/src/hw_impl_zybo.h +++ b/quad/xsdk_workspace/modular_quad_pid/src/hw_impl_zybo.h @@ -40,11 +40,11 @@ int zybo_i2c_read(struct I2CDriver *self, int zybo_global_timer_reset(struct TimerDriver *self); int zybo_global_timer_restart(struct TimerDriver *self); -int zybo_global_timer_read(struct TimerDriver *self, unsigned long *us); +int zybo_global_timer_read(struct TimerDriver *self, u64 *us); int zybo_axi_timer_reset(struct TimerDriver *self); int zybo_axi_timer_restart(struct TimerDriver *self); -int zybo_axi_timer_read(struct TimerDriver *self, unsigned long *us); +int zybo_axi_timer_read(struct TimerDriver *self, u64 *us); int zybo_mio7_led_reset(struct LEDDriver *self); int zybo_mio7_led_turn_on(struct LEDDriver *self); diff --git a/quad/xsdk_workspace/modular_quad_pid/src/hw_impl_zybo_axi_timer.c b/quad/xsdk_workspace/modular_quad_pid/src/hw_impl_zybo_axi_timer.c index bbbb5e3a3794926729063f435b26cc319d771869..fa4bb05a6a5bb0bea2167446297a9a29c0b6b9ca 100644 --- a/quad/xsdk_workspace/modular_quad_pid/src/hw_impl_zybo_axi_timer.c +++ b/quad/xsdk_workspace/modular_quad_pid/src/hw_impl_zybo_axi_timer.c @@ -15,7 +15,7 @@ int zybo_axi_timer_restart(struct TimerDriver *self) { return 0; } -int zybo_axi_timer_read(struct TimerDriver *self, unsigned long *us) { +int zybo_axi_timer_read(struct TimerDriver *self, u64 *us) { // Returns the number of useconds *us = XTmrCtr_GetValue(self->state, 0) / PL_CLK_CNTS_PER_USEC; return 0; diff --git a/quad/xsdk_workspace/modular_quad_pid/src/hw_impl_zybo_global_timer.c b/quad/xsdk_workspace/modular_quad_pid/src/hw_impl_zybo_global_timer.c index 9f59573dfcab7f6971881a51988d4cbcb6dc6d90..c1024a62f57e9e16eda073268e991012973ec35b 100644 --- a/quad/xsdk_workspace/modular_quad_pid/src/hw_impl_zybo_global_timer.c +++ b/quad/xsdk_workspace/modular_quad_pid/src/hw_impl_zybo_global_timer.c @@ -10,9 +10,9 @@ int zybo_global_timer_restart(struct TimerDriver *self) { return 0; } -int zybo_global_timer_read(struct TimerDriver *self, unsigned long *us) { +int zybo_global_timer_read(struct TimerDriver *self, u64 *us) { XTime time; XTime_GetTime(&time); - *us = (time * 1000000) / COUNTS_PER_SECOND; // (ticks)(1000000us/s)(s/ticks) + *us = ((u64)time * 1000000) / COUNTS_PER_SECOND; // (ticks)(1000000us/s)(s/ticks) return 0; }