Helvijs Kiselis
/
MicromousePES2
main.cpp: Sensoren einlesen und Motoren ansteuern
Motion.cpp
- Committer:
- Helvis
- Date:
- 2018-04-11
- Revision:
- 4:e74c06e43485
- Parent:
- 1:1adf5dfcc7bb
- Child:
- 5:47262622a9bf
File content as of revision 4:e74c06e43485:
#include <cmath> #include "Motion.h" using namespace std; const float Motion::SPEEDLEFT = 50.0f; const float Motion::SPEEDRIGHT = 50.0f; Motion::Motion(Controller& controller, EncoderCounter& counterLeft, EncoderCounter& counterRight, IRSensor& irSensorL, IRSensor& irSensorC, IRSensor& irSensorR) : controller(controller), counterLeft(counterLeft), counterRight(counterRight), irSensorL(irSensorL), irSensorC(irSensorC), irSensorR(irSensorR) { countsLeft = 0; countsRight = 0; } Motion::~Motion() {} void Motion::move() { distanceL = irSensorL.read(); distanceC = irSensorC.read(); distanceR = irSensorR.read(); while(countsLeft < 200 || countsRight < 200) { //Counts für eine Feld Bewegung countsLeft = counterLeft.read(); countsRight = counterRight.read(); controller.setDesiredSpeedLeft(50.0f); controller.setDesiredSpeedRight(-50.0f); } } void Motion::rotateL() { while(countsLeft < 200 || countsRight > -200) { //Count Grenze durch Rechnung bestimmen für 90° Umfang/4 countsLeft = counterLeft.read(); countsRight = counterRight.read(); controller.setDesiredSpeedLeft(50.0f); controller.setDesiredSpeedRight(-50.0f); } } void Motion::rotateR() { while(countsLeft > -200 || countsRight < 200) { //Count Grenze durch Rechnung bestimmen für 90° Umfang/4 countsLeft = counterLeft.read(); countsRight = counterRight.read(); controller.setDesiredSpeedLeft(-50.0f); controller.setDesiredSpeedRight(50.0f); } } //180° rotation void Motion::reverse() { while(countsLeft < 200 || countsRight > -200) { //Count Grenze durch Rechnung bestimmen für 180° Umfang/2 countsLeft = counterLeft.read(); countsRight = counterRight.read(); controller.setDesiredSpeedLeft(50.0f); controller.setDesiredSpeedRight(-50.0f); } }