![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
The preloaded firmware shipped on the mBot.
Please use the version of this project/repo found at: http://developer.mbed.org/teams/Outrageous-Circuits/code/Official_mBot/
mBot_lib/mBot.h@0:865d42c46692, 2014-11-25 (annotated)
- Committer:
- jeffknaggs
- Date:
- Tue Nov 25 14:34:47 2014 +0000
- Revision:
- 0:865d42c46692
Initial commit.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jeffknaggs | 0:865d42c46692 | 1 | /* |
jeffknaggs | 0:865d42c46692 | 2 | ** This software can be freely used, even comercially, as highlighted in the license. |
jeffknaggs | 0:865d42c46692 | 3 | ** |
jeffknaggs | 0:865d42c46692 | 4 | ** Copyright 2014 GHI Electronics, LLC |
jeffknaggs | 0:865d42c46692 | 5 | ** |
jeffknaggs | 0:865d42c46692 | 6 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
jeffknaggs | 0:865d42c46692 | 7 | ** you may not use this file except in compliance with the License. |
jeffknaggs | 0:865d42c46692 | 8 | ** You may obtain a copy of the License at |
jeffknaggs | 0:865d42c46692 | 9 | ** |
jeffknaggs | 0:865d42c46692 | 10 | ** http://www.apache.org/licenses/LICENSE-2.0 |
jeffknaggs | 0:865d42c46692 | 11 | ** |
jeffknaggs | 0:865d42c46692 | 12 | ** Unless required by applicable law or agreed to in writing, software |
jeffknaggs | 0:865d42c46692 | 13 | ** distributed under the License is distributed on an "AS IS" BASIS, |
jeffknaggs | 0:865d42c46692 | 14 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
jeffknaggs | 0:865d42c46692 | 15 | ** See the License for the specific language governing permissions and |
jeffknaggs | 0:865d42c46692 | 16 | ** limitations under the License. |
jeffknaggs | 0:865d42c46692 | 17 | ** |
jeffknaggs | 0:865d42c46692 | 18 | **/ |
jeffknaggs | 0:865d42c46692 | 19 | |
jeffknaggs | 0:865d42c46692 | 20 | #pragma once |
jeffknaggs | 0:865d42c46692 | 21 | #include <string> |
jeffknaggs | 0:865d42c46692 | 22 | #include "mbed.h" |
jeffknaggs | 0:865d42c46692 | 23 | |
jeffknaggs | 0:865d42c46692 | 24 | |
jeffknaggs | 0:865d42c46692 | 25 | class mBot |
jeffknaggs | 0:865d42c46692 | 26 | { |
jeffknaggs | 0:865d42c46692 | 27 | |
jeffknaggs | 0:865d42c46692 | 28 | public: // constructors, enums |
jeffknaggs | 0:865d42c46692 | 29 | mBot(); |
jeffknaggs | 0:865d42c46692 | 30 | |
jeffknaggs | 0:865d42c46692 | 31 | |
jeffknaggs | 0:865d42c46692 | 32 | typedef enum |
jeffknaggs | 0:865d42c46692 | 33 | { |
jeffknaggs | 0:865d42c46692 | 34 | /// <summary> |
jeffknaggs | 0:865d42c46692 | 35 | /// Represents the left sensor. |
jeffknaggs | 0:865d42c46692 | 36 | /// </summary> |
jeffknaggs | 0:865d42c46692 | 37 | Left, |
jeffknaggs | 0:865d42c46692 | 38 | |
jeffknaggs | 0:865d42c46692 | 39 | /// <summary> |
jeffknaggs | 0:865d42c46692 | 40 | /// Represents the right sensor. |
jeffknaggs | 0:865d42c46692 | 41 | /// </summary> |
jeffknaggs | 0:865d42c46692 | 42 | Right |
jeffknaggs | 0:865d42c46692 | 43 | } ReflectiveSensors; |
jeffknaggs | 0:865d42c46692 | 44 | |
jeffknaggs | 0:865d42c46692 | 45 | private: // fields |
jeffknaggs | 0:865d42c46692 | 46 | static const float MOTOR_BASE_PERIOD = 0.00001; // 100KHz |
jeffknaggs | 0:865d42c46692 | 47 | |
jeffknaggs | 0:865d42c46692 | 48 | static PwmOut *leftMotor; |
jeffknaggs | 0:865d42c46692 | 49 | static PwmOut *rightMotor; |
jeffknaggs | 0:865d42c46692 | 50 | |
jeffknaggs | 0:865d42c46692 | 51 | static DigitalOut *leftMotorDirectionCtrl_1; |
jeffknaggs | 0:865d42c46692 | 52 | static DigitalOut *leftMotorDirectionCtrl_2; |
jeffknaggs | 0:865d42c46692 | 53 | |
jeffknaggs | 0:865d42c46692 | 54 | static DigitalOut *rightMotorDirectionCtrl_1; |
jeffknaggs | 0:865d42c46692 | 55 | static DigitalOut *rightMotorDirectionCtrl_2; |
jeffknaggs | 0:865d42c46692 | 56 | |
jeffknaggs | 0:865d42c46692 | 57 | static bool leftMotorInverted; |
jeffknaggs | 0:865d42c46692 | 58 | static bool rightMotorInverted; |
jeffknaggs | 0:865d42c46692 | 59 | |
jeffknaggs | 0:865d42c46692 | 60 | static AnalogIn *leftSensor; |
jeffknaggs | 0:865d42c46692 | 61 | static AnalogIn *rightSensor; |
jeffknaggs | 0:865d42c46692 | 62 | static DigitalOut *leftIRLED; |
jeffknaggs | 0:865d42c46692 | 63 | static DigitalOut *rightIRLED; |
jeffknaggs | 0:865d42c46692 | 64 | |
jeffknaggs | 0:865d42c46692 | 65 | |
jeffknaggs | 0:865d42c46692 | 66 | public: // methods .... |
jeffknaggs | 0:865d42c46692 | 67 | |
jeffknaggs | 0:865d42c46692 | 68 | /// <summary> |
jeffknaggs | 0:865d42c46692 | 69 | /// Gets the reading from a reflective sensor between 0 and 1024 (10 bit resolution). The higher the number, |
jeffknaggs | 0:865d42c46692 | 70 | /// the more reflection that was detected. Nearby objects reflect more than far objects. |
jeffknaggs | 0:865d42c46692 | 71 | /// </summary> |
jeffknaggs | 0:865d42c46692 | 72 | /// <param name="sensor">The sensor to read from.</param> |
jeffknaggs | 0:865d42c46692 | 73 | static float GetReflectiveReading(ReflectiveSensors sensor); |
jeffknaggs | 0:865d42c46692 | 74 | |
jeffknaggs | 0:865d42c46692 | 75 | /// <summary> |
jeffknaggs | 0:865d42c46692 | 76 | /// Turns the reflective sensors on or off to save power (1 = on, 0 = off). They are on by default. |
jeffknaggs | 0:865d42c46692 | 77 | /// </summary> |
jeffknaggs | 0:865d42c46692 | 78 | static void SetReflectiveSensorState(int state); |
jeffknaggs | 0:865d42c46692 | 79 | |
jeffknaggs | 0:865d42c46692 | 80 | |
jeffknaggs | 0:865d42c46692 | 81 | /// <summary> |
jeffknaggs | 0:865d42c46692 | 82 | /// The reflective sensors on the mBot. |
jeffknaggs | 0:865d42c46692 | 83 | /// </summary> |
jeffknaggs | 0:865d42c46692 | 84 | /// <summary> |
jeffknaggs | 0:865d42c46692 | 85 | /// Sets the period and duration that the buzzer will buzz for. |
jeffknaggs | 0:865d42c46692 | 86 | /// </summary> |
jeffknaggs | 0:865d42c46692 | 87 | /// <param name="period">The period that the buzzer will buzz in hertz.</param> |
jeffknaggs | 0:865d42c46692 | 88 | /// <param name="duration">The duration the buzzer will buzz for in milliseconds.</param> |
jeffknaggs | 0:865d42c46692 | 89 | /// <param name="dutyCycle">The duty cycle for the buzzer.</param> |
jeffknaggs | 0:865d42c46692 | 90 | /// <remarks>If duration is 0, the buzzer will buzz indefinitely. If it is non-zero, then mBot call will block for as many milliseconds as specified in duration, then return.</remarks> |
jeffknaggs | 0:865d42c46692 | 91 | |
jeffknaggs | 0:865d42c46692 | 92 | /// <summary> |
jeffknaggs | 0:865d42c46692 | 93 | /// Sets the speed of the motor. -100 is full speed backwards, 100 is full speed forward, and 0 is stopped. |
jeffknaggs | 0:865d42c46692 | 94 | /// </summary> |
jeffknaggs | 0:865d42c46692 | 95 | /// <param name="leftSpeed">The new speed of the left motor.</param> |
jeffknaggs | 0:865d42c46692 | 96 | /// <param name="rightSpeed">The new speed of the right motor.</param> |
jeffknaggs | 0:865d42c46692 | 97 | static void SetMotorSpeed(int leftSpeed, int rightSpeed); |
jeffknaggs | 0:865d42c46692 | 98 | |
jeffknaggs | 0:865d42c46692 | 99 | /// <summary> |
jeffknaggs | 0:865d42c46692 | 100 | /// Change the wheel directions (useful if you want to treat the batteries as the back of the robot and the wheels as the front). |
jeffknaggs | 0:865d42c46692 | 101 | /// </summary> |
jeffknaggs | 0:865d42c46692 | 102 | /// <param name="invertLeft">true then inverted.</param> |
jeffknaggs | 0:865d42c46692 | 103 | /// <param name="invertRight">true then inverted.</param> |
jeffknaggs | 0:865d42c46692 | 104 | static void SetMotorInversion(bool invertLeft, bool invertRight); |
jeffknaggs | 0:865d42c46692 | 105 | |
jeffknaggs | 0:865d42c46692 | 106 | |
jeffknaggs | 0:865d42c46692 | 107 | private: |
jeffknaggs | 0:865d42c46692 | 108 | static void SetSpeed(PwmOut *motor, DigitalOut *directionCtrl_1, DigitalOut *directionCtrl_2, int speed); //, bool isLeft); |
jeffknaggs | 0:865d42c46692 | 109 | }; |
jeffknaggs | 0:865d42c46692 | 110 |