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
a955f421
Commit
a955f421
authored
Mar 17, 2019
by
thcl
Browse files
Implemented Rate of Change Limiter in both directions.
parent
75d4c626
Changes
2
Hide whitespace changes
Inline
Side-by-side
source_code/Teensy35/src/motor_ctrl.cpp
View file @
a955f421
...
@@ -24,7 +24,7 @@ const int led = 13;
...
@@ -24,7 +24,7 @@ const int led = 13;
int
const
SCALE_FACTOR
=
240
;
int
const
SCALE_FACTOR
=
240
;
// This is the PWM frequency and it is very important
// This is the PWM frequency and it is very important
int
FREQ
=
8
000
;
//8000;
int
FREQ
=
22
000
;
//8000
was our original value
;
// This is the lower limit of PWM frequency
// This is the lower limit of PWM frequency
// its important for not breaking gate drivers
// its important for not breaking gate drivers
...
...
source_code/Teensy35/src/utils.cpp
View file @
a955f421
...
@@ -3,6 +3,9 @@
...
@@ -3,6 +3,9 @@
#include "motor_ctrl.h"
#include "motor_ctrl.h"
#include "encoder.h"
#include "encoder.h"
const
float
UPWARD_ROC_LIMITER
=
0.005
;
float
UPWARD_ROC_PREV_VALUE
=
0
;
//This function will just block until the user hits the space bar
//This function will just block until the user hits the space bar
void
block_until_spacebar
(
void
)
void
block_until_spacebar
(
void
)
{
{
...
@@ -39,6 +42,16 @@ int get_pot_0_scaled(int scaleFactor, float period_over_255)
...
@@ -39,6 +42,16 @@ int get_pot_0_scaled(int scaleFactor, float period_over_255)
{
{
volatile
float
raw_potval
=
analogRead
(
A0
);
volatile
float
raw_potval
=
analogRead
(
A0
);
float
potval
=
raw_potval
;
float
potval
=
raw_potval
;
if
((
potval
-
UPWARD_ROC_PREV_VALUE
)
>
UPWARD_ROC_LIMITER
)
{
potval
=
UPWARD_ROC_PREV_VALUE
+
UPWARD_ROC_LIMITER
;
}
else
if
((
potval
-
UPWARD_ROC_PREV_VALUE
)
<
UPWARD_ROC_LIMITER
)
{
potval
=
UPWARD_ROC_PREV_VALUE
-
UPWARD_ROC_LIMITER
;
}
UPWARD_ROC_PREV_VALUE
=
potval
;
potval
=
potval
/
1024
;
potval
=
potval
/
1024
;
potval
=
potval
*
scaleFactor
;
potval
=
potval
*
scaleFactor
;
...
@@ -54,11 +67,11 @@ int get_pot_0_scaled(int scaleFactor, float period_over_255)
...
@@ -54,11 +67,11 @@ int get_pot_0_scaled(int scaleFactor, float period_over_255)
}
}
//this just prints the output of get_pot_0_scaled
//this just prints the output of get_pot_0_scaled
int
debug_pot_0_scaled
(
void
)
int
debug_pot_0_scaled
()
{
{
while
(
1
){
while
(
1
){
Serial
.
println
(
"value from get_pot_0_scaled"
);
Serial
.
println
(
"value from get_pot_0_scaled"
);
Serial
.
println
(
get_pot_0_scaled
(
5
0
,
0.0000000817
));
Serial
.
println
(
get_pot_0_scaled
(
24
0
,
0.0000000817
));
delay
(
200
);
// do not go too fast!
delay
(
200
);
// do not go too fast!
}
}
...
@@ -66,9 +79,6 @@ int debug_pot_0_scaled(void)
...
@@ -66,9 +79,6 @@ int debug_pot_0_scaled(void)
}
}
// This function just rotates the motor to position CB, waits until
// This function just rotates the motor to position CB, waits until
// everything stops moving, takes a read of what the encoder has
// everything stops moving, takes a read of what the encoder has
// prints it to the command line and then turns everything off
// prints it to the command line and then turns everything off
...
@@ -126,6 +136,9 @@ void debug_low_state_by_state(void)
...
@@ -126,6 +136,9 @@ void debug_low_state_by_state(void)
Serial
.
println
(
"Hit space to call turn_all_off()"
);
Serial
.
println
(
"Hit space to call turn_all_off()"
);
block_until_spacebar
();
block_until_spacebar
();
turn_all_off
();
turn_all_off
();
Serial
.
println
(
"Hit space to call setphase(1,0,0,0,0,0"
);
block_until_spacebar
();
set_phase
(
1
,
0
,
0
,
0
,
0
,
0
);
Serial
.
println
(
"Hit space to call setphase(0,0,0,0,0,0)"
);
Serial
.
println
(
"Hit space to call setphase(0,0,0,0,0,0)"
);
block_until_spacebar
();
block_until_spacebar
();
set_phase
(
0
,
0
,
0
,
0
,
0
,
0
);
set_phase
(
0
,
0
,
0
,
0
,
0
,
0
);
...
...
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