darwin_walk_backward_with_cv
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
darwin_walk_backward_with_cv [2017/12/03 15:21] – [Programming] yuhanghe | darwin_walk_backward_with_cv [2017/12/03 18:23] (current) – [Demonstration] yuhanghe | ||
---|---|---|---|
Line 29: | Line 29: | ||
===== Programming ===== | ===== Programming ===== | ||
- | Even though BallFollower class will not directly work with walking backward, the basic algorithm used in the class is applicable to backward motion. | + | The BallFollower class use an algorithm that is similar to proportional controller to follow a target. |
\\ \\ | \\ \\ | ||
- | There are 3 parameter in walking_tuner that cannot be saved: | + | In the algorithm, Darwin OP 2's head pan angle is set as process variable(PV). The head pan position at 0, when Darwin OP 2 is facing directly forward, is set as setpoint(SP). The percentage difference between PV and SP is set as error. Finally, A_MOVE_AMPLITUDE is control variable(CV), output of algorithm. |
\\ \\ | \\ \\ | ||
- | Below is a sample program that demonstrates Darwin OP 2 walking | + | Below is a demonstration of the algorithm combining with backward |
<code cpp | main.cpp> | <code cpp | main.cpp> | ||
int m_FollowMaxRLTurn = 35.0, m_UnitRLTurn = 1.0, m_GoalRLTurn = 0, m_RLTurn = 0; | int m_FollowMaxRLTurn = 35.0, m_UnitRLTurn = 1.0, m_GoalRLTurn = 0, m_RLTurn = 0; | ||
+ | // | ||
+ | //left turn amplitude. m_UnitRLTurn is used to set how much turn amplitude change at each iteration. | ||
+ | // | ||
+ | |||
+ | _marker_found = marker_tracker.SearchAndTracking(center); | ||
+ | //The algorithm must work with BallTracker class since it depends on head's pan angle, which is used as PV. | ||
if(Action:: | if(Action:: | ||
Line 45: | Line 50: | ||
if(Walking:: | if(Walking:: | ||
- | Walking:: | + | Walking:: |
- | Walking:: | + | Walking:: |
Walking:: | Walking:: | ||
} | } | ||
+ | //Enable motors and initialize backward motion | ||
| | ||
- | | + | |
+ | | ||
{ | { | ||
double pan = MotionStatus:: | double pan = MotionStatus:: | ||
+ | //receiving pan angle of Darwin OP 2's head as process variable | ||
+ | | ||
double pan_range = Head:: | double pan_range = Head:: | ||
double pan_percent = pan / pan_range; | double pan_percent = pan / pan_range; | ||
+ | //Calculate the error as a percentage | ||
m_GoalRLTurn = m_FollowMaxRLTurn * pan_percent; | m_GoalRLTurn = m_FollowMaxRLTurn * pan_percent; | ||
+ | //Convert error percentage to changes in control variable | ||
+ | | ||
if(m_RLTurn < m_GoalRLTurn) | if(m_RLTurn < m_GoalRLTurn) | ||
m_RLTurn += m_UnitRLTurn; | m_RLTurn += m_UnitRLTurn; | ||
else if(m_RLTurn > m_GoalRLTurn) | else if(m_RLTurn > m_GoalRLTurn) | ||
m_RLTurn -= m_UnitRLTurn; | m_RLTurn -= m_UnitRLTurn; | ||
- | + | //Instead of directly setting control variable as output, the algorithm use incremental changes | |
- | Walking:: | + | //to provide smoother transition while walking |
+ | | ||
+ | Walking:: | ||
+ | // | ||
+ | | ||
Walking:: | Walking:: | ||
Line 72: | Line 88: | ||
} | } | ||
} | } | ||
- | |||
</ | </ | ||
Line 80: | Line 95: | ||
In this demonstration, | In this demonstration, | ||
- | {{ youtube>GQ8AyZpQ9NU?large }} | + | {{ youtube>v8hwcmquTac?large }} |
+ | {{ youtube> | ||
===== Final Words ===== | ===== Final Words ===== | ||
- | This tutorial' | + | This tutorial' |
\\ | \\ | ||
\\ | \\ |
darwin_walk_backward_with_cv.txt · Last modified: 2017/12/03 18:23 by yuhanghe