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
2ba86a7a
Commit
2ba86a7a
authored
Apr 05, 2019
by
mattdr
Browse files
all of the work days changes and the added late night big changes
parent
13032120
Changes
6
Hide whitespace changes
Inline
Side-by-side
source_code/Teensy35/.vscode/ipch/6ee1ab8fb45e6d3b/WIRISH.ipch
0 → 100644
View file @
2ba86a7a
File added
source_code/Teensy35/.vscode/ipch/6ee1ab8fb45e6d3b/mmap_address.bin
0 → 100644
View file @
2ba86a7a
File added
source_code/Teensy35/.vscode/ipch/925c5bf3f99f0c62/PINS_TEENSY.ipch
0 → 100644
View file @
2ba86a7a
File added
source_code/Teensy35/.vscode/ipch/925c5bf3f99f0c62/mmap_address.bin
0 → 100644
View file @
2ba86a7a
File added
source_code/Teensy35/src/motor_ctrl.cpp
View file @
2ba86a7a
...
...
@@ -16,11 +16,14 @@
// TODO: #define coast <available pin>
const
int
sleep_time
=
30
;
// every sleep_time code cycles, turn everything off just to discharge
// #define HB1EN 0 //halfbridge 1 enable
// #define HB2EN 1 //halfbridge 2 enable
// #define HB3EN 2 //halfbridge 3 enable
const
int
led
=
13
;
const
int
time_led
=
1
;
// This scale factor scales the potentiometer
int
const
SCALE_FACTOR
=
240
;
...
...
@@ -88,6 +91,9 @@ void motor_setup(void) {
pinMode
(
led
,
OUTPUT
);
digitalWrite
(
led
,
HIGH
);
pinMode
(
time_led
,
OUTPUT
);
digitalWrite
(
time_led
,
LOW
);
//setup the pot_0_timer and the coast_timer to run thirty times a second
pot_0_timer
.
begin
(
pot_0_speed_ISR
,
33333
);
}
...
...
@@ -196,6 +202,35 @@ void set_phase(int high1, int high2, int high3, int low1, int low2, int low3)
void
set_phase_float
(
float
f1
,
float
f2
,
float
f3
)
{
//YOU MUST SLOW DOWN THIS CODE TO MATCH YOUR FREQ or be slower
static
int
last_f1i
=
0
;
static
int
last_f2i
=
0
;
static
int
last_f3i
=
0
;
// static int sleep_counter = 0;
// if (sleep_counter >= sleep_time)
// {
// sleep_counter = 0;
// // now we want to turn everything off just for this cycle
// // analogWrite(H1, 0.0);
// // analogWrite(H2, 0.0);
// // analogWrite(H3, 0.0);
// digitalWrite(L1, 0);
// digitalWrite(L2, 0);
// digitalWrite(L3, 0);
// return;
// }
// sleep_counter++;
//deal with the potentiometer first
// NOTE: The scale factor of is the max value we want out of
// the potentiometer
...
...
@@ -214,29 +249,96 @@ void set_phase_float(float f1, float f2, float f3)
int
f2i
=
(
int
)
f2
;
int
f3i
=
(
int
)
f3
;
if
(
f1i
==
0
){
digitalWrite
(
L1
,
1
);
}
else
{
bool
f1_is_transient
=
false
;
bool
f2_is_transient
=
false
;
bool
f3_is_transient
=
false
;
// work with transient states
if
(
(
last_f1i
==
0
)
&&
(
f1i
!=
0
)
)
{
// f1 used to have low side on now has high side on
// turn off f1 low side first then do f1s high side
digitalWrite
(
L1
,
0
);
analogWrite
(
H1
,
f1i
);
f1_is_transient
=
true
;
}
analogWrite
(
H1
,
f1i
);
if
(
f2i
==
0
){
digitalWrite
(
L2
,
1
);
else
if
(
(
last_f1i
!=
0
)
&&
(
f1i
==
0
)
){
//f1 used to have high side running now has low side on
// turn off the high side first then do f1s low side
analogWrite
(
H1
,
0
);
digitalWrite
(
L1
,
1
);
f1_is_transient
=
true
;
}
else
{
if
(
(
last_f2i
==
0
)
&&
(
f2i
!=
0
)
)
{
// f2 used to have low side on now has high side on
// turn off f2 low side first then do f2s high side
digitalWrite
(
L2
,
0
);
analogWrite
(
H2
,
f2i
);
f2_is_transient
=
true
;
}
else
if
(
(
last_f2i
!=
0
)
&&
(
f2i
==
0
)
){
//f2 used to have high side running now has low side on
// turn off the high side first then do f2s low side
analogWrite
(
H2
,
0
);
digitalWrite
(
L2
,
1
);
f2_is_transient
=
true
;
}
analogWrite
(
H2
,
f2i
);
if
(
f3i
==
0
){
if
(
(
last_f3i
==
0
)
&&
(
f3i
!=
0
)
)
{
// f3 used to have low side on now has high side on
// turn off f3 low side first then do f3s high side
digitalWrite
(
L3
,
0
);
analogWrite
(
H3
,
f3i
);
f3_is_transient
=
true
;
}
else
if
(
(
last_f3i
!=
0
)
&&
(
f3i
==
0
)
){
//f3 used to have high side running now has low side on
// turn off the high side first then do f3s low side
analogWrite
(
H3
,
0
);
digitalWrite
(
L3
,
1
);
f3_is_transient
=
true
;
}
else
{
digitalWrite
(
L3
,
0
);
if
(
!
f1_is_transient
){
if
(
f1i
==
0
){
digitalWrite
(
L1
,
1
);
}
else
{
digitalWrite
(
L1
,
0
);
}
analogWrite
(
H1
,
f1i
);
}
if
(
!
f2_is_transient
){
if
(
f2i
==
0
){
digitalWrite
(
L2
,
1
);
}
else
{
digitalWrite
(
L2
,
0
);
}
analogWrite
(
H2
,
f2i
);
}
if
(
!
f3_is_transient
){
if
(
f3i
==
0
){
digitalWrite
(
L3
,
1
);
}
else
{
digitalWrite
(
L3
,
0
);
}
analogWrite
(
H3
,
f3i
);
}
analogWrite
(
H3
,
f3i
);
last_f1i
=
f1i
;
last_f2i
=
f2i
;
last_f3i
=
f3i
;
}
void
motor_butt_control_inefficient
(
void
)
...
...
@@ -246,6 +348,7 @@ void motor_butt_control_inefficient(void)
while
(
1
)
{
int
position
=
get_wheel_position_ticks
();
float
n
=
(
position
/
8192
)
*
12
*
2
*
pi
;
n
+=
5
*
(
pi
/
3
);
...
...
@@ -268,6 +371,7 @@ void motor_butt_control_precalculated(void)
while
(
1
)
{
digitalWrite
(
time_led
,
HIGH
);
// get the current encoder tics (this does the math to offset)
int
position
=
get_wheel_position_ticks
();
// get position within current electrical revolution
...
...
@@ -277,6 +381,10 @@ void motor_butt_control_precalculated(void)
float
f3
=
C_SIN_FACTORS_SHIFTED
[
ele_position
];
set_phase_float
(
f1
,
f2
,
f3
);
digitalWrite
(
time_led
,
LOW
);
delayMicroseconds
(
42
);
// This was calculated to keep the code
// from running faster than the period
// of the high side freq
}
}
...
...
source_code/Teensy35/src/utils.cpp
View file @
2ba86a7a
...
...
@@ -5,7 +5,7 @@
float
CALIBRATION_MAX_PWM
=
100.0
;
const
float
UPWARD_ROC_LIMITER
=
2
0.0
;
const
float
UPWARD_ROC_LIMITER
=
1
0.0
;
float
UPWARD_ROC_PREV_VALUE
=
0
;
#define debugJumperOut 11
...
...
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