Commit 939731a6 authored by mattdr's avatar mattdr
Browse files

more work to get motor spinning in open loop

parent e5afa2a7
......@@ -15,11 +15,18 @@ void setup()
Serial.begin(9600);//Serial.begin(2000000); //FASTER!
// Hit space bar to start calibration
// Hit 'z' to run get hard coded offset
Serial.println("SPACE TO START CALIBRATION, Z TO GET HARDCODED OFFSET");
int choice = get_input();
char prompt[] = ("\
SPACE TO START CALIBRATION, \n\
Z TO GET HARDCODED OFFSET \n\
O TO START OPEN LOOP CONTROL\n");
int choice = get_input(prompt);
if(choice == 2){
do_hard_coded_offset();// run the set zero
}
if(choice == 3)
{
open_loop_control();
}
// if the choice==1 just continue...
// while(1){
// Serial.println("AROUND THE WORLD");
......
#include <Arduino.h>
#include "motor_ctrl.h"
#include "utils.h"
#define H1 6 //greenH
#define H2 21 //yellowH
......@@ -111,6 +112,31 @@ void set_phase(int high1, int high2, int high3, int low1, int low2, int low3)
analogWrite(H3, high3);
}
//This just spins the motor using speed (potentiometer on pin A1)
//and torque (potentiometer on pin A0)
void open_loop_control(void)
{
while(1)
{
for(int p = 1; p <= 6; p++)
{
set_block_phase(p);
//What's going on with this math, explination:
// The get_speed will return an int 0-100
// We want the minimum speed to be 1 sec per phase
// we want the maximum speed to be 2800 us per phase
// the max speed corresponds to 5 rev/sec
// we know we need to go faster but this is just testing
volatile int myDelay = 1500 + (get_speed() * 300);
// Serial.println("my delay:");
// Serial.println(myDelay);
// Serial.println("my speed:");
// Serial.println(get_speed());
delayMicroseconds(myDelay);
}
}
}
void debug_motor(void) {
while(1)
{
......
......@@ -5,6 +5,7 @@ void motor_setup(void);
void turn_all_off();
void set_block_phase(int phase);
void debug_motor(void);
void open_loop_control(void);
void set_phase(int high1, int high2, int high3, int low1, int low2, int low3);
......
......@@ -21,15 +21,25 @@ void block_until_spacebar(void)
}
}
//reads potentiometer on pin A1 and scales it 0-100
int get_speed(void)
{
volatile float potval = analogRead(A1);
potval = potval/1024;
potval = 1 - potval;
potval = potval * 100;
return (int)potval; //read from pot
}
// returns 1 if user sends space bar
// returns 2 if user sends 'z'
int get_input(void)
int get_input(char * prompt)
{
short incomingByte = 0;
while(1)
{
Serial.println("SPACE TO START CALIBRATION, Z TO GET HARDCODED OFFSET");
Serial.println(prompt);
delay(200); // do not go too fast!
if (Serial.available()) {
incomingByte = Serial.read();
......@@ -42,6 +52,10 @@ int get_input(void)
{
return 2;
}
else if(incomingByte == 111)
{
return 3;
}
}
}
......
......@@ -2,8 +2,10 @@
#define UTILS_H_
void block_until_spacebar(void);
int get_input(void);
int get_input(char * prompt);
void do_hard_coded_offset(void);
int get_speed(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