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

Dependencies:   PinDetect mbed

Fork of RenBuggyServo by Renishaw

Embed: (wiki syntax)

« Back to documentation index

Car Class Reference

Car Class Reference

RenBuggyServo Example: More...

#include <Car.h>

Public Member Functions

 Car (PinName servoPin, PinName motorPin)
 Constructs the car with PwmOut objects for servo and motor.
 Car (PinName servoPin, PinName motorPin, int countsPerRevolution, float wheelCircumference, PinName sensorPin)
 Constructs the car with PwmOut objects for servo and motor, and configures the encoder.
 ~Car ()
 Deconstructs the car.
void setSpeed (int speed_us)
 Sets the speed the buggy will move at.
void forwards_measured (float distance)
 Moves the car in the direction it is facing, for a specified distance.
void forwards_timed (float Time)
 Moves the car in the direction it is facing, until a user tells it to stop.
void forwards (float distance)
 Moves the car in the direction it is facing, for a specified distance.
void stop ()
 Stops the car from moving.
void setDirection (int degrees)
 Sets the direction the car will face.
void configureServo_us (int pulsewidth_us, int period_us, int range, float degrees)
 Configures the servo with a pulsewidth, period, range and degrees.
void configureServo_ms (int pulsewidth_ms, int period_ms, int range, float degrees)
 Configures the servo with a pulsewidth, period, range and degrees.
void configureMotor_us (int pulsewidth_us, int period_us)
 Configures the pulsewidth and period for the motor, in microseconds.
void configureMotor_ms (int pulsewidth_ms, int period_ms)
 Configures the pulsewidth and period for the motor, in milliseconds.
void configureEncoder (int countsPerRevolution, float wheelCircumference)
 Provides information required to make use of an encoder for specifying distance.

Detailed Description

RenBuggyServo Example:

#include "mbed.h"
#include "Car.h"

Car myCar(P1_25, P1_24);

// Main entry point of application.
int main() {
    
    // Drive the RenBuggy!
    myCar.setSpeed(20000);
    myCar.setDirection(0);
    
    myCar.forwards();   
    wait(1);
    myCar.setDirection(45);
    wait(1);
    myCar.setDirection(-45);
    wait(1);
    myCar.setDirection(0);
    myCar.stop(); 
    
    myCar.forwards(10); // Move the car a final 10cm.
    myCar.stop();
}
// End programme.

The car class for controlling the RenBuggy_Servo.

Definition at line 70 of file Car.h.


Constructor & Destructor Documentation

Car ( PinName  servoPin,
PinName  motorPin 
)

Constructs the car with PwmOut objects for servo and motor.

Parameters:
servoPinis the pin used for pwm output for driving the servo.
motorPinis the pin used for pwm output for driving the motor.

Definition at line 42 of file Car.cpp.

Car ( PinName  servoPin,
PinName  motorPin,
int  countsPerRevolution,
float  wheelCircumference,
PinName  sensorPin 
)

Constructs the car with PwmOut objects for servo and motor, and configures the encoder.

Parameters:
servoPinis the pin used for pwm output for driving the servo.
motorPinis the pin used for pwm output for driving the motor.
countsPerRevolutionis the number of counts the encoder makes in one full cycle of the wheel.
wheelCircumferenceis the circumference of the wheel being read by the encoder.
sensorPinis the pin required for the encoder for debouncing.

Definition at line 55 of file Car.cpp.

~Car (  )

Deconstructs the car.

Definition at line 75 of file Car.cpp.


Member Function Documentation

void configureEncoder ( int  countsPerRevolution,
float  wheelCircumference 
)

Provides information required to make use of an encoder for specifying distance.

Parameters:
countsPerRevolutionis the number of counts the encoder makes in one full cycle of the wheel.
wheelCircumferenceis the circumference of the wheel being read by the encoder.

Definition at line 167 of file Car.cpp.

void configureMotor_ms ( int  pulsewidth_ms,
int  period_ms 
)

Configures the pulsewidth and period for the motor, in milliseconds.

Parameters:
pulsewidth_msis the pwm pulsewidth for the motor, in milliseconds.
period_msis the pwm period for the motor, in milliseconds.

Definition at line 162 of file Car.cpp.

void configureMotor_us ( int  pulsewidth_us,
int  period_us 
)

Configures the pulsewidth and period for the motor, in microseconds.

Parameters:
pulsewidth_usis the pwm pulsewidth for the motor, in mircoseconds.
period_usis the pwm period for the motor, in microseconds.

Definition at line 157 of file Car.cpp.

void configureServo_ms ( int  pulsewidth_ms,
int  period_ms,
int  range,
float  degrees 
)

Configures the servo with a pulsewidth, period, range and degrees.

Pulsewidth and period is accepted in millisecond format.

Parameters:
pulsewidth_msis pwm pulsewidth for the servo, in millisecond.
period_msis the pwm period for the servo, in millisecond.
rangeis the pulsewidth range to full left/right turn of the servo from centre (1.5ms).
degreesis the angle to full right/left turn of the servo from centre (0).

Definition at line 150 of file Car.cpp.

void configureServo_us ( int  pulsewidth_us,
int  period_us,
int  range,
float  degrees 
)

Configures the servo with a pulsewidth, period, range and degrees.

Pulsewidth and period is accepted in microsecond format.

Parameters:
pulsewidth_usis pwm pulsewidth for the servo, in mircoseconds.
period_usis the pwm period for the servo, in mircoseconds.
rangeis the pulsewidth range to full left/right turn of the servo from centre (1500us).
degreesis the angle to full right/left turn of the servo from centre (0).

Definition at line 143 of file Car.cpp.

void forwards ( float  distance )

Moves the car in the direction it is facing, for a specified distance.

Parameters:
distanceis how far the car will travel, in cm.

Definition at line 114 of file Car.cpp.

void forwards_measured ( float  distance )

Moves the car in the direction it is facing, for a specified distance.

Parameters:
distanceis how far the car will travel, in cm.

Definition at line 86 of file Car.cpp.

void forwards_timed ( float  Time )

Moves the car in the direction it is facing, until a user tells it to stop.

Parameters:
Timeis the time in seconds during which it will drive forwards, then stop.

Definition at line 107 of file Car.cpp.

void setDirection ( int  degrees )

Sets the direction the car will face.

This is used to navigate the car.

Parameters:
degreesis the angle of the servo, where -45 is full left, 0 is centre and +45 is full right.

Definition at line 138 of file Car.cpp.

void setSpeed ( int  speed_us )

Sets the speed the buggy will move at.

Parameters:
speed_usis the speed the car will move at, in microseconds.

Definition at line 78 of file Car.cpp.

void stop (  )

Stops the car from moving.

Definition at line 134 of file Car.cpp.