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:
- 2:287a808baad7
- Parent:
- 1:3e1290de9c8d
- Child:
- 3:01bc89d7ae8e
--- a/Car.cpp Mon Mar 10 10:15:22 2014 +0000
+++ b/Car.cpp Mon Mar 10 11:53:45 2014 +0000
@@ -31,11 +31,6 @@
#include "Car.h"
#include "mbed.h"
-/*
-** Constructs the car with PwmOut objects for servo and motor.
-** @params servoPin: This is the pin used for pwm output for driving the servo.
-** @params motorPin: This is the pin used for pwm output for driving the motor.
-*/
Car::Car(PinName servoPin, PinName motorPin)
: m_servo(servoPin), m_motor(motorPin) {
m_speed = 15000;
@@ -47,26 +42,13 @@
m_speed = 15000;
}
-/*
-** Deconstructs the car.
-*/
Car::~Car() {
}
-/*
-**
-*/
void Car::setSpeed(int speed_us) {
m_speed = speed_us;
}
-/*
-** This function is for use in conjuction with
-** an encoder, and makes the car move a specified
-** distance.
-** @params distance: The distance the car should
-** move, in cm.
-*/
void Car::forwards(float distance) {
int countsForward = (int)(distance * (m_countsPerRevolution / m_wheelCircumference));
@@ -82,37 +64,19 @@
}
-/*
-** Start the car moving with a default speed.
-*/
void Car::forwards() {
m_motor.pulsewidth_us(m_speed);
}
-/*
-** Stops the motor.
-*/
void Car::stop() {
m_motor.pulsewidth_us(0);
}
-/*
-** Set the direction the car is facing.
-** @params degrees: The degrees of the angle, where -45 is full
-** left, 0 is centre and +45 is full right.
-*/
void Car::setDirection(int degrees) {
float angleOffset = m_servoRange * (m_servoDegrees / degrees);
m_servo.pulsewidth_us(1500 + angleOffset);
}
-/*
-** Configures the pulsewidth and perion for the servon, in microseconds.
-** @params pulsewidth_us: The pwm pulsewidth for the servo, in mircoseconds.
-** @params period_ms: The pwm period for the servo, in mircoseconds.
-** @params range: The pulsewidth range to full left/right turn of the servo from centre (1.5ms).
-** @params degrees: The angle to full right/left turn of the servo from centre (0).
-*/
void Car::configureServo_us(int pulsewidth_us, int period_us, int range, float degrees) {
m_servo.pulsewidth_us(pulsewidth_us);
m_servo.period_us(period_us);
@@ -120,13 +84,6 @@
m_servoDegrees = degrees;
}
-/*
-** Configures the pulsewidth and period for the servo, in milliseconds.
-** @params pulsewidth_ms: The pwm pulsewidth for the servo, in milliseconds.
-** @params period_ms: The pwm period for the servo, in milliseconds.
-** @params range: The pulsewidth range to full left/right turn of the servo from centre (1.5ms)
-** @params degrees: The angle to full right/left turn of the servo from centre (0).
-*/
void Car::configureServo_ms(int pulsewidth_ms, int period_ms, int range, float degrees) {
m_servo.pulsewidth_ms(pulsewidth_ms);
m_servo.period_ms(period_ms);
@@ -134,34 +91,16 @@
m_servoDegrees = degrees;
}
-/*
-** Configures the pulsewidth and period for the motor, in microseconds.
-** @params pulsewidth_us: The pwm pulsewidth for the motor, in mircoseconds.
-** @params period_us: The pwm period for the motor, in microseconds.
-*/
void Car::configureMotor_us(int pulsewidth_us, int period_us) {
m_motor.pulsewidth_us(pulsewidth_us);
m_motor.period_us(period_us);
}
-/*
-** Configures the pulsewidth and period for the motor, in milliseconds.
-** @params pulsewidth_ms: The pwm pulsewidth for the motor, in milliseconds.
-** @params period_ms: The pwm period for the motor, in milliseconds.
-*/
void Car::configureMotor_ms(int pulsewidth_ms, int period_ms) {
m_motor.pulsewidth_ms(pulsewidth_ms);
m_motor.period_ms(period_ms);
}
-/*
-** Provides information required to make use of an encoder for
-** specifying distance.
-** @params countsPerRevolution: The number of counts the encoder
-** makes in one full cycle of the wheel.
-** @params wheelCircumference: The circumference of the wheel being
-** read by the encoder.
-*/
void Car::configureEncoder(int countsPerRevolution, float wheelCircumference) {
m_countsPerRevolution = countsPerRevolution;
m_wheelCircumference = wheelCircumference;
