Commit 219b0da4 authored by Alex Wang Fu's avatar Alex Wang Fu
Browse files

new set wing angle works

parent 872b703e
......@@ -57,6 +57,10 @@ static volatile uint32_t current_compare = 0;
#define LEFT true
#define RIGHT false
static int left_wing_degrees = 0;
static int right_wing_degrees = 0;
//Interrupt handler function for performing PID calculation
void control_interrupt_handler(uint8_t index) {
if (index != control_tc_index) return;
......@@ -64,9 +68,9 @@ void control_interrupt_handler(uint8_t index) {
Tc* tc = tc_insts[index];
if (!tc->COUNT16.INTFLAG.bit.MC0) return;
printf("in timer interrupt\n");
printf("Left: %d, right: %d\n", left_wing_degrees, right_wing_degrees);
// set_wing_angle(LEFT,degrees); //For setting the LEFT wing angle (degrees is a global variable whose value originates from the Python function control.tasks(degrees))
//set_wing_angle(LEFT,degrees); //For setting the LEFT wing angle (degrees is a global variable whose value originates from the Python function control.tasks(degrees))
//set_wing_angle(RIGHT, degrees); //For setting the RIGHT wing angle (angle needs a global variable from Python script)
// Clear the interrupt bit.
......@@ -143,8 +147,16 @@ void common_hal_motor_PID(void){
/*The function that updates the variable "degrees" with the new setpoint value from Python's control.tasks(degrees).
This function disables interrupts first and then updates "degrees".
The interrupts get reenabled with common_hal_motor_PID() is called. */
void control_set_degrees(float d){
The interrupts get reenabled with common_hal_motor_PID() is called.
Assumes that interrupts have already started.
void control_set_degrees(int side, float d){
degrees = d;
if(side == LEFT) {
left_wing_degrees = d;
} else {
right_wing_degrees = d;
// Reenable interrupts
......@@ -36,8 +36,6 @@
void control_interrupt_handler(uint8_t index);
void common_hal_motor_construct(void);
void common_hal_motor_PID(void);
void control_set_degrees(float);
extern int degrees;
void control_set_degrees(int side, float degreres);
......@@ -167,6 +167,8 @@ void shared_module_ee285_wing_leds(int side, mp_obj_t rgb1, mp_obj_t rgb2, mp_ob
common_hal_neopixel_write(&io, pixels, NUM_WING_LEDS*3);
static bool motor_control_initted = false;
void shared_module_ee285_motor_control_loop_init(void) {
// Init accels
......@@ -177,14 +179,17 @@ void shared_module_ee285_motor_control_loop_init(void) {
// Init interrupts
motor_control_initted = true;
void shared_module_ee285_wing_angle(int side, float angle)
//This should interface with the control loop
// here we should call control_set_degrees and common_hal_motor_PID
// and perhaps restructure so that it enables and disabled interrupts all in the
// same fn call?
if(!motor_control_initted) {
printf("Motor control loop not yet initted! Init first!\n");
control_set_degrees(side, angle);
......@@ -54,7 +54,7 @@ void interrupt_work(void){
common_hal_motor_PID(); // uhh shouldn;t this come after control_set_degrees???
// also... we're gonna want to put this into the wing_angle function in the ee285 module instead of the control
// control_set_degrees(degrees);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment