Commit 7f4e2306 authored by zataraclark's avatar zataraclark
Browse files

Changed do_hard_coded_offset to run through each phase before holding at phase 6

parent d8113077
......@@ -18,12 +18,12 @@ bool calibration_complete = false; // similar to the bool above but not used ins
// define the offset from zero using interrupt and the z signal
// This offset is different each time it starts up and must be calibrated
int Zoffset = 0;
int Zoffset = 0; // THIS IS NOT THE HARDCODED OFFSET, DON'T EDIT IT
// This is the difference in encoder tics from the Z index to
// the electrical encoder zero (which is found by powering the
// AB block and waiting for the motor to settle)
int hard_coded_offset = -420 - 50;
int hard_coded_offset = 2406 - 50;
//Invert position to invert position add 341 to any offset
......@@ -258,11 +258,11 @@ int calibrate_encoder()
set_block_phase(p);
delayMicroseconds(CALIBRATION_DELAY);
}
turn_all_off();
turn_all_mosfets_off();
if(calibrated == true){
//ditch the interrupt
turn_all_off();
turn_all_mosfets_off();
detachInterrupt(digitalPinToInterrupt(Z));
if(getDebugOn()) {
......@@ -275,7 +275,7 @@ int calibrate_encoder()
}
}
turn_all_off();
turn_all_mosfets_off();
Serial.println("CALIBRATION FAILED");
return -1;
}
......
......@@ -48,6 +48,8 @@ H TO TO SEND SPECIFIC PHASES DEBUG MOTOR\n");
if (Serial.available()) {
incomingByte = Serial.read();
}
if(incomingByte == ' ')//space bar
{
break;
......
......@@ -9,9 +9,9 @@
#define H1 6 //greenH
#define H2 21 //yellowH
#define H3 23 //blueH
#define H3 23 //blueH
#define L1 5 //GreenL
#define L2 20 //YellowL
#define L2 20 //YellowL
#define L3 22 //BlueL
// TODO: #define coast <available pin>
......@@ -46,7 +46,7 @@ int POT_0_VALUE = 0;
void pot_0_speed_ISR();
void turn_all_off();
void turn_all_mosfets_off();
int one_to_scaleFactor(int x);
void set_phase(int high1, int high2, int high3, int low1, int low2, int low3);
void set_block_phase(int phase);
......@@ -79,7 +79,7 @@ void motor_setup(void) {
analogWriteFrequency(L2, FREQ);
analogWriteFrequency(L3, FREQ);
turn_all_off();
turn_all_mosfets_off();
//setup the halfbridges enables
// pinMode(HB1EN, OUTPUT);
......@@ -117,7 +117,7 @@ void pot_0_speed_ISR() {
// }
}
void turn_all_off() {
void turn_all_mosfets_off() {
analogWrite(L1, 0);
analogWrite(L2, 0);
analogWrite(L3, 0);
......@@ -176,7 +176,7 @@ void set_block_phase(int phase)
set_phase(0,0,1,0,1,0); //Phase CB
break;
default :
turn_all_off();
turn_all_mosfets_off();
//no break needed
}
return;
......@@ -435,11 +435,11 @@ void open_loop_control(void)
// this should allways be called right before powering the motor
void charge_bootstrap_capacitors(void)
{
turn_all_off();
turn_all_mosfets_off();
delayMicroseconds(50);
set_phase(0,0,0,1,1,1);
delayMicroseconds(50);
turn_all_off();
turn_all_mosfets_off();
}
//using hardcoded located state positions
......@@ -547,7 +547,7 @@ void debug_motor(void) {
Serial.println(incomingByte);
}
switch (incomingByte - 48)
switch (incomingByte - '0')
{
case 0:
Serial.println("AROUND THE WORLD");
......@@ -565,7 +565,7 @@ void debug_motor(void) {
set_phase(0,0,1,0,1,0);
delay(10);
}
turn_all_off();
turn_all_mosfets_off();
Serial.println("DONE WITH AROUND THE WORLD");
case 1:
......@@ -599,7 +599,7 @@ void debug_motor(void) {
break;
case -16:
turn_all_off();
turn_all_mosfets_off();
Serial.println("STOP THE PRESSES!!!");
break;
......
......@@ -2,7 +2,7 @@
#define MOTOR_CTRL_H_
void motor_setup(void);
void turn_all_off();
void turn_all_mosfets_off();
void set_block_phase(int phase);
void debug_motor(void);
void open_loop_control(void);
......
......@@ -67,7 +67,7 @@ int get_pot_0_scaled(int scaleFactor, float period_over_255)
if ((potval - UPWARD_ROC_PREV_VALUE) > UPWARD_ROC_LIMITER) {
potval = UPWARD_ROC_PREV_VALUE + UPWARD_ROC_LIMITER;
}
else if ((potval - UPWARD_ROC_PREV_VALUE) < UPWARD_ROC_LIMITER) {
else if ((potval - UPWARD_ROC_PREV_VALUE) < -UPWARD_ROC_LIMITER) {
potval = UPWARD_ROC_PREV_VALUE - UPWARD_ROC_LIMITER;
}
......@@ -123,12 +123,22 @@ void do_hard_coded_offset(void)
while(1)
{
int my_position = 0;
set_block_phase(1);
delayMicroseconds(500000); //half sec delay
set_block_phase(2);
delayMicroseconds(500000); //half sec delay
set_block_phase(3);
delayMicroseconds(500000); //half sec delay
set_block_phase(4);
delayMicroseconds(500000); //half sec delay
set_block_phase(5);
delayMicroseconds(500000); //half sec delay
set_block_phase(6);
delayMicroseconds(1000000); //1 sec delay
//now lets grab the position
my_position = get_raw_wheel_position_ticks() - get_Zoffset();
//turn it off!
turn_all_off();
turn_all_mosfets_off();
//print it out wayyyy too much It is supposed to get stuck here
Serial.println("Get Hard coded offset got a BC position of:");
Serial.println(my_position);
......@@ -157,7 +167,7 @@ void locate_state_positions(void)
Serial.printf("%d:%d\n", p, get_wheel_position_ticks());
}
}
turn_all_off();
turn_all_mosfets_off();
while(1)
{
}
......@@ -168,9 +178,9 @@ void debug_low_state_by_state(void)
while(1){
Serial.println("lets run some debug tests");
Serial.println("Hit space to call turn_all_off()");
Serial.println("Hit space to call turn_all_mosfets_off()");
block_until_spacebar();
turn_all_off();
turn_all_mosfets_off();
Serial.println("Hit space to call setphase(0,0,0,0,0,0)");
block_until_spacebar();
set_phase(0,0,0,0,0,0);
......
......@@ -11,6 +11,7 @@ void locate_state_positions(void);
void direct_position_control(void);
void debug_low_state_by_state(void);
int debug_pot_0_scaled(void);
void set_calibration_complete(void);
......
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