User Tools

Site Tools


darwin_walk_backward_with_cv

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
darwin_walk_backward_with_cv [2017/12/03 15:21] – [Programming] yuhanghedarwin_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. Even though BallFollower class will not directly work with walking backward, the basic algorithm used in that class is applicable to backward motion. 
 \\ \\  \\ \\ 
-There are 3 parameter in walking_tuner that cannot be saved: ''Step forward/back (mm), Step right/left (mm)and Step Direction (degree)''. Insteadthese variables should be updated constantly by your program during Darwin OP 2's walking process+In the algorithm, Darwin OP 2's head pan angle is set as process variable(PV). The head pan position at 0when 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 backward. Place both ''main.cpp'' and ''Makefile'' inside a new folder in directory **''robotisop2/Linux/project/tutorial/''**. Then, type ''make'' command to compile  executable and type ''./walk_backward'' to execute program. +Below is a demonstration of the algorithm combining with backward motion.
  
 <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;
 +//initialize 4 variables to be used in the algorithm. m_FollowMaxRLTurn is used to set the maximum right or 
 +//left turn amplitude. m_UnitRLTurn is used to set how much turn amplitude change at each iteration. 
 +//m_GoalRLTurn is calculated based on error. m_RLTurn is the output.
 +
 +_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::GetInstance()->IsRunning() == 0)             if(Action::GetInstance()->IsRunning() == 0)
Line 45: Line 50:
  
                 if(Walking::GetInstance()->IsRunning() == false){                 if(Walking::GetInstance()->IsRunning() == false){
-                Walking::GetInstance()->X_MOVE_AMPLITUDE = 30.0; +                Walking::GetInstance()->X_MOVE_AMPLITUDE = -15.0; 
-                Walking::GetInstance()->A_MOVE_AMPLITUDE = 4.0;+                Walking::GetInstance()->A_MOVE_AMPLITUDE = 0.0;
                 Walking::GetInstance()->Start();                 Walking::GetInstance()->Start();
                 }                 }
 +                //Enable motors and initialize backward motion
                                  
-                else if(_marker_found == 1 && _backpedal == 1)+                 
 +                if(_marker_found == 1)
                 {                 {
                     double pan = MotionStatus::m_CurrentJoints.GetAngle(JointData::ID_HEAD_PAN);                     double pan = MotionStatus::m_CurrentJoints.GetAngle(JointData::ID_HEAD_PAN);
 +                    //receiving pan angle of Darwin OP 2's head as process variable
 +                    
                     double pan_range = Head::GetInstance()->GetLeftLimitAngle();                     double pan_range = Head::GetInstance()->GetLeftLimitAngle();
                     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::GetInstance()->A_MOVE_AMPLITUDE = (m_RLTurn);+                    //to provide smoother transition while walking 
 +                     
 +                  Walking::GetInstance()->A_MOVE_AMPLITUDE = m_RLTurn; 
 +                    //A_MOVE_AMPLITUDE is set to the output of algorithm 
 +                    
                     Walking::GetInstance()->X_MOVE_AMPLITUDE = -15.0;                     Walking::GetInstance()->X_MOVE_AMPLITUDE = -15.0;
  
Line 72: Line 88:
                 }                 }
              }              }
- 
  
 </code> </code>
Line 80: Line 95:
 In this demonstration, I successfully compile and execute the above programs In this demonstration, I successfully compile and execute the above programs
  
-{{ youtube>GQ8AyZpQ9NU?large }} +{{ youtube>v8hwcmquTac?large }}  
  
 +{{ youtube>SHYVUATcH5I?large }} 
 ===== Final Words ===== ===== Final Words =====
  
-This tutorial's objective was to demonstrate how to program Darwin OP 2 to walk backward. +This tutorial's objective was to demonstrate how to program Darwin OP 2 to walk backward with CV
 \\ \\
 \\ \\
darwin_walk_backward_with_cv.txt · Last modified: 2017/12/03 18:23 by yuhanghe