Updated version of RenBuggy Servo that can accept instructions based on time or distance.
Fork of RenBuggyServo by
Diff: Car.h
- Revision:
- 0:d388aed56112
- Child:
- 1:3e1290de9c8d
diff -r 000000000000 -r d388aed56112 Car.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Car.h Fri Mar 07 07:54:13 2014 +0000 @@ -0,0 +1,58 @@ +/******************************************************************************* +* RenBED Car used to drive RenBuggy with servo and 1 motor * +* Copyright (c) 2014 Mark Jones * +* * +* Permission is hereby granted, free of charge, to any person obtaining a copy * +* of this software and associated documentation files (the "Software"), to deal* +* in the Software without restriction, including without limitation the rights * +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * +* copies of the Software, and to permit persons to whom the Software is * +* furnished to do so, subject to the following conditions: * +* * +* The above copyright notice and this permission notice shall be included in * +* all copies or substantial portions of the Software. * +* * +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * +* THE SOFTWARE. * +* * +* Car.h * +* * +* V1. 05/03/2014 Mark Jones * +*******************************************************************************/ + +#ifndef CAR_H +#define CAR_H + +#include "mbed.h" + +class Car { + private: + PwmOut m_servo; + PwmOut m_motor; + int m_pwmPeriod; // Period used in PWM. + int m_servoRange; // Pulsewidth range to full left/right from centre (1.5ms) + float m_servoDegrees; // Angle to full right/left turn from centre (0). + float distanceToTimeConverter(float distance); + public: + Car(PinName servoPin, PinName motorPin); + ~Car(); + + void forwards(float distance); + void forwards(int speed); + void forwards(); + void stop(); + void setDirection(int degrees); + + void configureServo_us(int pulsewidth_us, int period_us, int range, float degrees); + void configureServo_ms(int pulsewidth_ms, int period_ms, int range, float degrees); + + void configureMotor_us(int pulsewidth_us, int period_us); + void configureMotor_ms(int pulsewidth_ms, int period_ms); +}; + +#endif // CAR_H \ No newline at end of file