Practical Robotics Modular Robot Library

Dependents:   ModularRobot

motors.h

Committer:
jah128
Date:
2016-11-26
Revision:
1:a6728adaf7e7
Parent:
0:8a2dd255c508
Child:
3:8762f6b2ea8d

File content as of revision 1:a6728adaf7e7:

#ifndef MOTORS_H
#define MOTORS_H

/**
 *  The Motors class contains the functions to control the robots motors
 */
class Motors
{
public:
    /**
    * Setup the PWM based H-Bridge drivers for the motors
    */
    void init(void);
    
    
    /**
     * Put the H-Bridge drivers in sleep (low-power) mode
     */ 
    void sleep(void);
    
    /**
     * Wake the H-Bridge drivers from sleep mode
     */
    void wake_up(void);
    
    /**
     * Set the left H-Bridge driver to high-Z (coast mode) for the motor
     */
    void coast_left(void);
    
    /**
     * Set the left H-Bridge driver to active brake
     */
    void brake_left(void);
    
    /**
     * Set the speed and direction of the left-motor H-Bridge driver
     *
     * @param speed - A value between -1.0 [max reverse], 0 [coast] and 1.0 [max forward]
     */
    void set_left_motor_speed(float speed);
    
    /**
     * Set the right H-Bridge driver to high-Z (coast mode) for the motor
     */
    void coast_right(void);
    
    /**
     * Set the right H-Bridge driver to active brake
     */
    void brake_right(void);
    
    /**
     * Set both H-Bridge drivers to high-Z (coast mode) for the motor
     */
    void coast(void);
    
     /**
     * Set both H-Bridge drivers to active brake
     */
    void brake(void);
    
    /**
     * Set the speed and direction of the right-motor H-Bridge driver
     *
     * @param speed - A value between -1.0 [max reverse], 0 [coast] and 1.0 [max forward]
     */
    void set_right_motor_speed(float speed);
    
    /**
     * Get the approximate instantaneous current draw of the left-motor H-Bridge driver
     *
     * @returns The current value in A
     */
    float get_current_left(void);
    
    /**
     * Get the approximate instantaneous current draw of the right-motor H-Bridge driver
     *
     * @returns The current value in A
     */
    float get_current_right(void);
    
    /**
     * Calculates an adjusted speed value to avoid stalls at low-speeds if USE_STALL_OFFSET is set to 1 [in robot.h]
     * @params speed_in - The speed value from 0.0 to 1.0
     * @returns The adjusted speed value from 0.0 to 1.0, increased by STALL_OFFSET then scaled to fit
     */
    float get_adjusted_speed(float speed_in);
    

};

#endif