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.
Dependencies: PinDetect
Fork of RenBuggyServo by
Diff: Car.cpp
- Revision:
- 4:aac581bec332
- Parent:
- 3:01bc89d7ae8e
- Child:
- 5:c06b90175a54
diff -r 01bc89d7ae8e -r aac581bec332 Car.cpp
--- a/Car.cpp Thu Mar 13 07:31:10 2014 +0000
+++ b/Car.cpp Mon Mar 31 07:44:16 2014 +0000
@@ -31,11 +31,25 @@
#include "Car.h"
#include "mbed.h"
+const int SERVO_PWM = 1500; // 1500 = centre.
+const int SERVO_PWM_PERIOD = 2000;
+const int SERVO_PWM_RANGE = 500; // + or - 500 microseconds.
+const float SERVO_DEGREES_RANGE = 45.0; // + or - from centre is full right/left.
+
+const int MOTOR_PWM = 20000;
+const int MOTOR_PERIOD = 20000;
+
Car::Car(PinName servoPin, PinName motorPin)
: m_servo(servoPin), m_motor(motorPin) {
+
m_speed = 15000;
m_countsPerRevolution = 0;
m_wheelCircumference = 0;
+
+ configureServo_us(SERVO_PWM, SERVO_PWM_PERIOD,
+ SERVO_PWM_RANGE, SERVO_DEGREES_RANGE);
+
+ configureMotor_us(MOTOR_PWM, MOTOR_PERIOD);
}
Car::Car(PinName servoPin, PinName motorPin, int countsPerRevolution, float wheelCircumference, PinName sensorPin)
@@ -45,6 +59,11 @@
m_speed = 15000;
setDirection(0);
+ configureServo_us(SERVO_PWM, SERVO_PWM_PERIOD,
+ SERVO_PWM_RANGE, SERVO_DEGREES_RANGE);
+
+ configureMotor_us(MOTOR_PWM, MOTOR_PERIOD);
+
m_encoderCount = 0;
m_sensor.setSampleFrequency(1000);
m_sensor.setSamplesTillHeld(5);
