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
5d05a3c8
Verified
Commit
5d05a3c8
authored
2 years ago
by
Thomas Lambert
Browse files
Options
Downloads
Patches
Plain Diff
refact: reorder stuff, better names
parent
d643cd9d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
controller/controller.ino
+21
-18
21 additions, 18 deletions
controller/controller.ino
with
21 additions
and
18 deletions
controller/controller.ino
+
21
−
18
View file @
5d05a3c8
...
...
@@ -32,7 +32,8 @@ Repo: https://gitlab.uliege.be/thlamb/mecharaptor-controller
#define CLK_PIN 2 // Encoder CLK
#define DO_PIN 8 // Encoder Digital Output
#define CSN_PINS { 3, 4, 5, 6 } // Encoder Chip Select pins
#define CSN_PINS \
{ 3, 4, 5, 6 } // Encoder Chip Select pins
#define CUR1_PIN A1 // Current measurement for Front motor
#define CUR2_PIN A2 // Current measurement for Aft motor
...
...
@@ -43,10 +44,10 @@ Repo: https://gitlab.uliege.be/thlamb/mecharaptor-controller
#define DIV_RES1 9000.0 // Resistance of R1 in the voltage dividers
#define DIV_RES2 1000.0 // Resistance of R2 in the voltage dividers
#define SEN0098_VCC 5 // Supply voltage of the current sensors
#define SEN0098_SENSI 20.0 // [FIXME] VERIFY!
#define SEN0098_VIOUT 0.12 // [FIXME] VERIFY!
#define SEN0098_OFFSET 0.
12
// [FIXME] VERIFY!
#define SEN0098_VCC 5
// Supply voltage of the current sensors
#define SEN0098_SENSI 20.0
// [FIXME] VERIFY!
#define SEN0098_VIOUT 0.12
// [FIXME] VERIFY!
#define SEN0098_OFFSET 0.
007
// [FIXME] VERIFY!
#define GEAR_RATIO 0.1 // Gear ratio between motor and wings
...
...
@@ -159,8 +160,8 @@ void loop() {
// Read current and power
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
]);
GetPsu
(
TENS1_PIN
,
CUR1_PIN
,
psu_vol
[
0
],
psu_cur
[
0
]);
GetPsu
(
TENS2_PIN
,
CUR2_PIN
,
psu_vol
[
1
],
psu_cur
[
1
]);
SerialPrint
(
gMode
,
potent
,
gEsc_val
,
wing_angles
,
psu_vol
,
psu_cur
);
}
...
...
@@ -271,7 +272,9 @@ 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
)
/
100.0
;
Serial
.
print
(
"/*"
);
...
...
@@ -283,7 +286,7 @@ void SerialPrint(String mode, int potent, int esc_val, unsigned int wing_angles[
Serial
.
print
(
","
);
Serial
.
print
(
esc_val
);
Serial
.
print
(
","
);
Serial
.
print
(
freq
);
// [FIXME] Is it useful?
Serial
.
print
(
freq
);
for
(
int
i
=
0
;
i
<
sizeof
(
gCSN_PINS
);
i
++
)
{
Serial
.
print
(
","
);
Serial
.
print
(
wing_angles
[
i
]);
...
...
@@ -297,12 +300,19 @@ void SerialPrint(String mode, int potent, int esc_val, unsigned int wing_angles[
Serial
.
println
(
"*/"
);
}
// Get the tension and current of a PSU
void
GetPsu
(
byte
vol_pin
,
byte
cur_pin
,
float
&
vol
,
float
&
cur
)
{
vol
=
GetTension
(
vol_pin
);
cur
=
GetCurrent
(
cur_pin
);
}
// Measure current consumed by module
float
GetCurrent
(
byte
cur_pin
)
{
float
cur
_raw
=
(
5.0
/
1023.0
)
*
analogRead
(
cur_pin
);
float
volt
_raw
=
(
5.0
/
1023.0
)
*
analogRead
(
cur_pin
);
float
cur
=
cur
_raw
*
-
gCUR_QOV
+
0.007
;
//Trimming vale to make current equal to 0 when no current
return
cur
/
gCUR_FACT
;
// get a
ctual current
float
volt
=
volt
_raw
*
-
gCUR_QOV
+
SEN0098_OFFSET
;
//
Trimming val
u
e to make current equal to 0 when no current
return
volt
/
gCUR_FACT
;
// A
ctual current
}
// Measure the tension provided by the PSU
...
...
@@ -311,10 +321,3 @@ float GetTension(byte vol_pin) {
return
vol_raw
*
(
DIV_RES1
+
DIV_RES2
)
/
(
DIV_RES2
);
}
// Get the tension and current of a PSU
void
GetPsu
(
byte
vol_pin
,
byte
cur_pin
,
float
&
vol
,
float
&
cur
)
{
vol
=
GetTension
(
vol_pin
);
cur
=
GetCurrent
(
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