Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
IBT2.h
00001 /* mbed IBT-2 H-bridge motor controller 00002 * Copyright (c) 2015, rwunderl, http://mbed.org 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a copy 00005 * of this software and associated documentation files (the "Software"), to deal 00006 * in the Software without restriction, including without limitation the rights 00007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00008 * copies of the Software, and to permit persons to whom the Software is 00009 * furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included in 00012 * all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00020 * THE SOFTWARE. 00021 */ 00022 00023 #ifndef MBED_IBT2_H 00024 #define MBED_IBT2_H 00025 00026 #include "mbed.h" 00027 00028 /** Interface to the IBT-2 H-bridge motor controller 00029 * 00030 * Control a DC motor connected to the IBT-2 H-bridge using one of two modes: 00031 * 00032 * Mode 1: 00033 * 2 PwmOuts and 1 DigitalOut 00034 * - L_PWM controlled with a PwmOut 00035 * - R_PWM controlled with a PwmOut 00036 * - L_EN, R_EN connected to a DigitalOut (High is Enabled) 00037 * 00038 * Mode 2: 00039 * 1 PwmOut and 2 DigitalOuts 00040 * - L_PWM connected to a DigitalOut (High is Forward; keep R_PWM Low) 00041 * - R_PWM connected to a DigitalOut (High is Reverse; keep L_PWM Low) 00042 * - L_EN, R_EN controlled with a PwmOut 00043 * 00044 * For now, only Mode 1 is used. 00045 */ 00046 class IBT2 { 00047 public: 00048 /** Create an IBT-2 control interface 00049 * 00050 * @param L_pwm A PwmOut pin, driving the L_PWM H-bridge line to control the forward speed. 00051 * @param R_pwm A PwmOut pin, driving the R_PWM H-bridge line to control the reverse speed. 00052 * @param en A DigitalOut pin, driving the L_EN and R_EN H-bridge enable lines. 00053 * @param freq The frequency of the H-bridge PWM lines in Hz. 00054 */ 00055 IBT2(PinName L_pwm, PinName R_pwm, PinName en, float freq); 00056 00057 /** Set the speed and direction of the motor 00058 * 00059 * @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. 00060 */ 00061 void setSpeed(float speed); 00062 00063 /** Get the speed and direction of the motor 00064 * 00065 * @returns 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. 00066 */ 00067 float getSpeed(void); 00068 00069 protected: 00070 PwmOut _L_pwm; 00071 PwmOut _R_pwm; 00072 DigitalOut _en; 00073 float _period; 00074 float _speed; 00075 }; 00076 00077 #endif /* MBED_IBT2_H */
Generated on Fri Jul 29 2022 08:25:18 by
1.7.2