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

Dependencies:   PinDetect mbed

Fork of RenBuggyServo by Renishaw

Car.h

Committer:
Markatron
Date:
2014-03-10
Revision:
1:3e1290de9c8d
Parent:
0:d388aed56112
Child:
2:287a808baad7

File content as of revision 1:3e1290de9c8d:

/*******************************************************************************
* 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_speed;
    
    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 m_wheelCircumference; // The circumference of the wheel with stripes.
    int m_countsPerRevolution;  // The number of stripes on the wheel.
    //InterruptIn m_stripeInterrupt;
    
    //float distanceToTimeConverter(float distance);
    
    public:
    
    Car(PinName servoPin, PinName motorPin);
    Car(PinName servoPin, PinName motorPin, int countsPerRevolution, float wheelCircumference);
    ~Car();
    
    void setSpeed(int speed_us);
    void forwards(float distance);
    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);
    
    void configureEncoder(int countsPerRevolution, float wheelCircumference);
};

#endif // CAR_H