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
058d5751
Commit
058d5751
authored
Mar 26, 2019
by
thcl
Browse files
Added a skeleton for our coast button
parent
4b828896
Changes
2
Hide whitespace changes
Inline
Side-by-side
source_code/Teensy35/src/main.cpp
deleted
100644 → 0
View file @
4b828896
#include
<Arduino.h>
#include
"motor_ctrl.h"
#include
"encoder.h"
#include
"utils.h"
//BE AWARE COGGING POINTS MAY BE INBETWEEN STATES
//(THIS OFFSET MAY IMPACT THE HARD CODED POSITION)
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
// Hit 'z' to run get hard coded offset
char
prompt
[]
=
(
"\
SPACE TO START CALIBRATION AND NORMAL OPERATIONS,
\n
\
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
\
S TO START BUTT CONTROL (OPTIMIZED)
\n\n
\
Y TO DEBUG LOW STATE BY STATE
\n
\
U TO DEBUG_POT_0_SCALED
\n
\
K TO DEBUG ENCODER
\n
\
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
())
{
incomingByte
=
Serial
.
read
();
}
if
(
incomingByte
==
' '
)
//space bar
{
break
;
}
else
if
(
incomingByte
==
'z'
)
//'z'
{
charge_bootstrap_capacitors
();
do_hard_coded_offset
();
// run the set zero
}
else
if
(
incomingByte
==
'o'
)
//'o'
{
charge_bootstrap_capacitors
();
open_loop_control
();
}
else
if
(
incomingByte
==
'l'
)
//'l'
{
charge_bootstrap_capacitors
();
locate_state_positions
();
}
else
if
(
incomingByte
==
'd'
)
//'d'
{
charge_bootstrap_capacitors
();
direct_position_control
();
}
else
if
(
incomingByte
==
'b'
)
//'b'
{
charge_bootstrap_capacitors
();
motor_butt_control_inefficient
();
}
else
if
(
incomingByte
==
's'
)
//'s'
{
charge_bootstrap_capacitors
();
motor_butt_control_precalculated
();
}
else
if
(
incomingByte
==
'y'
)
// 'y'
{
debug_low_state_by_state
();
}
else
if
(
incomingByte
==
'u'
)
//'u'
{
debug_pot_0_scaled
();
}
else
if
(
incomingByte
==
'k'
)
//'k'
{
debug_encoder
();
}
else
if
(
incomingByte
==
'h'
)
//'h'
{
debug_motor
();
}
}
charge_bootstrap_capacitors
();
int
calibration_return
=
calibrate_encoder
();
if
(
calibration_return
==
-
1
)
{
while
(
1
){
//error out
delay
(
900
);
Serial
.
println
(
"CALIBRATION FAILED, REBOOT"
);
}
}
Serial
.
println
(
"CALIBRATION COMPLETE"
);
return
;
}
void
loop
()
{
//hold on to the old phase number
static
int
last_phase
=
0
;
// 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
);
// get the phase number that corresponds to this ele position
int
phase
=
get_phase_number
(
ele_position
);
phase
=
(
phase
%
6
)
+
1
;
//if we have a new phase, set the new phase
set_block_phase
(
phase
);
}
source_code/Teensy35/src/motor_ctrl.cpp
View file @
058d5751
...
...
@@ -14,6 +14,8 @@
#define L2 20 //YellowL
#define L3 22 //BlueL
// TODO: #define coast <available pin>
// #define HB1EN 0 //halfbridge 1 enable
// #define HB2EN 1 //halfbridge 2 enable
// #define HB3EN 2 //halfbridge 3 enable
...
...
@@ -86,7 +88,7 @@ void motor_setup(void) {
pinMode
(
led
,
OUTPUT
);
digitalWrite
(
led
,
HIGH
);
//setup the pot_0_timer to run
every
thirty times a second
//setup the pot_0_timer
and the coast_timer
to run thirty times a second
pot_0_timer
.
begin
(
pot_0_speed_ISR
,
33333
);
}
...
...
@@ -95,7 +97,11 @@ void pot_0_speed_ISR() {
// Serial.print("POT_VALUE: ");
// Serial.print(POT_0_VALUE);
// Serial.println();
// Serial.println()
// if(digitalRead(coast)) {
// POT_0_VALUE = 0;
// }
}
void
turn_all_off
()
{
...
...
Write
Preview
Supports
Markdown
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