Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MechaRaptor - Arduino Controller
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Aerospace and Mechanical Engineering
tlambert
MechaRaptor - Arduino Controller
Commits
9885ce91
Verified
Commit
9885ce91
authored
2 years ago
by
Thomas Lambert
Browse files
Options
Downloads
Patches
Plain Diff
perf: use precise types to reduce RAM, avoid map for floats
Signed-off-by:
Thomas Lambert
<
t.lambert@uliege.be
>
parent
5d05a3c8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CHANGELOG.md
+1
-0
1 addition, 0 deletions
CHANGELOG.md
controller/controller.ino
+18
-18
18 additions, 18 deletions
controller/controller.ino
with
19 additions
and
18 deletions
CHANGELOG.md
+
1
−
0
View file @
9885ce91
...
...
@@ -21,6 +21,7 @@ to [Semantic Versioning][sem_ver].
-
**Logging**
: Minor adaptations to serial-studio interface
-
**Logging**
: Output desired frequency as well
-
**All**
: Various refactoring and style improvements
-
**All**
: Use more precise types to limit RAM
### Deprecated
...
...
This diff is collapsed.
Click to expand it.
controller/controller.ino
+
18
−
18
View file @
9885ce91
...
...
@@ -57,23 +57,23 @@ Repo: https://gitlab.uliege.be/thlamb/mecharaptor-controller
*******************************************************************************/
// Constant values that can be tweaked here or in the ESC before run
const
int
gMAX_SIG
=
2000
;
// Max signal to the ESC [ms]
const
int
gMIN_SIG
=
1000
;
// Min signal to the ESC [ms]
const
u
int
16_t
gMAX_SIG
=
2000
;
// Max signal to the ESC [ms]
const
u
int
16_t
gMIN_SIG
=
1000
;
// Min signal to the ESC [ms]
const
int
gMAX_RPM
=
3000
;
// Motor maximum RPM (set in ESC)
const
int
gMIN_RPM
=
750
;
// Motor minimum RPM (set in ESC)
const
int
gMAX_ESC_VAL
=
160
;
// Value at which motor is at max RPM
const
int
gMIN_ESC_VAL
=
40
;
// Min value for ESC to start motor (trial-error)
const
u
int
16_t
gMAX_RPM
=
3000
;
// Motor maximum RPM (set in ESC)
const
u
int
16_t
gMIN_RPM
=
750
;
// Motor minimum RPM (set in ESC)
const
u
int
8_t
gMAX_ESC_VAL
=
160
;
// Value at which motor is at max RPM
const
u
int
8_t
gMIN_ESC_VAL
=
40
;
// Min value for ESC to start motor (trial-error)
const
uint8_t
gCSN_PINS
[]
=
CSN_PINS
;
// Encoder Chip Select pins
const
float
gCUR_FACT
=
SEN0098_SENSI
/
1000.0
;
// Factor for current measurement
const
float
gCUR_QOV
=
SEN0098_VIOUT
*
SEN0098_VCC
;
const
uint8_t
gCSN_PINS
[]
=
CSN_PINS
;
// Encoder Chip Select pins
const
float
gCUR_FACT
=
SEN0098_SENSI
/
1000.0
;
// Factor for current measurement
const
float
gCUR_QOV
=
SEN0098_VIOUT
*
SEN0098_VCC
;
// [FIXME] Verify
// Other
Servo
gEsc1
;
// ESC for front motor
Servo
gEsc2
;
// ESC for aft motor
int
gEsc_val
=
0
;
// ESC angle (to use with the Servo library) [0-180]
u
int
8_t
gEsc_val
=
0
;
// ESC angle (to use with the Servo library) [0-180]
String
gMode
;
// Mode of operation
...
...
@@ -158,11 +158,12 @@ void loop() {
wing_angles
[
i
]
=
ReadSensor
(
gCSN_PINS
[
i
]);
}
// Read
current and power
// Read
tension and current from PSU
float
psu_cur
[
2
],
psu_vol
[
2
];
GetPsu
(
TENS1_PIN
,
CUR1_PIN
,
psu_vol
[
0
],
psu_cur
[
0
]);
GetPsu
(
TENS2_PIN
,
CUR2_PIN
,
psu_vol
[
1
],
psu_cur
[
1
]);
// Output all to serial for treatment with serial-studio
SerialPrint
(
gMode
,
potent
,
gEsc_val
,
wing_angles
,
psu_vol
,
psu_cur
);
}
...
...
@@ -186,8 +187,7 @@ float SetupSerial() {
Serial
.
println
(
" [Hz]"
);
while
(
input
>
max_freq
or
input
<
min_freq
)
{
// Loop indefinitely while waiting for serial input
while
(
Serial
.
available
()
==
0
)
{}
while
(
Serial
.
available
()
==
0
)
{}
// Wait for serial input
input
=
Serial
.
parseFloat
();
if
(
input
>
max_freq
or
input
<
min_freq
)
{
...
...
@@ -211,7 +211,7 @@ float SetupSerial() {
int
FreqToEsc
(
float
freq
)
{
// Need to scale times 100 so we can have better precision
int
esc_val
=
map
(
freq
*
100
,
0
,
100
*
RpmToFreq
(
gMAX_RPM
)
,
0
,
180
);
int
esc_val
=
freq
*
(
180.0
/
RpmToFreq
(
gMAX_RPM
));
if
(
esc_val
<
gMIN_ESC_VAL
)
{
esc_val
=
gMIN_ESC_VAL
;
...
...
@@ -272,12 +272,11 @@ unsigned int ReadSensor(uint8_t csn) {
// Output data to use with serial-studio
// The /* and */ indicate beginning and end of stream data. Do not modify!
void
SerialPrint
(
String
mode
,
int
potent
,
int
esc_val
,
unsigned
int
wing_angles
[],
float
psu_vol
[],
float
psu_cur
[])
{
float
freq
=
map
(
esc_val
,
0
,
180
,
0
,
RpmToFreq
(
gMAX_RPM
)
*
100.0
)
/
1
0
0.0
;
float
freq
=
esc_val
*
(
RpmToFreq
(
gMAX_RPM
)
/
1
8
0.0
)
;
Serial
.
print
(
"/*"
);
Serial
.
print
(
"/*"
);
// Beginning of data stream
Serial
.
print
(
mode
);
Serial
.
print
(
","
);
Serial
.
print
(
millis
()
/
1000.0
);
...
...
@@ -297,7 +296,7 @@ void SerialPrint(String mode, int potent, int esc_val, unsigned int wing_angles[
Serial
.
print
(
","
);
Serial
.
print
(
psu_cur
[
i
]);
}
Serial
.
println
(
"*/"
);
Serial
.
println
(
"*/"
);
// End of data stream
}
...
...
@@ -308,6 +307,7 @@ void GetPsu(byte vol_pin, byte cur_pin, float &vol, float &cur) {
}
// Measure current consumed by module
// [FIXME] Check properly
float
GetCurrent
(
byte
cur_pin
)
{
float
volt_raw
=
(
5.0
/
1023.0
)
*
analogRead
(
cur_pin
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment