Updated version of RenBuggy Servo that can accept instructions based on time or distance.

Dependencies:   PinDetect mbed

Fork of RenBuggyServo by Renishaw

Files at this revision

API Documentation at this revision

Comitter:
ELloyd
Date:
Wed Apr 02 12:47:01 2014 +0000
Parent:
6:5767cb4ed8de
Child:
8:7af88a6dbb05
Commit message:
Adjusted so that it will work with programs written for previous versions

Changed in this revision

Car.cpp Show annotated file Show diff for this revision Revisions of this file
Car.h Show annotated file Show diff for this revision Revisions of this file
--- 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() {
--- a/Car.h	Mon Mar 31 12:54:28 2014 +0000
+++ b/Car.h	Wed Apr 02 12:47:01 2014 +0000
@@ -129,8 +129,16 @@
     /**
     * Moves the car in the direction it is facing, until a user
     * tells it to stop.
+    * @param Time is the time in seconds during which it will drive forwards, then stop.
     */
-    void forwards_timed();
+    void forwards_timed(float Time);
+    
+    /**
+    * Moves the car in the direction it is facing, for a specified
+    * distance.
+    * @param distance is how far the car will travel, in cm.
+    */
+    void forwards(float distance);
     
     /**
     * Stops the car from moving.