¼«ºî ET¥í¥Ü¥³¥ó ¥·¥ß¥å¥ì¡¼¥¿ ¤Î³«È¯Æüµ ·ó ET¥í¥Ü¥³¥ó»²Àïµ ·ó È÷˺Ͽ
¡ÚÌÜŪ¡Û
¥¤¥ó¥¿¥Õ¥§¡¼¥¹¶¦Ä̲½¤Ë¤è¤êPC¾å¤ÇPathfinder¤ÎÁö¹Ô¥¢¥ë¥´¥ê¥º¥à¤ò³Îǧ¤Ç¤¤ë¤è¤¦¤Ë¤¹¤ë¡£¡Ê¤³¤Î¥Ú¡¼¥¸²¼Éô¤Ë¥³¡¼¥ÉÎã·ÇºÜ)
¡Ú³«È¯¥Õ¥í¡¼¡Û
¥·¥ß¥å¥ì¡¼¥¿¤Ç¥¢¥ë¥´¥ê¥º¥à¤Î´ðÁø¡Æ¤¢ª¼Âµ¡¤Ç¥Á¥å¡¼¥Ë¥ó¥°¡¡¤Îή¤ì¤Ç³Ú¤·¤¯³«È¯¢ö
¡Ú¥¹¥Ú¥Ã¥¯¡Û
±¿Æ°³Ø¡§2ÎØ¥â¥Ç¥ë¡¢BRICK¡§LEGO Mindstorm(RCX)¡¢½ï¸µÃÍ¡§RCX¥Ù¡¼¥¹¤Î¥Ñ¥¹¥Õ¥¡¥¤¥ó¥À¡¼¤«¤é¼Â¬¡¢2Dɽ¼¨¥â¡¼¥É¡¦3Dɽ¼¨¥â¡¼¥É¡¢¼Â»þ´Ö¥·¥ß¥å¥ì¡¼¥·¥ç¥ó²Äǽ¡¢ET¥í¥Ü¥³¥ó 2007Âбþ
¡ÚÆ°²è¡Û
¤½¤Î¸å RCX¤«¤éNXT¤ËÊѤï¤Ã¤Æ¡¢º£¤ÏEV3¤Ê¤ó¤Ç¤¹¤Ã¤Æ¤Í¡£(2016Äɵ)
#pragma once #include <vcclr.h> namespace BrickOSWrapper{ class PathFinder{ private: static gcroot<Misawat::Etrobo::Simulator::PathFinder*> _pathFinder; public: static void Set( Misawat::Etrobo::Simulator::PathFinder* pathFinder ){ _pathFinder = pathFinder; } static Misawat::Etrobo::Simulator::PathFinder* pathFinder(){ return _pathFinder; } }; class LightSensorWrapper{ private: gcroot<Misawat::Etrobo::Simulator::LightSensor*> _lightSensor; public: LightSensorWrapper(){ _lightSensor = PathFinder::pathFinder()->GetLightSensor(); } unsigned int get() const{ return _lightSensor->Get(); } }; class TractionMotorWrapper{ private: gcroot<Misawat::Etrobo::Simulator::Motor*> _tractionMotor; public: TractionMotorWrapper(){ _tractionMotor = PathFinder::pathFinder()->GetTractionMotor(); } void Forward( unsigned char s ) const{ _tractionMotor->Foward(s); } void Reverse( unsigned char s ) const{ _tractionMotor->Reverse(s); } }; class SteeringMotorWrapper{ private: gcroot<Misawat::Etrobo::Simulator::Motor*> _steeringMotor; public: SteeringMotorWrapper(){ _steeringMotor = PathFinder::pathFinder()->GetSteeringMotor(); } void Forward( unsigned char s ) const{ _steeringMotor->Foward(s); } void Reverse( unsigned char s ) const{ _steeringMotor->Reverse(s); } }; };
#include "StdAfx.h" #include "RunningMethodManager.h" // Normal #include "RunningMethod_Normal.h" RunningMethod::Normal* iRunningMethodNormal; // TODO-start: ¤³¤³¤Ë³Æ¼«¤ÎRunngingMethod¥¯¥é¥¹¤òÄɲà // #include "RunningMethod_XXX.h" // iRunningMethodXXX* iRunningMethodXXX; // TODO-end: RunningMethodManager::RunningMethodManager() { // ¸÷¥»¥ó¥µ¡¼ÃÍÍúÎò´ÉÍý¥â¥¸¥å¡¼¥ëÀ¸À® iLightValueHistory = new Common::LightValueHistory(); iRunningMethodNormal = new RunningMethod::Normal(); // TODO-start: ¤³¤³¤Ë³Æ¼«¤ÎRunngingMethod¥¯¥é¥¹¤òÄɲà // iRunningMethodXXX = new iRunningMethodXXX(); // TODO-end: // ïçÃÍÀßÄê Common::LightValueHistory::setThreshold( 100,0, 50 ); } RunningMethodManager::~RunningMethodManager() { } int RunningMethodManager::StartRunning() { bool courseDetection = false; unsigned int latestValue = 0; // ¸÷¥»¥ó¥µ¡¼Ã͹¹¿· iLightValueHistory->UpdateLightValueHistory(&latestValue); // ¥³¡¼¥¹È½ÊÌ // TODO-start: ¤³¤³¤Ë³Æ¼«¤ÎRunngingMethod¥¯¥é¥¹¤òÄɲà // courseDetection = iRunningMethodXXX->DetectCourse(iLightValueHistory); // if(true == courseDetection){ // iRunningMethodXXX->Run(); // } // TODO-end: courseDetection = iRunningMethodNormal->DetectCourse(iLightValueHistory); if(true == courseDetection){ iRunningMethodNormal->Run(); } return 1; } int RunningMethodManager::StopRunning() { return 1; }
//============================================================================== // - ̾Á°: Ä̾ïÁö¹Ô // - µ¡Ç½: Æñ½ê¤Ê¤É¤ò´Þ¤Þ¤Ê¤¤Ä̾ï¤Î¥«¡¼¥Ö¡¦Ä¾Àþ¤òÁö¤ë¥í¥¸¥Ã¥¯¤ò»ý¤Ä¡£ // - ³¥¿§¸¡½Ð¤Î¤¿¤á¥³¡¼¥¹¤Î³°Â¦¤ò¥¨¥Ã¥¸Áö¹Ô¤¹¤ë¡£ // ¤Ä¤Þ¤ê¡¢¹õ¡§±¦¡¢Çò¡§º¸¤Ë¥¹¥Æ¥¢¥ê¥ó¥°¤òÀڤ롣 // - °ìÄê³ÑÅٰʾ她¥Æ¥¢¥ê¥ó¥°¤ò¤¤é¤Ê¤¤¤è¤¦¤Ë¥ê¥ß¥Ã¥È¤òÀߤ±¤ë¡£ //============================================================================== #include "stdafx.h" #include "RunningMethod_Normal.h" using namespace Common; using namespace BrickOSWrapper; using namespace RunningMethod; #define ABS(x) (0<(x)?(x):-(x)) Normal::Normal() : _currentDirection( DirectionRight ), _counter( 0 ) { COUNTER_MAX = 100; STEERING_SPEED = 255 / (LIGHT_HISTORY_MAX / 2); } Normal::~Normal() { } int Normal::Run() { _tractionMotor.Forward(100); if( _lightValueHistory->isWhite( _lightSensor.get() ) ){ Left(); }else{ Right(); } return 0; } void Normal::Right() { Count( DirectionRight ); _steeringMotor.Forward( GetSpeed() ); } void Normal::Left() { Count( DirectionLeft ); _steeringMotor.Reverse( GetSpeed() ); } void Normal::Count( Direction direction ) { if( _currentDirection!=direction ){ _counter = 0; } else{ _counter ++; } _currentDirection = direction; } unsigned char Normal::GetSpeed() { if( _counter < COUNTER_MAX ){ return GetSpeedFromHistory(); } else{ // ¥¹¥Æ¥¢¥ê¥ó¥°¤¤ê¤¹¤®ËÉ»ß return 0; } } unsigned char Normal::GetSpeedFromHistory() { // Çò¹õ¤Î³ä¹ç¤Ë¤è¤Ã¤Æ¡¢¥¹¥Æ¥¢¥ê¥ó¥°¥¹¥Ô¡¼¥É¤ÎÊѹ¹ return ABS(_lightValueHistory->GetWhiteRate()-LIGHT_HISTORY_MAX/2) * STEERING_SPEED; } bool Normal::DetectCourse(Common::LightValueHistory* lightValueHistory) { // run¤Ç»ÈÍѤ¹¤ë¤Î¤Ç¥Ý¥¤¥ó¥¿¤òÊÝ»ý _lightValueHistory = lightValueHistory; // Ä̾ïÁö¹Ô¤Ê¤Î¤Çɬ¤ºtrue¤òÊÖ¤¹ return true; }