This is an old revision of the document!
Table of Contents
Program Darwin OP 2 to Walk toward Target
Author: Yu Hang He Email: hey6@unlv.nevada.edu
Date: Last modified on <11/19/17>
Keywords: Darwin OP 2, C Programming, Robotis OP 2
This tutorial will demonstrate how to program Darwin to walk towards a target. The tutorial will incorporate materials from previous two sections: How to Add a New Mode to Darwin OP 2 and How to Use Darwin OP 2's Computer Vision. The target is consisted of two 20cm by 20cm panels, colored green and blue, perpendicular to each other. This tutorial take approximately 3 hours to complete.
Motivation and Audience
This tutorial's motivation is to demonstrate how to program Darwin OP 2 to walk toward a target. This tutorial assumes the reader has the following background and interests:
- Familiar with handling Darwin OP 2
- Familiar with C++/C programming language
- Familiar with C++/C codes on Darwin OP 2
The rest of this tutorial is presented as follows:
Programming
This tutorial will only demonstrate parts of program that needs modification to include a new mode.
- | StatusCheck.h
//Line 16 enum { INITIAL, READY, SOCCER, MOTION, VISION, SPRINT, //Add a new mode called "NEW_MODE" to an enumerated list of modes MAX_MODE };
- | StatusCheck.cpp
//At the end of if statement Line 141 if(m_old_btn & BTN_MODE) /////////////////////////// ////////////////////////// ////////////////////////// else if(m_cur_mode == SPRINT) //adding LED and play mp3 for new mode { cm730.WriteByte(CM730::P_LED_PANNEL, 0x01|0x04, NULL); //Signaling Darwin OP 2 which LED to turn on LinuxActionScript::PlayMP3("../../../Data/mp3/New_Mode mode.mp3"); //play an mp3 file (you can use any mp3 file but make sure file name matches) } } // Line 267 Add else if(m_cur_mode == SPRINT) { MotionManager::GetInstance()->Reinitialize(); MotionManager::GetInstance()->SetEnable(true); //initialize and enable MotionManager class m_is_started = 1; LinuxActionScript::PlayMP3("../../../Data/mp3/Start New_Mode demonstration.mp3"); //play an mp3 file (you can use any mp3 file but make sure file name matches) // Joint Enable... Action::GetInstance()->m_Joint.SetEnableBody(true, true); Action::GetInstance()->Start(9); while(Action::GetInstance()->IsRunning() == true) usleep(8000); Head::GetInstance()->m_Joint.SetEnableHeadOnly(true, true); Walking::GetInstance()->m_Joint.SetEnableBodyWithoutHead(true, true); //Reset Gyro sensor MotionManager::GetInstance()->ResetGyroCalibration(); while(1) { if(MotionManager::GetInstance()->GetCalibrationStatus() == 1) { LinuxActionScript::PlayMP3("../../../Data/mp3/Sensor calibration complete.mp3"); break; } else if(MotionManager::GetInstance()->GetCalibrationStatus() == -1) { LinuxActionScript::PlayMP3Wait("../../../Data/mp3/Sensor calibration fail.mp3"); MotionManager::GetInstance()->ResetGyroCalibration(); } usleep(8000); } //copied status check condition from soccer mode to new mode //These codes initialize Darwin OP 2 for movement and walking
- | main.cpp
//L317 Add case SPRINT: //implement new codes here to execute after pressing start button
Demonstration
In this demonstration, I created a new mode called Sprint mode following the previous step and successfully execute it on Darwin OP 2.
Final Words
This tutorial's objective was to demonstrate how to add a new mode to Darwin OP 2's demo program. Follow this tutorial to quickly implement and test new codes on Darwin OP 2.
For questions, clarifications, etc, Email: hey6@unlv.nevada.edu