C++ Library for the PsiSwarm Robot - Version 0.8

Dependents:   PsiSwarm_V8_Blank_CPP Autonomia_RndmWlk

Fork of PsiSwarmV7_CPP by Psi Swarm Robot

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers motors.h Source File

motors.h

00001 /* University of York Robotics Laboratory PsiSwarm Library: Motor Functions Header File
00002  *
00003  * Copyright 2016 University of York
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
00007  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS
00008  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00009  * See the License for the specific language governing permissions and limitations under the License.
00010  *
00011  * File: motors.h
00012  *
00013  * (C) Dept. Electronics & Computer Science, University of York
00014  * James Hilder, Alan Millard, Alexander Horsfield, Homero Elizondo, Jon Timmis
00015  *
00016  * PsiSwarm Library Version: 0.8
00017  *
00018  * October 2016
00019  *
00020  *
00021  */
00022 
00023 #ifndef MOTORS_H
00024 #define MOTORS_H
00025 
00026 /**
00027  * Motors class
00028  * Functions to control the Psi Swarm robot motors
00029  *
00030  * Example:
00031  * @code
00032  * #include "psiswarm.h"
00033  *
00034  * int main() {
00035  *     init();
00036  *     motors.forward(0.5);    //Set the motors to forward at speed 0.5
00037  *     wait(0.5);
00038  *     motors.brake();         //Enable the hardware brake
00039  *     wait(0.5);
00040  *     motors.turn(0.5);       //Turn clockwise at 50% speed
00041  *     wait(0.5);
00042  *     motors.stop();          //Sets motor speed to zero (but not hardware brake)
00043  * }
00044  * @endcode
00045 */
00046 class Motors
00047 {
00048 public:
00049 
00050     /** Set the left motor to the specified speed
00051     * @param speed - The set motor to the specified (range -1.0 for max. reverse to 1.0 for max. forward)
00052     */
00053     void set_left_motor_speed(float speed);
00054 
00055     /** Set the left motor to the specified speed
00056     * @param speed - The set motor to the specified (range -1.0 for max. reverse to 1.0 for max. forward)
00057     */
00058     void set_right_motor_speed(float speed);
00059 
00060     /** Enable the active brake on the left motor
00061     */
00062     void brake_left_motor(void);
00063 
00064     /** Enable the active brake on the right motor
00065     */
00066     void brake_right_motor(void);
00067 
00068     /** Enable the active brake on the both motors
00069     */
00070     void brake(void);
00071 
00072     /** Stop both motors
00073     * This sets the speed of both motors to 0; it does not enable the active brake
00074     */
00075     void stop(void);
00076 
00077     /** Sets both motors to the specified speed
00078     * @param speed - Set the motors to the specified speed (range -1.0 for max. reverse to 1.0 for max. forward)
00079     */
00080     void forward(float speed);
00081 
00082     /** Sets both motors to the specified inverted speed
00083     * @param speed - Set the motors to the specified speed (range -1.0 for max. forward to 1.0 for max. reverse)
00084     */
00085     void backward(float speed);
00086 
00087     /** Turn the robot on the spot by setting motors to equal and opposite speeds
00088     * @param speed - Sets the turning speed (range -1.0 for max. counter-clockwise to 1.0 for max. clockwise)
00089     */
00090     void turn(float speed);
00091 
00092     /** Initialise the PWM settings for the motors
00093     *
00094     */
00095     void init_motors(void);
00096 
00097     // New time based functions (added in library v0.3)
00098 
00099     /** Make the robot move forward for a predetermined amount of time
00100     * @param speed - Sets the motors to the specified speed (range -1.0 for max. forward to 1.0 for max. reverse)
00101     * @param microseconds - The duration to keep moving
00102     * @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
00103     */
00104     void time_based_forward(float speed, int microseconds, char brake);
00105 
00106     /** Make the robot turn for a predetermined amount of time
00107     * @param speed - Sets the turning speed (range -1.0 for max. counter-clockwise to 1.0 for max. clockwise)
00108     * @param microseconds - The duration to keep moving
00109     * @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
00110     */
00111     void time_based_turn(float speed, int microseconds, char brake);
00112 
00113     int time_based_turn_degrees(float speed, float degrees, char brake);
00114     float get_maximum_turn_angle(int microseconds);
00115     int get_time_based_turn_time(float speed, float degrees);
00116 
00117 private:
00118     void IF_check_time_for_existing_time_based_action();
00119     void IF_end_time_based_action();
00120     void IF_update_motors();
00121     float IF_calibrated_left_speed(float speed);
00122     float IF_calibrated_right_speed(float speed);
00123     float IF_calibrated_speed(float speed);
00124 
00125 };
00126 #endif