Updated version of RenBuggy Servo that can accept instructions based on time or distance.
Fork of RenBuggyServo by
Diff: Car.cpp
- Revision:
- 7:566d6deaceac
- Parent:
- 6:5767cb4ed8de
--- a/Car.cpp Mon Mar 31 12:54:28 2014 +0000 +++ b/Car.cpp Wed Apr 02 12:47:01 2014 +0000 @@ -104,8 +104,31 @@ return; } -void Car::forwards_timed() { +void Car::forwards_timed(float Time) { + m_motor.pulsewidth_us(m_speed); + wait(Time); + stop(); +} + + +void Car::forwards(float distance) { //Temporary extra one so that their current instructions still work. + int countsForward = (int)(distance * (m_countsPerRevolution / m_wheelCircumference)); + + m_encoderCount = 0; + bool isMoving = true; m_motor.pulsewidth_us(m_speed); + + while(isMoving) { + wait(0.2); // <<-- for some unknown reason, this requires a delay to work :-S + if(countsForward < m_encoderCount) + { + isMoving = false; + } + } + // When it's finished, stop the buggy. + stop(); + + return; } void Car::stop() {