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.
Car.h
- Committer:
- edmugu
- Date:
- 2019-05-24
- Revision:
- 8:14e91fdf70e8
- Parent:
- 0:7676da98b5c1
File content as of revision 8:14e91fdf70e8:
#ifndef MBED_MOTOR_H #define MBED_MOTOR_H #include "mbed.h" #include <Motor.h> // DC motor driver struct Car_vector { float speed; float turnCW; }; class Car { public: Car( PinName pwm1, PinName fwd1, PinName rev1, PinName encoderA1, PinName encoderB1, PinName pwm2, PinName fwd2, PinName rev2, PinName encoderA2, PinName encoderB2 ); //Sets the speed as thicks per second(i.e. 1 = 100% and 0.5 = 50%) void speed(float speed); float speed(void); //Sets the speed difference between the motors // Example 1: if original speed is 50% // turnCW(0.5) => rightMotor @ 25% and leftMotor @ 75% // turnCW(0.1) => rightMotor @ 45% and leftMotor @ 55% // // Example 2: if original speed is 100% // turnCW(0.5) => rightMotor @ 75% and leftMotor @ 100% // turnCW(0.1) => rightMotor @ 95% and leftMotor @ 100% void turnCW(float turn); protected: void _set_motors(void); float _clamp_speed(float sp); void _mlspeed(float sp); void _mrspeed(float sp); float _car_speed; float _car_turn; time_t _last_tick_left; time_t _last_tick_right; DigitalIn _ml_encoderA; DigitalIn _ml_encoderB; DigitalIn _mr_encoderA; DigitalIn _mr_encoderB; bool _ml_encoderA_before; bool _ml_encoderB_before; bool _mr_encoderA_before; bool _mr_encoderB_before; PwmOut _ml_pwm; PwmOut _mr_pwm; DigitalOut _ml_fwd; DigitalOut _mr_fwd; DigitalOut _ml_rev; DigitalOut _mr_rev; }; #endif