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
b6b28c47
Commit
b6b28c47
authored
Jan 30, 2019
by
mattdr
Browse files
made some code changes and moved to 3.5
parent
00015f86
Changes
5
Hide whitespace changes
Inline
Side-by-side
source_code/Teensy32/src/encoder.cpp
View file @
b6b28c47
...
...
@@ -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
=
32
1
;
int
hard_coded_offset
=
510
1
;
// how long in microsec (us) to delay between phases while calibrating
// the wheel
...
...
source_code/Teensy32/src/main.cpp
View file @
b6b28c47
...
...
@@ -38,30 +38,37 @@ S TO START BUTT CONTROL (OPTIMIZED)\n");
}
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
();
}
}
charge_bootstrap_capacitors
();
int
calibration_return
=
calibrate_encoder
();
if
(
calibration_return
==
-
1
)
{
...
...
source_code/Teensy32/src/motor_ctrl.cpp
View file @
b6b28c47
...
...
@@ -39,6 +39,7 @@ 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
);
void
charge_bootstrap_capacitors
(
void
);
...
...
@@ -127,19 +128,30 @@ void set_block_phase(int phase)
return
;
}
// This function takes in a seris of
// This function takes in a seris of
1 and 0s
void
set_phase
(
int
high1
,
int
high2
,
int
high3
,
int
low1
,
int
low2
,
int
low3
)
{
high1
=
one_to_scaleFactor
(
high1
);
high2
=
one_to_scaleFactor
(
high2
);
high3
=
one_to_scaleFactor
(
high3
);
digitalWrite
(
L1
,
low1
);
digitalWrite
(
L2
,
low2
);
digitalWrite
(
L3
,
low3
);
analogWrite
(
H1
,
high1
);
analogWrite
(
H2
,
high2
);
analogWrite
(
H3
,
high3
);
//turn the stuff that should be off, off first
if
(
!
low1
)
digitalWrite
(
L1
,
low1
);
if
(
!
low2
)
digitalWrite
(
L2
,
low2
);
if
(
!
low3
)
digitalWrite
(
L3
,
low3
);
if
(
!
high1
)
analogWrite
(
H1
,
high1
);
if
(
!
high2
)
analogWrite
(
H2
,
high2
);
if
(
!
high3
)
analogWrite
(
H3
,
high3
);
//turn the stuff that should be on, on
if
(
low1
)
digitalWrite
(
L1
,
low1
);
if
(
low2
)
digitalWrite
(
L2
,
low2
);
if
(
low3
)
digitalWrite
(
L3
,
low3
);
if
(
high1
)
analogWrite
(
H1
,
high1
);
if
(
high2
)
analogWrite
(
H2
,
high2
);
if
(
high3
)
analogWrite
(
H3
,
high3
);
}
void
set_phase_float
(
float
f1
,
float
f2
,
float
f3
)
...
...
@@ -246,6 +258,17 @@ void open_loop_control(void)
}
}
// This just charges up the small boostrap capacitors
// this should allways be called right before powering the motor
void
charge_bootstrap_capacitors
(
void
)
{
turn_all_off
();
delayMicroseconds
(
50
);
set_phase
(
0
,
0
,
0
,
1
,
1
,
1
);
delayMicroseconds
(
50
);
turn_all_off
();
}
//using hardcoded located state positions
void
direct_position_control
(
void
)
{
...
...
source_code/Teensy32/src/motor_ctrl.h
View file @
b6b28c47
...
...
@@ -10,6 +10,7 @@ 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
);
void
charge_bootstrap_capacitors
(
void
);
...
...
source_code/Teensy32/src/utils.cpp
View file @
b6b28c47
...
...
@@ -47,7 +47,7 @@ int get_pot_0_scaled(int scaleFactor, float period_over_255)
// This code is used to make sure that the pwm nver has a period
// lower than 250 ns (as this may be problematic for gate drivrs)
if
((
period_over_255
*
potval
)
<
250.0E-9
){
potval
=
0.
0
;
return
(
int
)
0
;
}
return
(
int
)
potval
;
...
...
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