Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
Ardupilot
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
OpenSource
Ardupilot
Commits
bd8534ef
Commit
bd8534ef
authored
13 years ago
by
rmackay9
Browse files
Options
Downloads
Patches
Plain Diff
ArduCopter - Attitude.pde - added logging of optical flow pid controller
parent
53ddb58c
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
ArduCopter/Attitude.pde
+42
-2
42 additions, 2 deletions
ArduCopter/Attitude.pde
with
42 additions
and
2 deletions
ArduCopter/Attitude.pde
+
42
−
2
View file @
bd8534ef
...
@@ -586,9 +586,11 @@ static int32_t
...
@@ -586,9 +586,11 @@ static int32_t
get_of_roll
(
int32_t
control_roll
)
get_of_roll
(
int32_t
control_roll
)
{
{
#ifdef OPTFLOW_ENABLED
#ifdef OPTFLOW_ENABLED
static
int8_t
log_counter
=
0
;
// used to slow down logging of PID values to dataflash
static
float
tot_x_cm
=
0
;
// total distance from target
static
float
tot_x_cm
=
0
;
// total distance from target
static
uint32_t
last_of_roll_update
=
0
;
static
uint32_t
last_of_roll_update
=
0
;
int32_t
new_roll
=
0
;
int32_t
new_roll
=
0
;
int32_t
p
,
i
,
d
;
// check if new optflow data available
// check if new optflow data available
if
(
optflow
.
last_update
!=
last_of_roll_update
)
{
if
(
optflow
.
last_update
!=
last_of_roll_update
)
{
...
@@ -599,17 +601,35 @@ get_of_roll(int32_t control_roll)
...
@@ -599,17 +601,35 @@ get_of_roll(int32_t control_roll)
// only stop roll if caller isn't modifying roll
// only stop roll if caller isn't modifying roll
if
(
control_roll
==
0
&&
current_loc
.
alt
<
1500
)
{
if
(
control_roll
==
0
&&
current_loc
.
alt
<
1500
)
{
new_roll
=
g
.
pid_optflow_roll
.
get_pid
(
-
tot_x_cm
,
1.0
);
// we could use the last update time to calculate the time change
p
=
g
.
pid_optflow_roll
.
get_p
(
-
tot_x_cm
);
i
=
g
.
pid_optflow_roll
.
get_i
(
-
tot_x_cm
,
1.0
);
// we could use the last update time to calculate the time change
d
=
g
.
pid_optflow_roll
.
get_d
(
-
tot_x_cm
,
1.0
);
new_roll
=
p
+
i
+
d
;
}
else
{
}
else
{
g
.
pid_optflow_roll
.
reset_I
();
g
.
pid_optflow_roll
.
reset_I
();
tot_x_cm
=
0
;
tot_x_cm
=
0
;
p
=
0
;
// for logging
i
=
0
;
d
=
0
;
}
}
// limit amount of change and maximum angle
// limit amount of change and maximum angle
of_roll
=
constrain
(
new_roll
,
(
of_roll
-
20
),
(
of_roll
+
20
));
of_roll
=
constrain
(
new_roll
,
(
of_roll
-
20
),
(
of_roll
+
20
));
#if LOGGING_ENABLED == ENABLED
// log output if PID logging is on and we are tuning the rate P, I or D gains
if
(
g
.
log_bitmask
&
MASK_LOG_PID
&&
(
g
.
radio_tuning
==
CH6_OPTFLOW_KP
||
g
.
radio_tuning
==
CH6_OPTFLOW_KI
||
g
.
radio_tuning
==
CH6_OPTFLOW_KD
)
)
{
log_counter
++
;
if
(
log_counter
>=
5
)
{
// (update rate / desired output rate) = (100hz / 10hz) = 10
log_counter
=
0
;
Log_Write_PID
(
CH6_OPTFLOW_KP
,
tot_x_cm
,
p
,
i
,
d
,
of_roll
,
tuning_value
);
}
}
#endif // LOGGING_ENABLED == ENABLED
}
}
// limit max angle
// limit max angle
of_roll
=
constrain
(
of_roll
,
-
1000
,
1000
);
of_roll
=
constrain
(
of_roll
,
-
1000
,
1000
);
return
control_roll
+
of_roll
;
return
control_roll
+
of_roll
;
#else
#else
return
control_roll
;
return
control_roll
;
...
@@ -620,9 +640,11 @@ static int32_t
...
@@ -620,9 +640,11 @@ static int32_t
get_of_pitch
(
int32_t
control_pitch
)
get_of_pitch
(
int32_t
control_pitch
)
{
{
#ifdef OPTFLOW_ENABLED
#ifdef OPTFLOW_ENABLED
static
int8_t
log_counter
=
0
;
// used to slow down logging of PID values to dataflash
static
float
tot_y_cm
=
0
;
// total distance from target
static
float
tot_y_cm
=
0
;
// total distance from target
static
uint32_t
last_of_pitch_update
=
0
;
static
uint32_t
last_of_pitch_update
=
0
;
int32_t
new_pitch
=
0
;
int32_t
new_pitch
=
0
;
int32_t
p
,
i
,
d
;
// check if new optflow data available
// check if new optflow data available
if
(
optflow
.
last_update
!=
last_of_pitch_update
)
{
if
(
optflow
.
last_update
!=
last_of_pitch_update
)
{
...
@@ -633,18 +655,36 @@ get_of_pitch(int32_t control_pitch)
...
@@ -633,18 +655,36 @@ get_of_pitch(int32_t control_pitch)
// only stop roll if caller isn't modifying pitch
// only stop roll if caller isn't modifying pitch
if
(
control_pitch
==
0
&&
current_loc
.
alt
<
1500
)
{
if
(
control_pitch
==
0
&&
current_loc
.
alt
<
1500
)
{
new_pitch
=
g
.
pid_optflow_pitch
.
get_pid
(
tot_y_cm
,
1.0
);
// we could use the last update time to calculate the time change
p
=
g
.
pid_optflow_pitch
.
get_p
(
tot_y_cm
);
i
=
g
.
pid_optflow_pitch
.
get_i
(
tot_y_cm
,
1.0
);
// we could use the last update time to calculate the time change
d
=
g
.
pid_optflow_pitch
.
get_d
(
tot_y_cm
,
1.0
);
new_pitch
=
p
+
i
+
d
;
}
else
{
}
else
{
tot_y_cm
=
0
;
tot_y_cm
=
0
;
g
.
pid_optflow_pitch
.
reset_I
();
g
.
pid_optflow_pitch
.
reset_I
();
p
=
0
;
// for logging
i
=
0
;
d
=
0
;
}
}
// limit amount of change
// limit amount of change
of_pitch
=
constrain
(
new_pitch
,
(
of_pitch
-
20
),
(
of_pitch
+
20
));
of_pitch
=
constrain
(
new_pitch
,
(
of_pitch
-
20
),
(
of_pitch
+
20
));
#if LOGGING_ENABLED == ENABLED
// log output if PID logging is on and we are tuning the rate P, I or D gains
if
(
g
.
log_bitmask
&
MASK_LOG_PID
&&
(
g
.
radio_tuning
==
CH6_OPTFLOW_KP
||
g
.
radio_tuning
==
CH6_OPTFLOW_KI
||
g
.
radio_tuning
==
CH6_OPTFLOW_KD
)
)
{
log_counter
++
;
if
(
log_counter
>=
5
)
{
// (update rate / desired output rate) = (100hz / 10hz) = 10
log_counter
=
0
;
Log_Write_PID
(
CH6_OPTFLOW_KP
+
100
,
tot_y_cm
,
p
,
i
,
d
,
of_pitch
,
tuning_value
);
}
}
#endif // LOGGING_ENABLED == ENABLED
}
}
// limit max angle
// limit max angle
of_pitch
=
constrain
(
of_pitch
,
-
1000
,
1000
);
of_pitch
=
constrain
(
of_pitch
,
-
1000
,
1000
);
return
control_pitch
+
of_pitch
;
return
control_pitch
+
of_pitch
;
#else
#else
return
control_pitch
;
return
control_pitch
;
...
...
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