Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of RenBuggyServo by
Revision 7:566d6deaceac, committed 2014-04-02
- 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.
