Commit 27a41275 authored by mattdr's avatar mattdr
Browse files

just starting to work sin controll

parent b1f48da8
......@@ -20,7 +20,7 @@ int Zoffset = 0;
// 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 = 910;
int hard_coded_offset = -1123;
// how long in microsec (us) to delay between phases while calibrating
// the wheel
......@@ -43,8 +43,8 @@ int get_phase_number(int elec_position);
//init our internal counter for quad decode
// (x_a = pin 3)
// (x_b = pin 4)
// (x_a = pin 3) white
// (x_b = pin 4) grey
QuadDecode<1> encoder; // Template using FTM1
//setup quadrature decoding
......
......@@ -21,7 +21,8 @@ Z TO GET HARDCODED OFFSET \n\
O TO START OPEN LOOP CONTROL\n\
L TO LOCATE STATE POSITIONS\n\
D TO START DIRECT POSITION CONTROL\n\
B TO START BUTT CONTROL (NON-OPTIMIZED)\n");
B TO START BUTT CONTROL (NON-OPTIMIZED)\n\
S TO START BUTT CONTROL (OPTIMIZED)\n");
int choice = get_input(prompt);
if(choice == 2){
do_hard_coded_offset();// run the set zero
......@@ -42,6 +43,10 @@ B TO START BUTT CONTROL (NON-OPTIMIZED)\n");
{
motor_butt_control_inefficient();
}
if(choice == 7)
{
motor_butt_control_precalculated();
}
int calibration_return = calibrate_encoder();
if(calibration_return == -1)
{
......
......@@ -3,6 +3,7 @@
#include "utils.h"
#include "encoder.h"
#include "math.h"
#include "sin_factors.h"
#define pi 3.1415926535897932384626433832795
......@@ -21,6 +22,8 @@ void set_phase(int high1, int high2, int high3, int low1, int low2, int low3);
void set_block_phase(int phase);
void motor_butt_control_inefficient(void);
void set_phase_float(float f1, float f2, float f3);
void motor_butt_control_precalculated(void);
......@@ -60,7 +63,7 @@ int one_to_255(int x)
{
float potval = analogRead(A0);
potval = potval/1024;
potval = potval * 40;
potval = potval * 20;
return (int)potval; //read from pot
}
else{
......@@ -125,11 +128,15 @@ void set_phase_float(float f1, float f2, float f3)
//deal with the potentiometer first
float potval = analogRead(A0);
potval = potval/1024;
potval = potval * 40;
potval = potval * 20;
f1 = (f1 * potval);
f2 = (f2 * potval);
f3 = (f3 * potval);
int f1i = (int)(f1 * potval);
int f2i = (int)(f2 * potval);
int f3i = (int)(f3 * potval);
int f1i = (int) f1;
int f2i = (int) f2;
int f3i = (int) f3;
if(f1i == 0){
digitalWrite(L1, 1);
......@@ -175,6 +182,26 @@ void motor_butt_control_inefficient(void)
}
}
void motor_butt_control_precalculated(void)
{
calibrate_encoder();
block_until_spacebar();
while(1)
{
// get the current encoder tics (this does the math to offset)
int position = get_wheel_position_ticks();
// get position within current electrical revolution
int ele_position = get_elec_rev_position_ticks(position);
float f1 = A_SIN_FACTORS_SHIFTED[ele_position];
float f2 = B_SIN_FACTORS_SHIFTED[ele_position];
float f3 = C_SIN_FACTORS_SHIFTED[ele_position];
set_phase_float(f1,f2,f3);
}
}
//This just spins the motor using speed (potentiometer on pin A1)
//and torque (potentiometer on pin A0)
void open_loop_control(void)
......
......@@ -9,6 +9,7 @@ void open_loop_control(void);
void set_phase(int high1, int high2, int high3, int low1, int low2, int low3);
void motor_butt_control_inefficient(void);
void set_phase_float(float f1, float f2, float f3);
void motor_butt_control_precalculated(void);
......
This diff is collapsed.
......@@ -68,6 +68,10 @@ int get_input(char * prompt)
{
return 6;
}
else if (incomingByte == 's') //'b'
{
return 7;
}
}
}
......
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