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
6edd58f3
Verified
Commit
6edd58f3
authored
2 years ago
by
Thomas Lambert
Browse files
Options
Downloads
Patches
Plain Diff
feat: PSU sensor and angle calibration
parent
23183d32
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
+29
-12
29 additions, 12 deletions
controller/controller.ino
with
29 additions
and
12 deletions
controller/controller.ino
+
29
−
12
View file @
6edd58f3
...
@@ -35,22 +35,28 @@ Repo: https://gitlab.uliege.be/thlamb/mecharaptor-controller
...
@@ -35,22 +35,28 @@ Repo: https://gitlab.uliege.be/thlamb/mecharaptor-controller
#define CSN_PINS \
#define CSN_PINS \
{ 6, 5, 4, 3 } // Encoder Chip Select pins
{ 6, 5, 4, 3 } // Encoder Chip Select pins
#define CUR1_PIN A
1
// Current measurement for Front motor
#define CUR1_PIN A
4
// Current measurement for Front motor
#define CUR2_PIN A2 // Current measurement for Aft motor
#define CUR2_PIN A2 // Current measurement for Aft motor
#define TENS1_PIN A3 // Tension measurement for Front motor
#define TENS1_PIN A3 // Tension measurement for Front motor
#define TENS2_PIN A
4
// Tension measurement for Aft motor
#define TENS2_PIN A
1
// Tension measurement for Aft motor
// Values
// Values
#define DIV_RES1
90
00.0 // Resistance of R1 in the voltage dividers
#define DIV_RES1
478
00.0 // Resistance of R1 in the voltage dividers
#define DIV_RES2
10
00.0 // Resistance of R2 in the voltage dividers
#define DIV_RES2
68
00.0 // Resistance of R2 in the voltage dividers
#define SEN0098_VCC 5 // Supply voltage of the current sensors
#define SEN0098_VCC 5 // Supply voltage of the current sensors
#define SEN0098_SENSI 20.0 // [FIXME] VERIFY!
#define SEN0098_SENSI 20.0 // [FIXME] VERIFY!
#define SEN0098_VIOUT 0.12 // [FIXME] VERIFY!
#define SEN0098_VIOUT 0.12 // [FIXME] VERIFY!
#define SEN0098_OFFSET 0.007 // [FIXME] VERIFY!
#define SEN0098_OFFSET 0.007 // [FIXME] VERIFY!
#define GEAR_RATIO 0.1 // Gear ratio between motor and wings
#define GEAR_RATIO 0.1 // Gear ratio between motor and wings
// Calibration of encoders (NEEDS TO BE REDONE WHEN ENCODERS ARE MOVED)
#define ENC_PRECISION 4096 // 12-Bits encoders (nb of points per rot)
#define ENC_ORIENT {1, -1, 1, -1} // Encoder orientation
#define MAX_WING_POS {222.1, 117.77, 117, 117} // Maximum wing angle (returned by encoder value)
#define TRUE_MAX_ANGLE 37.9 // Maximum wing angle (measured on setup)
/*******************************************************************************
/*******************************************************************************
Globals (for things that I can change manually)
Globals (for things that I can change manually)
...
@@ -66,6 +72,8 @@ const uint8_t gMAX_ESC_VAL = 160; // Value at which motor is at max RPM
...
@@ -66,6 +72,8 @@ const uint8_t gMAX_ESC_VAL = 160; // Value at which motor is at max RPM
const
uint8_t
gMIN_ESC_VAL
=
40
;
// Min value for ESC to start motor (trial-error)
const
uint8_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
uint8_t
gCSN_PINS
[]
=
CSN_PINS
;
// Encoder Chip Select pins
const
int8_t
gENC_ORIENT
[]
=
ENC_ORIENT
;
// Encoder orientation
const
uint16_t
gMAX_WING_POS
[]
=
MAX_WING_POS
;
// Encoder maximum recorder position
const
float
gCUR_FACT
=
SEN0098_SENSI
/
1000.0
;
// Factor for current measurement
const
float
gCUR_FACT
=
SEN0098_SENSI
/
1000.0
;
// Factor for current measurement
const
float
gCUR_QOV
=
SEN0098_VIOUT
*
SEN0098_VCC
;
// [FIXME] Verify
const
float
gCUR_QOV
=
SEN0098_VIOUT
*
SEN0098_VCC
;
// [FIXME] Verify
...
@@ -75,6 +83,7 @@ Servo gEsc2; // ESC for aft motor
...
@@ -75,6 +83,7 @@ Servo gEsc2; // ESC for aft motor
uint8_t
gEsc_val
=
0
;
// ESC angle (to use with the Servo library) [0-180]
uint8_t
gEsc_val
=
0
;
// ESC angle (to use with the Servo library) [0-180]
String
gMode
;
// Mode of operation
String
gMode
;
// Mode of operation
uint16_t
max_wing_pos
[
4
];
// Encoder maximum recorder position
/*******************************************************************************
/*******************************************************************************
...
@@ -134,7 +143,7 @@ void setup() {
...
@@ -134,7 +143,7 @@ void setup() {
void
loop
()
{
void
loop
()
{
int
potent
=
analogRead
(
POT_PIN
);
// Potentiometer value
int
potent
=
analogRead
(
POT_PIN
);
// Potentiometer value
u
int16_
t
wing_angles
[
sizeof
(
gCSN_PINS
)];
// Wing angles (1L, 1R, 2L, 2R)
u
nsigned
in
t
wing_angles
[
sizeof
(
gCSN_PINS
)];
// Wing angles (1L, 1R, 2L, 2R)
if
(
gMode
==
"SERIAL"
and
Serial
.
available
())
{
if
(
gMode
==
"SERIAL"
and
Serial
.
available
())
{
...
@@ -155,7 +164,7 @@ void loop() {
...
@@ -155,7 +164,7 @@ void loop() {
// Read value from rotary encoders
// Read value from rotary encoders
for
(
int
i
=
0
;
i
<
sizeof
(
gCSN_PINS
);
i
++
)
{
for
(
int
i
=
0
;
i
<
sizeof
(
gCSN_PINS
);
i
++
)
{
wing_angles
[
i
]
=
ReadSensor
(
gCSN_PINS
[
i
]);
wing_angles
[
i
]
=
ReadSensor
(
gCSN_PINS
[
i
]
,
gENC_ORIENT
[
i
]
);
}
}
// Read tension and current from PSU
// Read tension and current from PSU
...
@@ -251,8 +260,8 @@ void StopMotor(int old_esc_val) {
...
@@ -251,8 +260,8 @@ void StopMotor(int old_esc_val) {
//Read 12-bit rotary encoder (RobinL modified by linarism on forum.arduino.cc)
//Read 12-bit rotary encoder (RobinL modified by linarism on forum.arduino.cc)
u
int16_
t
ReadSensor
(
uint8_t
csn
)
{
u
nsigned
in
t
ReadSensor
(
uint8_t
csn
,
int8_t
orient
)
{
u
int16_
t
ret
=
0
;
u
nsigned
in
t
ret
=
0
;
digitalWrite
(
csn
,
LOW
);
digitalWrite
(
csn
,
LOW
);
delayMicroseconds
(
1
);
//Waiting for Tclkfe
delayMicroseconds
(
1
);
//Waiting for Tclkfe
...
@@ -267,12 +276,12 @@ uint16_t ReadSensor(uint8_t csn) {
...
@@ -267,12 +276,12 @@ uint16_t ReadSensor(uint8_t csn) {
}
}
digitalWrite
(
csn
,
HIGH
);
//deselects the encoder from reading
digitalWrite
(
csn
,
HIGH
);
//deselects the encoder from reading
return
ret
;
return
(
1
-
orient
)
/
2
*
ENC_PRECISION
+
orient
*
ret
;
}
}
// Output data to use with serial-studio
// Output data to use with serial-studio
void
SerialPrint
(
String
mode
,
int
potent
,
int
esc_val
,
u
int16_
t
wing_angles
[],
float
psu_vol
[],
float
psu_cur
[])
{
void
SerialPrint
(
String
mode
,
int
potent
,
int
esc_val
,
u
nsigned
in
t
wing_angles
[],
float
psu_vol
[],
float
psu_cur
[])
{
float
freq
=
esc_val
*
(
RpmToFreq
(
gMAX_RPM
)
/
180.0
);
float
freq
=
esc_val
*
(
RpmToFreq
(
gMAX_RPM
)
/
180.0
);
...
@@ -288,7 +297,7 @@ void SerialPrint(String mode, int potent, int esc_val, uint16_t wing_angles[], f
...
@@ -288,7 +297,7 @@ void SerialPrint(String mode, int potent, int esc_val, uint16_t wing_angles[], f
Serial
.
print
(
freq
);
Serial
.
print
(
freq
);
for
(
int
i
=
0
;
i
<
sizeof
(
gCSN_PINS
);
i
++
)
{
for
(
int
i
=
0
;
i
<
sizeof
(
gCSN_PINS
);
i
++
)
{
Serial
.
print
(
","
);
Serial
.
print
(
","
);
Serial
.
print
(
wing_angles
[
i
]);
Serial
.
print
(
PosToDeg
(
wing_angles
[
i
])
-
gMAX_WING_POS
[
i
]
+
TRUE_MAX_ANGLE
)
;
}
}
for
(
int
i
=
0
;
i
<
sizeof
(
psu_vol
);
i
++
)
{
for
(
int
i
=
0
;
i
<
sizeof
(
psu_vol
);
i
++
)
{
Serial
.
print
(
","
);
Serial
.
print
(
","
);
...
@@ -317,7 +326,15 @@ float GetCurrent(byte cur_pin) {
...
@@ -317,7 +326,15 @@ float GetCurrent(byte cur_pin) {
// Measure the tension provided by the PSU
// Measure the tension provided by the PSU
float
GetTension
(
byte
vol_pin
)
{
float
GetTension
(
byte
vol_pin
)
{
in
t
vol_raw
=
analogRead
(
vol_pin
)
*
(
5.0
/
1023.0
);
floa
t
vol_raw
=
analogRead
(
vol_pin
)
*
(
5.0
/
1023.0
);
return
vol_raw
*
(
DIV_RES1
+
DIV_RES2
)
/
(
DIV_RES2
);
return
vol_raw
*
(
DIV_RES1
+
DIV_RES2
)
/
(
DIV_RES2
);
}
}
// Convert encoder position to degree
float
PosToDeg
(
unsigned
int
pos
){
return
pos
*
360.0
/
ENC_PRECISION
;
}
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