Psi Swarm robot library version 0.9

Fork of PsiSwarmV9 by Psi Swarm Robot

Committer:
jah128
Date:
Mon May 14 15:35:38 2018 +0000
Revision:
20:1bc6c6dc477b
Parent:
18:9204f74069b4
Updated?

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jah128 0:d6269d17c8cf 1 /* University of York Robotics Laboratory PsiSwarm Library: Motor Functions Header File
jah128 8:6c92789d5f87 2 *
jah128 16:50686c07ad07 3 * Copyright 2017 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 16:50686c07ad07 16 * PsiSwarm Library Version: 0.9
jah128 0:d6269d17c8cf 17 *
jah128 16:50686c07ad07 18 * June 2017
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 18:9204f74069b4 96
jah128 18:9204f74069b4 97 /** Motor calibration routine
jah128 18:9204f74069b4 98 * Calculates stall and speed offsets for motors, stores in EEPROM
jah128 18:9204f74069b4 99 */
jah128 18:9204f74069b4 100 void calibrate_motors(void);
jah128 8:6c92789d5f87 101
jah128 8:6c92789d5f87 102 // New time based functions (added in library v0.3)
jah128 0:d6269d17c8cf 103
jah128 8:6c92789d5f87 104 /** Make the robot move forward for a predetermined amount of time
jah128 8:6c92789d5f87 105 * @param speed - Sets the motors to the specified speed (range -1.0 for max. forward to 1.0 for max. reverse)
jah128 8:6c92789d5f87 106 * @param microseconds - The duration to keep moving
jah128 8:6c92789d5f87 107 * @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 108 */
jah128 8:6c92789d5f87 109 void time_based_forward(float speed, int microseconds, char brake);
jah128 8:6c92789d5f87 110
jah128 8:6c92789d5f87 111 /** Make the robot turn for a predetermined amount of time
jah128 8:6c92789d5f87 112 * @param speed - Sets the turning speed (range -1.0 for max. counter-clockwise to 1.0 for max. clockwise)
jah128 8:6c92789d5f87 113 * @param microseconds - The duration to keep moving
jah128 8:6c92789d5f87 114 * @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 115 */
jah128 8:6c92789d5f87 116 void time_based_turn(float speed, int microseconds, char brake);
jah128 0:d6269d17c8cf 117
jah128 8:6c92789d5f87 118 int time_based_turn_degrees(float speed, float degrees, char brake);
jah128 8:6c92789d5f87 119 float get_maximum_turn_angle(int microseconds);
jah128 8:6c92789d5f87 120 int get_time_based_turn_time(float speed, float degrees);
jah128 8:6c92789d5f87 121
jah128 8:6c92789d5f87 122 private:
jah128 8:6c92789d5f87 123 void IF_check_time_for_existing_time_based_action();
jah128 8:6c92789d5f87 124 void IF_end_time_based_action();
jah128 8:6c92789d5f87 125 void IF_update_motors();
jah128 8:6c92789d5f87 126 float IF_calibrated_left_speed(float speed);
jah128 8:6c92789d5f87 127 float IF_calibrated_right_speed(float speed);
jah128 18:9204f74069b4 128 //float IF_calibrated_speed(float speed);
jah128 8:6c92789d5f87 129
jah128 8:6c92789d5f87 130 };
jah128 0:d6269d17c8cf 131 #endif