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/11/27 08:18] – yuhanghe | darwin_walk_backward_with_cv [2017/12/03 18:23] (current) – [Demonstration] yuhanghe | ||
---|---|---|---|
Line 29: | Line 29: | ||
===== Programming ===== | ===== Programming ===== | ||
- | Darwin OP 2's Walking | + | The BallFollower |
\\ \\ | \\ \\ | ||
- | 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> | ||
- | #include <stdio.h> | + | int m_FollowMaxRLTurn = 35.0, m_UnitRLTurn |
- | #include < | + | //initialize 4 variables to be used in the algorithm. m_FollowMaxRLTurn is used to set the maximum right or |
- | #include < | + | //left turn amplitude. m_UnitRLTurn is used to set how much turn amplitude change at each iteration. |
- | #include < | + | //m_GoalRLTurn is calculated based on error. m_RLTurn is the output. |
- | #include " | + | |
- | + | ||
- | #define INI_FILE_PATH | + | |
- | #define U2D_DEV_NAME | + | |
- | + | ||
- | using namespace Robot; | + | |
- | + | ||
- | + | ||
- | void change_current_dir() | + | |
- | { | + | |
- | char exepath[1024] = {0}; | + | |
- | if(readlink("/ | + | |
- | chdir(dirname(exepath)); | + | |
- | } | + | |
- | + | ||
- | int main(void) | + | |
- | { | + | |
- | printf( "\n===== Walk Backward Tutorial for DARwIn =====\n\n" | + | |
- | + | ||
- | change_current_dir(); | + | |
- | + | ||
- | minIni* ini = new minIni(INI_FILE_PATH); | + | |
- | + | ||
- | //////////////////// | + | |
- | LinuxCM730 linux_cm730(U2D_DEV_NAME); | + | |
- | CM730 cm730(& | + | |
- | if(MotionManager:: | + | |
- | { | + | |
- | printf(" | + | |
- | return | + | |
- | } | + | |
- | //Port initialization and opening, dynamixel power on | + | |
- | + | ||
- | MotionManager:: | + | |
- | Walking:: | + | |
- | //Load default settings for MotionManager and Walking module | + | |
- | + | ||
- | MotionManager:: | + | |
- | MotionManager:: | + | |
- | LinuxMotionTimer *motion_timer | + | |
- | | + | |
- | | + | |
- | ///////////////////////////////////////////////////////////////////// | + | |
- | + | ||
- | ///////////////////////// | + | |
- | int n = 0; | + | |
- | int param[JointData:: | + | |
- | int wGoalPosition, | + | |
- | + | ||
- | for(int id=JointData:: | + | |
- | { | + | |
- | wStartPosition = MotionStatus:: | + | |
- | wGoalPosition = Walking:: | + | |
- | if( wStartPosition > wGoalPosition ) | + | |
- | wDistance = wStartPosition - wGoalPosition; | + | |
- | else | + | |
- | wDistance = wGoalPosition - wStartPosition; | + | |
- | + | ||
- | wDistance >>= 2; | + | |
- | if( wDistance < 8 ) | + | |
- | wDistance = 8; | + | |
- | + | ||
- | param[n++] = id; | + | |
- | param[n++] = CM730:: | + | |
- | param[n++] = CM730:: | + | |
- | param[n++] = CM730:: | + | |
- | param[n++] = CM730:: | + | |
- | } | + | |
- | cm730.SyncWrite(MX28:: | + | |
- | //Capture initial position of Darwin OP 2's motor position | + | |
- | + | ||
- | printf(" | + | |
- | getchar(); | + | |
- | + | ||
- | Head:: | + | |
- | Walking:: | + | |
- | MotionManager:: | + | |
- | //Walking and MotionManager enable motors | + | |
- | while(1) | + | _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. |
- | | + | |
{ | { | ||
Head:: | Head:: | ||
Line 130: | Line 51: | ||
if(Walking:: | if(Walking:: | ||
Walking:: | Walking:: | ||
- | // | ||
- | //each unit corresponds to approximately 1 mm. Set X_MOVE_AMPLITUDE to negative numbers to program | ||
- | //Darwin OP 2 to walk backwards. The Walking class calculates corresponding motor positions | ||
- | // | ||
- | | ||
Walking:: | Walking:: | ||
- | // | ||
- | //unit correspond approximately to 1 degree. Positive degrees for Darwin OP 2 to turn | ||
- | // | ||
- | | ||
Walking:: | Walking:: | ||
- | //Start walking algorithm | ||
} | } | ||
- | + | //Enable motors and initialize backward motion | |
- | Walking:: | + | |
- | Walking:: | + | |
| | ||
- | } | + | |
+ | if(_marker_found == 1) | ||
+ | { | ||
+ | double pan = MotionStatus:: | ||
+ | //receiving pan angle of Darwin OP 2's head as process variable | ||
+ | |||
+ | double pan_range = Head:: | ||
+ | double pan_percent = pan / pan_range; | ||
+ | //Calculate the error as a percentage | ||
- | | + | m_GoalRLTurn = m_FollowMaxRLTurn * pan_percent; |
+ | //Convert error percentage to changes in control variable | ||
+ | |||
+ | if(m_RLTurn < m_GoalRLTurn) | ||
+ | m_RLTurn += m_UnitRLTurn; | ||
+ | else if(m_RLTurn > m_GoalRLTurn) | ||
+ | m_RLTurn -= m_UnitRLTurn; | ||
+ | //Instead of directly setting control variable as output, the algorithm use incremental changes | ||
+ | //to provide smoother transition while walking | ||
+ | |||
+ | Walking:: | ||
+ | // | ||
+ | |||
+ | Walking:: | ||
+ | |||
+ | } | ||
+ | else | ||
+ | { | ||
+ | Walking:: | ||
+ | Walking:: | ||
+ | } | ||
+ | } | ||
- | return 0; | ||
- | } | ||
</ | </ | ||
- | <code make | Makefile> | ||
- | |||
- | TARGET = walk_backward | ||
- | |||
- | INCLUDE_DIRS = -I../ | ||
- | |||
- | CXX = g++ | ||
- | CXXFLAGS += -O2 -DLINUX -Wall $(INCLUDE_DIRS) | ||
- | #CXXFLAGS += -O2 -DDEBUG -DLINUX -Wall $(INCLUDE_DIRS) | ||
- | LFLAGS += -lpthread -ljpeg -lrt | ||
- | |||
- | OBJECTS = | ||
- | |||
- | all: $(TARGET) | ||
- | |||
- | clean: | ||
- | rm -f *.a *.o $(TARGET) core *~ *.so *.lo | ||
- | |||
- | libclean: | ||
- | make -C ../ | ||
- | |||
- | distclean: clean libclean | ||
- | |||
- | darwin.a: | ||
- | make -C ../ | ||
- | |||
- | $(TARGET): darwin.a $(OBJECTS) | ||
- | $(CXX) $(CFLAGS) $(OBJECTS) ../ | ||
- | chmod 755 $(TARGET) | ||
- | |||
- | # useful to make a backup "make tgz" | ||
- | tgz: clean | ||
- | mkdir -p backups | ||
- | tar czvf ./ | ||
- | </ | ||
===== Demonstration ===== | ===== Demonstration ===== | ||
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.1511799488.txt.gz · Last modified: 2017/11/27 08:18 by yuhanghe