Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mattdr
supermileage_2018
Commits
939731a6
Commit
939731a6
authored
Dec 04, 2018
by
mattdr
Browse files
more work to get motor spinning in open loop
parent
e5afa2a7
Changes
5
Hide whitespace changes
Inline
Side-by-side
source_code/Teensy32/src/main.cpp
View file @
939731a6
...
...
@@ -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");
...
...
source_code/Teensy32/src/motor_ctrl.cpp
View file @
939731a6
#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
)
{
...
...
source_code/Teensy32/src/motor_ctrl.h
View file @
939731a6
...
...
@@ -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
);
...
...
source_code/Teensy32/src/utils.cpp
View file @
939731a6
...
...
@@ -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
;
}
}
}
...
...
source_code/Teensy32/src/utils.h
View file @
939731a6
...
...
@@ -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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment