C++ Library for the PsiSwarm Robot - Version 0.8
Dependents: PsiSwarm_V8_Blank_CPP Autonomia_RndmWlk
Fork of PsiSwarmV7_CPP by
motors.h@8:6c92789d5f87, 2016-10-16 (annotated)
- Committer:
- jah128
- Date:
- Sun Oct 16 12:54:33 2016 +0000
- Revision:
- 8:6c92789d5f87
- Parent:
- 6:b340a527add9
Renamed to V8 [C++ version]; converted display, eprom and motor classes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jah128 | 0:d6269d17c8cf | 1 | /* University of York Robotics Laboratory PsiSwarm Library: Motor Functions Header File |
jah128 | 8:6c92789d5f87 | 2 | * |
jah128 | 6:b340a527add9 | 3 | * Copyright 2016 University of York |
jah128 | 6:b340a527add9 | 4 | * |
jah128 | 8:6c92789d5f87 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. |
jah128 | 6:b340a527add9 | 6 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
jah128 | 6:b340a527add9 | 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS |
jah128 | 8:6c92789d5f87 | 8 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
jah128 | 6:b340a527add9 | 9 | * See the License for the specific language governing permissions and limitations under the License. |
jah128 | 6:b340a527add9 | 10 | * |
jah128 | 0:d6269d17c8cf | 11 | * File: motors.h |
jah128 | 0:d6269d17c8cf | 12 | * |
jah128 | 0:d6269d17c8cf | 13 | * (C) Dept. Electronics & Computer Science, University of York |
jah128 | 0:d6269d17c8cf | 14 | * James Hilder, Alan Millard, Alexander Horsfield, Homero Elizondo, Jon Timmis |
jah128 | 0:d6269d17c8cf | 15 | * |
jah128 | 8:6c92789d5f87 | 16 | * PsiSwarm Library Version: 0.8 |
jah128 | 0:d6269d17c8cf | 17 | * |
jah128 | 5:3cdd1a37cdd7 | 18 | * October 2016 |
jah128 | 0:d6269d17c8cf | 19 | * |
jah128 | 0:d6269d17c8cf | 20 | * |
jah128 | 8:6c92789d5f87 | 21 | */ |
jah128 | 0:d6269d17c8cf | 22 | |
jah128 | 0:d6269d17c8cf | 23 | #ifndef MOTORS_H |
jah128 | 0:d6269d17c8cf | 24 | #define MOTORS_H |
jah128 | 0:d6269d17c8cf | 25 | |
jah128 | 8:6c92789d5f87 | 26 | /** |
jah128 | 8:6c92789d5f87 | 27 | * Motors class |
jah128 | 8:6c92789d5f87 | 28 | * Functions to control the Psi Swarm robot motors |
jah128 | 8:6c92789d5f87 | 29 | * |
jah128 | 8:6c92789d5f87 | 30 | * Example: |
jah128 | 8:6c92789d5f87 | 31 | * @code |
jah128 | 8:6c92789d5f87 | 32 | * #include "psiswarm.h" |
jah128 | 8:6c92789d5f87 | 33 | * |
jah128 | 8:6c92789d5f87 | 34 | * int main() { |
jah128 | 8:6c92789d5f87 | 35 | * init(); |
jah128 | 8:6c92789d5f87 | 36 | * motors.forward(0.5); //Set the motors to forward at speed 0.5 |
jah128 | 8:6c92789d5f87 | 37 | * wait(0.5); |
jah128 | 8:6c92789d5f87 | 38 | * motors.brake(); //Enable the hardware brake |
jah128 | 8:6c92789d5f87 | 39 | * wait(0.5); |
jah128 | 8:6c92789d5f87 | 40 | * motors.turn(0.5); //Turn clockwise at 50% speed |
jah128 | 8:6c92789d5f87 | 41 | * wait(0.5); |
jah128 | 8:6c92789d5f87 | 42 | * motors.stop(); //Sets motor speed to zero (but not hardware brake) |
jah128 | 8:6c92789d5f87 | 43 | * } |
jah128 | 8:6c92789d5f87 | 44 | * @endcode |
jah128 | 8:6c92789d5f87 | 45 | */ |
jah128 | 8:6c92789d5f87 | 46 | class Motors |
jah128 | 8:6c92789d5f87 | 47 | { |
jah128 | 8:6c92789d5f87 | 48 | public: |
jah128 | 8:6c92789d5f87 | 49 | |
jah128 | 8:6c92789d5f87 | 50 | /** Set the left motor to the specified speed |
jah128 | 8:6c92789d5f87 | 51 | * @param speed - The set motor to the specified (range -1.0 for max. reverse to 1.0 for max. forward) |
jah128 | 8:6c92789d5f87 | 52 | */ |
jah128 | 8:6c92789d5f87 | 53 | void set_left_motor_speed(float speed); |
jah128 | 8:6c92789d5f87 | 54 | |
jah128 | 8:6c92789d5f87 | 55 | /** Set the left motor to the specified speed |
jah128 | 8:6c92789d5f87 | 56 | * @param speed - The set motor to the specified (range -1.0 for max. reverse to 1.0 for max. forward) |
jah128 | 8:6c92789d5f87 | 57 | */ |
jah128 | 8:6c92789d5f87 | 58 | void set_right_motor_speed(float speed); |
jah128 | 8:6c92789d5f87 | 59 | |
jah128 | 8:6c92789d5f87 | 60 | /** Enable the active brake on the left motor |
jah128 | 8:6c92789d5f87 | 61 | */ |
jah128 | 8:6c92789d5f87 | 62 | void brake_left_motor(void); |
jah128 | 8:6c92789d5f87 | 63 | |
jah128 | 8:6c92789d5f87 | 64 | /** Enable the active brake on the right motor |
jah128 | 8:6c92789d5f87 | 65 | */ |
jah128 | 8:6c92789d5f87 | 66 | void brake_right_motor(void); |
jah128 | 8:6c92789d5f87 | 67 | |
jah128 | 8:6c92789d5f87 | 68 | /** Enable the active brake on the both motors |
jah128 | 8:6c92789d5f87 | 69 | */ |
jah128 | 8:6c92789d5f87 | 70 | void brake(void); |
jah128 | 8:6c92789d5f87 | 71 | |
jah128 | 8:6c92789d5f87 | 72 | /** Stop both motors |
jah128 | 8:6c92789d5f87 | 73 | * This sets the speed of both motors to 0; it does not enable the active brake |
jah128 | 8:6c92789d5f87 | 74 | */ |
jah128 | 8:6c92789d5f87 | 75 | void stop(void); |
jah128 | 0:d6269d17c8cf | 76 | |
jah128 | 8:6c92789d5f87 | 77 | /** Sets both motors to the specified speed |
jah128 | 8:6c92789d5f87 | 78 | * @param speed - Set the motors to the specified speed (range -1.0 for max. reverse to 1.0 for max. forward) |
jah128 | 8:6c92789d5f87 | 79 | */ |
jah128 | 8:6c92789d5f87 | 80 | void forward(float speed); |
jah128 | 8:6c92789d5f87 | 81 | |
jah128 | 8:6c92789d5f87 | 82 | /** Sets both motors to the specified inverted speed |
jah128 | 8:6c92789d5f87 | 83 | * @param speed - Set the motors to the specified speed (range -1.0 for max. forward to 1.0 for max. reverse) |
jah128 | 8:6c92789d5f87 | 84 | */ |
jah128 | 8:6c92789d5f87 | 85 | void backward(float speed); |
jah128 | 8:6c92789d5f87 | 86 | |
jah128 | 8:6c92789d5f87 | 87 | /** Turn the robot on the spot by setting motors to equal and opposite speeds |
jah128 | 8:6c92789d5f87 | 88 | * @param speed - Sets the turning speed (range -1.0 for max. counter-clockwise to 1.0 for max. clockwise) |
jah128 | 8:6c92789d5f87 | 89 | */ |
jah128 | 8:6c92789d5f87 | 90 | void turn(float speed); |
jah128 | 8:6c92789d5f87 | 91 | |
jah128 | 8:6c92789d5f87 | 92 | /** Initialise the PWM settings for the motors |
jah128 | 8:6c92789d5f87 | 93 | * |
jah128 | 8:6c92789d5f87 | 94 | */ |
jah128 | 8:6c92789d5f87 | 95 | void init_motors(void); |
jah128 | 8:6c92789d5f87 | 96 | |
jah128 | 8:6c92789d5f87 | 97 | // New time based functions (added in library v0.3) |
jah128 | 0:d6269d17c8cf | 98 | |
jah128 | 8:6c92789d5f87 | 99 | /** Make the robot move forward for a predetermined amount of time |
jah128 | 8:6c92789d5f87 | 100 | * @param speed - Sets the motors to the specified speed (range -1.0 for max. forward to 1.0 for max. reverse) |
jah128 | 8:6c92789d5f87 | 101 | * @param microseconds - The duration to keep moving |
jah128 | 8:6c92789d5f87 | 102 | * @param brake - If set to 1, the brake instruction will be applied at the end of the move, else motors are just set to stop |
jah128 | 8:6c92789d5f87 | 103 | */ |
jah128 | 8:6c92789d5f87 | 104 | void time_based_forward(float speed, int microseconds, char brake); |
jah128 | 8:6c92789d5f87 | 105 | |
jah128 | 8:6c92789d5f87 | 106 | /** Make the robot turn for a predetermined amount of time |
jah128 | 8:6c92789d5f87 | 107 | * @param speed - Sets the turning speed (range -1.0 for max. counter-clockwise to 1.0 for max. clockwise) |
jah128 | 8:6c92789d5f87 | 108 | * @param microseconds - The duration to keep moving |
jah128 | 8:6c92789d5f87 | 109 | * @param brake - If set to 1, the brake instruction will be applied at the end of the move, else motors are just set to stop |
jah128 | 8:6c92789d5f87 | 110 | */ |
jah128 | 8:6c92789d5f87 | 111 | void time_based_turn(float speed, int microseconds, char brake); |
jah128 | 0:d6269d17c8cf | 112 | |
jah128 | 8:6c92789d5f87 | 113 | int time_based_turn_degrees(float speed, float degrees, char brake); |
jah128 | 8:6c92789d5f87 | 114 | float get_maximum_turn_angle(int microseconds); |
jah128 | 8:6c92789d5f87 | 115 | int get_time_based_turn_time(float speed, float degrees); |
jah128 | 8:6c92789d5f87 | 116 | |
jah128 | 8:6c92789d5f87 | 117 | private: |
jah128 | 8:6c92789d5f87 | 118 | void IF_check_time_for_existing_time_based_action(); |
jah128 | 8:6c92789d5f87 | 119 | void IF_end_time_based_action(); |
jah128 | 8:6c92789d5f87 | 120 | void IF_update_motors(); |
jah128 | 8:6c92789d5f87 | 121 | float IF_calibrated_left_speed(float speed); |
jah128 | 8:6c92789d5f87 | 122 | float IF_calibrated_right_speed(float speed); |
jah128 | 8:6c92789d5f87 | 123 | float IF_calibrated_speed(float speed); |
jah128 | 8:6c92789d5f87 | 124 | |
jah128 | 8:6c92789d5f87 | 125 | }; |
jah128 | 0:d6269d17c8cf | 126 | #endif |