Library for driving the IBT-2 H-bridge motor controller (with BTS 7960 or BTN 7971 half bridges).

See the Wiki tab for example code.

Committer:
rwunderl
Date:
Fri Jul 31 20:05:31 2015 +0000
Revision:
0:ea214158c2fb
Child:
1:fe72c69ab361
First commit of the IBT2 library.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rwunderl 0:ea214158c2fb 1 /* mbed IBT-2 H-bridge motor controller
rwunderl 0:ea214158c2fb 2 * Copyright (c) 2015, rwunderl, http://mbed.org
rwunderl 0:ea214158c2fb 3 *
rwunderl 0:ea214158c2fb 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
rwunderl 0:ea214158c2fb 5 * of this software and associated documentation files (the "Software"), to deal
rwunderl 0:ea214158c2fb 6 * in the Software without restriction, including without limitation the rights
rwunderl 0:ea214158c2fb 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
rwunderl 0:ea214158c2fb 8 * copies of the Software, and to permit persons to whom the Software is
rwunderl 0:ea214158c2fb 9 * furnished to do so, subject to the following conditions:
rwunderl 0:ea214158c2fb 10 *
rwunderl 0:ea214158c2fb 11 * The above copyright notice and this permission notice shall be included in
rwunderl 0:ea214158c2fb 12 * all copies or substantial portions of the Software.
rwunderl 0:ea214158c2fb 13 *
rwunderl 0:ea214158c2fb 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
rwunderl 0:ea214158c2fb 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
rwunderl 0:ea214158c2fb 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
rwunderl 0:ea214158c2fb 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
rwunderl 0:ea214158c2fb 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
rwunderl 0:ea214158c2fb 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
rwunderl 0:ea214158c2fb 20 * THE SOFTWARE.
rwunderl 0:ea214158c2fb 21 */
rwunderl 0:ea214158c2fb 22
rwunderl 0:ea214158c2fb 23 #ifndef MBED_IBT2_H
rwunderl 0:ea214158c2fb 24 #define MBED_IBT2_H
rwunderl 0:ea214158c2fb 25
rwunderl 0:ea214158c2fb 26 #include "mbed.h"
rwunderl 0:ea214158c2fb 27
rwunderl 0:ea214158c2fb 28 /** Interface to the IBT-2 H-bridge motor controller
rwunderl 0:ea214158c2fb 29 *
rwunderl 0:ea214158c2fb 30 * Control a DC motor connected to the IBT-2 H-bridge using one of two modes:
rwunderl 0:ea214158c2fb 31 * Mode 1:
rwunderl 0:ea214158c2fb 32 * 2 PwmOuts and 1 DigitalOut
rwunderl 0:ea214158c2fb 33 * - L_PWM controlled with a PwmOut
rwunderl 0:ea214158c2fb 34 * - R_PWM controlled with a PwmOut
rwunderl 0:ea214158c2fb 35 * - L_EN, R_EN connected to a DigitalOut (High is Enabled)
rwunderl 0:ea214158c2fb 36 * Mode 1:
rwunderl 0:ea214158c2fb 37 * 2 PwmOuts and 1 DigitalOut
rwunderl 0:ea214158c2fb 38 * - L_PWM controlled with a PwmOut
rwunderl 0:ea214158c2fb 39 * - R_PWM controlled with a PwmOut
rwunderl 0:ea214158c2fb 40 * - L_EN, R_EN connected to a DigitalOut (High is Enabled)
rwunderl 0:ea214158c2fb 41 * For now, only Mode 1 is used.
rwunderl 0:ea214158c2fb 42 */
rwunderl 0:ea214158c2fb 43 class IBT2 {
rwunderl 0:ea214158c2fb 44 public:
rwunderl 0:ea214158c2fb 45 /** Create an IBT-2 control interface
rwunderl 0:ea214158c2fb 46 *
rwunderl 0:ea214158c2fb 47 * @param L_pwm A PwmOut pin, driving the L_PWM H-bridge line to control the forward speed.
rwunderl 0:ea214158c2fb 48 * @param R_pwm A PwmOut pin, driving the R_PWM H-bridge line to control the reverse speed.
rwunderl 0:ea214158c2fb 49 * @param en A DigitalOut pin, driving the L_EN and R_EN H-bridge enable lines.
rwunderl 0:ea214158c2fb 50 * @param freq The frequency of the H-bridge PWM lines in Hz.
rwunderl 0:ea214158c2fb 51 */
rwunderl 0:ea214158c2fb 52 IBT2(PinName L_pwm, PinName R_pwm, PinName en, float freq);
rwunderl 0:ea214158c2fb 53
rwunderl 0:ea214158c2fb 54 /** Set the speed and direction of the motor
rwunderl 0:ea214158c2fb 55 *
rwunderl 0:ea214158c2fb 56 * @param speed The speed of the motor as a normalized value between -1.0 and 1.0. Use a positive value for forward and a negative value for reverse.
rwunderl 0:ea214158c2fb 57 */
rwunderl 0:ea214158c2fb 58 void setSpeed(float speed);
rwunderl 0:ea214158c2fb 59
rwunderl 0:ea214158c2fb 60 /** Get the speed and direction of the motor
rwunderl 0:ea214158c2fb 61 *
rwunderl 0:ea214158c2fb 62 * @returns float The speed of the motor as a normalized value between -1.0 and 1.0. A positive value is forward and a negative value is reverse.
rwunderl 0:ea214158c2fb 63 */
rwunderl 0:ea214158c2fb 64 float getSpeed(void);
rwunderl 0:ea214158c2fb 65
rwunderl 0:ea214158c2fb 66 protected:
rwunderl 0:ea214158c2fb 67 PwmOut _L_pwm;
rwunderl 0:ea214158c2fb 68 PwmOut _R_pwm;
rwunderl 0:ea214158c2fb 69 DigitalOut _en;
rwunderl 0:ea214158c2fb 70 float _period;
rwunderl 0:ea214158c2fb 71 float _speed;
rwunderl 0:ea214158c2fb 72 };
rwunderl 0:ea214158c2fb 73
rwunderl 0:ea214158c2fb 74 #endif /* MBED_IBT2_H */