Commit c3eadfee authored by thcl's avatar thcl
Browse files

Added code for a Debug Jumper. We also reenabled the encoder calibration by block control.

parent f1e320d7
......@@ -4,6 +4,7 @@
#include <avr/interrupt.h>
#include "motor_ctrl.h"
#include "encoder.h"
#include "utils.h"
#define Z 7
......@@ -34,7 +35,7 @@ int button_offset_increment = 5;
// how long in microsec (us) to delay between phases while calibrating
// the wheel
int calibration_delay = 1000;
int CALIBRATION_DELAY = 28500;
// Timer setup (for speed calc)
IntervalTimer speed_timer;
......@@ -81,16 +82,20 @@ void encoder_setup(void)
//xPosn.zeroFTM(); //This zeros the counter
//setup the speed timer to run every 1 sec
speed_timer.begin(print_speed_ISR, 1000000);
delay(1000); //sit tight for a bit
if(getDebugOn()) {
//setup interupts to allow button presses
pinMode(ButtonA, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(ButtonA), buttonA_ISR, RISING);
pinMode(ButtonB, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(ButtonB), buttonB_ISR, RISING);
//setup the speed timer to run every 1 sec
speed_timer.begin(print_speed_ISR, 1000000);
delay(1000); //sit tight for a bit
//setup interupts to allow button presses
pinMode(ButtonA, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(ButtonA), buttonA_ISR, RISING);
pinMode(ButtonB, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(ButtonB), buttonB_ISR, RISING);
}
}
void buttonA_ISR(){
......@@ -235,42 +240,33 @@ void isr_index_print(void){
// This function will turn the motor blindly forward until it finds
// the zero index
// if this process fails will return -1 else will return 1
int calibrate_encoder(void)
int calibrate_encoder()
{
//worst case needs 6 full electrical rotations
Serial.println("STARTING CALIBRATION");
if(getDebugOn()) {
//worst case needs 6 full electrical rotations
Serial.println("STARTING CALIBRATION");
}
while(1){
// for(int p = 1; p <= 6; p++)
// {
// set_block_phase(p);
// int myDelay = 28500;
// delayMicroseconds(myDelay);
// }
for(int p = 1; p <= 6; p++)
{
set_block_phase(p);
delayMicroseconds(CALIBRATION_DELAY);
}
turn_all_off();
if(calibrated == true){
//ditch the interrupt
turn_all_off();
detachInterrupt(digitalPinToInterrupt(Z));
Serial.println("CALIBRATION SUCCESSFULL");
if(getDebugOn()) {
Serial.println("CALIBRATION SUCCESSFULL");
}
return 1;
}
}
// for(int i=0; i < 6; i++)
// {
// for (int p=1; p <= 6; p++)
// {
// set_block_phase(p);
// delayMicroseconds(calibration_delay);
// if(calibrated == true){
// //ditch the interrupt
// turn_all_off();
// detachInterrupt(digitalPinToInterrupt(Z));
// Serial.println("CALIBRATION SUCCESSFULL");
// return 1;
// }
// }
// }
turn_all_off();
Serial.println("CALIBRATION FAILED");
return -1;
......
#ifndef ENCODER_H_ /* Include guard */
#define ENCODER_H_
void encoder_setup(void);
void encoder_setup();
void isr_index(void);
void isr_index_print(void);
int wrap_wheel_tics(int in_position);
......
......@@ -9,8 +9,13 @@
void setup()
{
// Pin Jumper to decide whether we print our options or skip straight to
// Precalculated Butt Control
checkDebugJumper();
motor_setup();
encoder_setup();
//deal with serial (might want this faster)
Serial.begin(9600);//Serial.begin(2000000); //FASTER!
// Hit space bar to start calibration
......@@ -31,6 +36,13 @@ H TO TO SEND SPECIFIC PHASES DEBUG MOTOR\n");
short incomingByte = 0;
while(1)
{
if(!getDebugOn()) {
charge_bootstrap_capacitors();
motor_butt_control_precalculated();
}
Serial.println(prompt);
delay(200); // do not go too fast!
if (Serial.available()) {
......@@ -69,9 +81,6 @@ H TO TO SEND SPECIFIC PHASES DEBUG MOTOR\n");
{
charge_bootstrap_capacitors();
motor_butt_control_precalculated();
// after coasting, when we reengage the motor, we want
// to limit our upwards rate of change
}
else if (incomingByte == 'y') // 'y'
{
......
......@@ -85,12 +85,9 @@ void motor_setup(void) {
//setup led
pinMode(led, OUTPUT);
digitalWrite(led, HIGH);
pinMode(12, OUTPUT);
//setup the pot_0_timer to run every thirty times a second
pot_0_timer.begin(pot_0_speed_ISR, 33333);
}
void pot_0_speed_ISR() {
......@@ -258,13 +255,13 @@ void motor_butt_control_inefficient(void)
void motor_butt_control_precalculated(void)
{
calibrate_encoder();
block_until_spacebar();
if(getDebugOn()) {
block_until_spacebar();
}
while(1)
{
//used to check the speed of this function
digitalWrite(12, HIGH);
// get the current encoder tics (this does the math to offset)
int position = get_wheel_position_ticks();
// get position within current electrical revolution
......@@ -274,9 +271,6 @@ void motor_butt_control_precalculated(void)
float f3 = C_SIN_FACTORS_SHIFTED[ele_position];
set_phase_float(f1,f2,f3);
//used to check the speed of this function
digitalWrite(12, LOW);
}
}
......
......@@ -6,6 +6,25 @@
const float UPWARD_ROC_LIMITER = 0.005;
float UPWARD_ROC_PREV_VALUE = 0;
#define debugJumperOut 11
#define debugJumperIn 12
bool DEBUG_JUMPER_ON = false;
void checkDebugJumper() {
pinMode(debugJumperOut, OUTPUT);
pinMode(debugJumperIn, INPUT);
digitalWrite(debugJumperOut, HIGH);
DEBUG_JUMPER_ON = digitalRead(debugJumperIn);
}
bool getDebugOn() {
return DEBUG_JUMPER_ON;
}
//This function will just block until the user hits the space bar
void block_until_spacebar(void)
{
......
#ifndef UTILS_H_ /* Include guard */
#define UTILS_H_
void checkDebugJumper(void);
bool getDebugOn(void);
void block_until_spacebar(void);
void do_hard_coded_offset(void);
int get_pot_1_inv(void);
......
Supports Markdown
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