A Library to drive the RenBuggy_Servo.
Dependencies: PinDetect
Fork of RenBuggyServo by
Car.h@1:3e1290de9c8d, 2014-03-10 (annotated)
- Committer:
- Markatron
- Date:
- Mon Mar 10 10:15:22 2014 +0000
- Revision:
- 1:3e1290de9c8d
- Parent:
- 0:d388aed56112
- Child:
- 2:287a808baad7
RenBuggy Servo updated library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Markatron | 0:d388aed56112 | 1 | /******************************************************************************* |
Markatron | 0:d388aed56112 | 2 | * RenBED Car used to drive RenBuggy with servo and 1 motor * |
Markatron | 0:d388aed56112 | 3 | * Copyright (c) 2014 Mark Jones * |
Markatron | 0:d388aed56112 | 4 | * * |
Markatron | 0:d388aed56112 | 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy * |
Markatron | 0:d388aed56112 | 6 | * of this software and associated documentation files (the "Software"), to deal* |
Markatron | 0:d388aed56112 | 7 | * in the Software without restriction, including without limitation the rights * |
Markatron | 0:d388aed56112 | 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * |
Markatron | 0:d388aed56112 | 9 | * copies of the Software, and to permit persons to whom the Software is * |
Markatron | 0:d388aed56112 | 10 | * furnished to do so, subject to the following conditions: * |
Markatron | 0:d388aed56112 | 11 | * * |
Markatron | 0:d388aed56112 | 12 | * The above copyright notice and this permission notice shall be included in * |
Markatron | 0:d388aed56112 | 13 | * all copies or substantial portions of the Software. * |
Markatron | 0:d388aed56112 | 14 | * * |
Markatron | 0:d388aed56112 | 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * |
Markatron | 0:d388aed56112 | 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * |
Markatron | 0:d388aed56112 | 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * |
Markatron | 0:d388aed56112 | 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * |
Markatron | 0:d388aed56112 | 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* |
Markatron | 0:d388aed56112 | 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * |
Markatron | 0:d388aed56112 | 21 | * THE SOFTWARE. * |
Markatron | 0:d388aed56112 | 22 | * * |
Markatron | 0:d388aed56112 | 23 | * Car.h * |
Markatron | 0:d388aed56112 | 24 | * * |
Markatron | 0:d388aed56112 | 25 | * V1. 05/03/2014 Mark Jones * |
Markatron | 0:d388aed56112 | 26 | *******************************************************************************/ |
Markatron | 0:d388aed56112 | 27 | |
Markatron | 0:d388aed56112 | 28 | #ifndef CAR_H |
Markatron | 0:d388aed56112 | 29 | #define CAR_H |
Markatron | 0:d388aed56112 | 30 | |
Markatron | 0:d388aed56112 | 31 | #include "mbed.h" |
Markatron | 0:d388aed56112 | 32 | |
Markatron | 0:d388aed56112 | 33 | class Car { |
Markatron | 0:d388aed56112 | 34 | private: |
Markatron | 1:3e1290de9c8d | 35 | |
Markatron | 0:d388aed56112 | 36 | PwmOut m_servo; |
Markatron | 0:d388aed56112 | 37 | PwmOut m_motor; |
Markatron | 1:3e1290de9c8d | 38 | |
Markatron | 1:3e1290de9c8d | 39 | int m_speed; |
Markatron | 1:3e1290de9c8d | 40 | |
Markatron | 0:d388aed56112 | 41 | int m_servoRange; // Pulsewidth range to full left/right from centre (1.5ms) |
Markatron | 0:d388aed56112 | 42 | float m_servoDegrees; // Angle to full right/left turn from centre (0). |
Markatron | 1:3e1290de9c8d | 43 | |
Markatron | 1:3e1290de9c8d | 44 | float m_wheelCircumference; // The circumference of the wheel with stripes. |
Markatron | 1:3e1290de9c8d | 45 | int m_countsPerRevolution; // The number of stripes on the wheel. |
Markatron | 1:3e1290de9c8d | 46 | //InterruptIn m_stripeInterrupt; |
Markatron | 1:3e1290de9c8d | 47 | |
Markatron | 1:3e1290de9c8d | 48 | //float distanceToTimeConverter(float distance); |
Markatron | 1:3e1290de9c8d | 49 | |
Markatron | 0:d388aed56112 | 50 | public: |
Markatron | 1:3e1290de9c8d | 51 | |
Markatron | 0:d388aed56112 | 52 | Car(PinName servoPin, PinName motorPin); |
Markatron | 1:3e1290de9c8d | 53 | Car(PinName servoPin, PinName motorPin, int countsPerRevolution, float wheelCircumference); |
Markatron | 0:d388aed56112 | 54 | ~Car(); |
Markatron | 0:d388aed56112 | 55 | |
Markatron | 1:3e1290de9c8d | 56 | void setSpeed(int speed_us); |
Markatron | 0:d388aed56112 | 57 | void forwards(float distance); |
Markatron | 0:d388aed56112 | 58 | void forwards(); |
Markatron | 0:d388aed56112 | 59 | void stop(); |
Markatron | 0:d388aed56112 | 60 | void setDirection(int degrees); |
Markatron | 0:d388aed56112 | 61 | |
Markatron | 0:d388aed56112 | 62 | void configureServo_us(int pulsewidth_us, int period_us, int range, float degrees); |
Markatron | 0:d388aed56112 | 63 | void configureServo_ms(int pulsewidth_ms, int period_ms, int range, float degrees); |
Markatron | 0:d388aed56112 | 64 | |
Markatron | 0:d388aed56112 | 65 | void configureMotor_us(int pulsewidth_us, int period_us); |
Markatron | 0:d388aed56112 | 66 | void configureMotor_ms(int pulsewidth_ms, int period_ms); |
Markatron | 1:3e1290de9c8d | 67 | |
Markatron | 1:3e1290de9c8d | 68 | void configureEncoder(int countsPerRevolution, float wheelCircumference); |
Markatron | 0:d388aed56112 | 69 | }; |
Markatron | 0:d388aed56112 | 70 | |
Markatron | 0:d388aed56112 | 71 | #endif // CAR_H |