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:46] – [Programming] yuhanghedarwin_walk_backward_with_cv [2017/12/03 18:23] (current) – [Demonstration] yuhanghe
Line 31: Line 31:
 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.  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. 
 \\ \\  \\ \\ 
-In the algorithm, Darwin OP 2's head pan position 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.+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 demonstration of the algorithm combining with backward motion. Below is a demonstration of the algorithm combining with backward motion.
Line 38: Line 38:
 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  //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+//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); _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 48: 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
 +                
                                  
                 if(_marker_found == 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  
 +                    //to provide smoother transition while walking 
 +                    
                   Walking::GetInstance()->A_MOVE_AMPLITUDE = m_RLTurn;                   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 75: Line 88:
                 }                 }
              }              }
- 
  
 </code> </code>
Line 83: 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.1512344799.txt.gz · Last modified: by yuhanghe