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.
Dependencies: mbed Servo ros_lib_kinetic
Motors/Motor.h@10:51dd168b5a96, 2020-01-06 (annotated)
- Committer:
- Stumi
- Date:
- Mon Jan 06 20:38:07 2020 +0000
- Revision:
- 10:51dd168b5a96
- Parent:
- 9:326b8f261ef0
added autonomous control to ros commands
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Stumi | 2:6197e1cf2cd1 | 1 | /*-------------------------------------------------------------------------------- |
| Stumi | 2:6197e1cf2cd1 | 2 | Filename: TOF.h |
| Stumi | 2:6197e1cf2cd1 | 3 | Description: Header file for adafruit VL_6180X TOF sensor |
| Stumi | 2:6197e1cf2cd1 | 4 | --------------------------------------------------------------------------------*/ |
| Stumi | 2:6197e1cf2cd1 | 5 | #ifndef MOTOR_H |
| Stumi | 2:6197e1cf2cd1 | 6 | #define MOTOR_H |
| Stumi | 2:6197e1cf2cd1 | 7 | |
| Stumi | 2:6197e1cf2cd1 | 8 | #include "mbed.h" |
| Stumi | 6:2cc2aac35868 | 9 | #include "Buzzer.h" |
| Stumi | 8:262c6c40bff9 | 10 | #include <ros.h> |
| Alexshawcroft | 9:326b8f261ef0 | 11 | #include <Servo.h> |
| Stumi | 8:262c6c40bff9 | 12 | #include <std_msgs/UInt8.h> |
| Stumi | 2:6197e1cf2cd1 | 13 | |
| Stumi | 2:6197e1cf2cd1 | 14 | /*-------------------------------------------------------------------------------- |
| Stumi | 2:6197e1cf2cd1 | 15 | ---------------------------------DEFINES------------------------------------------ |
| Stumi | 2:6197e1cf2cd1 | 16 | --------------------------------------------------------------------------------*/ |
| Stumi | 2:6197e1cf2cd1 | 17 | |
| Stumi | 2:6197e1cf2cd1 | 18 | //MOTOR 1 |
| Stumi | 2:6197e1cf2cd1 | 19 | #define M1_IN1 PC_6 |
| Stumi | 2:6197e1cf2cd1 | 20 | #define M1_IN2 PB_15 |
| Stumi | 2:6197e1cf2cd1 | 21 | #define M1_PWM PB_13 |
| Stumi | 2:6197e1cf2cd1 | 22 | #define M1_A PA_4 |
| Stumi | 2:6197e1cf2cd1 | 23 | #define M1_B PB_12 |
| Stumi | 2:6197e1cf2cd1 | 24 | |
| Stumi | 2:6197e1cf2cd1 | 25 | //MOTOR 2 |
| Stumi | 2:6197e1cf2cd1 | 26 | #define M2_IN1 PA_15 |
| Stumi | 2:6197e1cf2cd1 | 27 | #define M2_IN2 PC_7 |
| Stumi | 2:6197e1cf2cd1 | 28 | #define M2_PWM PB_4 |
| Stumi | 2:6197e1cf2cd1 | 29 | #define M2_A PB_5 |
| Stumi | 2:6197e1cf2cd1 | 30 | #define M2_B PB_3 |
| Alexshawcroft | 9:326b8f261ef0 | 31 | #define srvoPan PE_5 |
| Alexshawcroft | 9:326b8f261ef0 | 32 | #define srvoTilt PF_9 |
| Alexshawcroft | 9:326b8f261ef0 | 33 | |
| Alexshawcroft | 9:326b8f261ef0 | 34 | |
| Alexshawcroft | 9:326b8f261ef0 | 35 | static Servo servo1(srvoTilt); |
| Alexshawcroft | 9:326b8f261ef0 | 36 | static Servo servo2(srvoPan); |
| Stumi | 2:6197e1cf2cd1 | 37 | |
| Stumi | 2:6197e1cf2cd1 | 38 | /*-------------------------------------------------------------------------------- |
| Stumi | 2:6197e1cf2cd1 | 39 | ---------------------------------CLASSES------------------------------------------ |
| Stumi | 2:6197e1cf2cd1 | 40 | --------------------------------------------------------------------------------*/ |
| Stumi | 2:6197e1cf2cd1 | 41 | |
| Stumi | 2:6197e1cf2cd1 | 42 | // Class for managing connection and state to a VL6180X sensor |
| Stumi | 2:6197e1cf2cd1 | 43 | |
| Stumi | 2:6197e1cf2cd1 | 44 | class cMotor |
| Stumi | 2:6197e1cf2cd1 | 45 | { |
| Stumi | 2:6197e1cf2cd1 | 46 | public: |
| Stumi | 2:6197e1cf2cd1 | 47 | cMotor(PwmOut pwm, DigitalOut fwd, DigitalOut rev); //Constructor, initialised motor pinouts |
| Stumi | 7:8248af58df5a | 48 | void Forwards(float speed); //Drives motor forwards |
| Stumi | 7:8248af58df5a | 49 | void Backwards(float speed);//Drives motor backwards |
| Stumi | 7:8248af58df5a | 50 | void Stop(); //Stops both motors |
| Stumi | 2:6197e1cf2cd1 | 51 | private: |
| Stumi | 2:6197e1cf2cd1 | 52 | PwmOut _pwm; |
| Stumi | 2:6197e1cf2cd1 | 53 | DigitalOut _fwd; |
| Stumi | 2:6197e1cf2cd1 | 54 | DigitalOut _rev; |
| Stumi | 2:6197e1cf2cd1 | 55 | |
| Stumi | 2:6197e1cf2cd1 | 56 | }; |
| Stumi | 2:6197e1cf2cd1 | 57 | |
| Stumi | 2:6197e1cf2cd1 | 58 | /*-------------------------------------------------------------------------------- |
| Stumi | 2:6197e1cf2cd1 | 59 | -----------------------------------Functions--------------------------------------- |
| Stumi | 2:6197e1cf2cd1 | 60 | --------------------------------------------------------------------------------*/ |
| Stumi | 10:51dd168b5a96 | 61 | void Check_for_obstacles(float TOFRange[4]); //Obstacle avoidance functionality |
| Stumi | 7:8248af58df5a | 62 | void update_power_levels(float vBatt); //Sends power level to the LED class for further processing |
| Alexshawcroft | 9:326b8f261ef0 | 63 | void MotorKeySub(const std_msgs::UInt8 &keyPress); |
| Alexshawcroft | 9:326b8f261ef0 | 64 | void servoKeySub(const std_msgs::UInt8 &ServoKeyPress); |
| Alexshawcroft | 9:326b8f261ef0 | 65 | |
| Stumi | 2:6197e1cf2cd1 | 66 | /*-------------------------------------------------------------------------------- |
| Stumi | 2:6197e1cf2cd1 | 67 | --------------------------------External Variables-------------------------------- |
| Stumi | 2:6197e1cf2cd1 | 68 | --------------------------------------------------------------------------------*/ |
| Stumi | 4:36a04230554d | 69 | //extern cMotor MotorL; //Left motor class and pin initialisation |
| Stumi | 4:36a04230554d | 70 | //extern cMotor MotorR; //Right motor class and pin initialisation |
| Stumi | 2:6197e1cf2cd1 | 71 | |
| Alexshawcroft | 9:326b8f261ef0 | 72 | |
| Alexshawcroft | 9:326b8f261ef0 | 73 | static int IncSize; //Increment size for servo movment in increments of 1 - 20 degrees |
| Stumi | 10:51dd168b5a96 | 74 | extern float *TOFrangePtr[4]; |
| Alexshawcroft | 9:326b8f261ef0 | 75 | |
| Stumi | 2:6197e1cf2cd1 | 76 | #endif |