Kallums Fork
Fork of SteeringServo by
Embed:
(wiki syntax)
Show/hide line numbers
SteeringServo.h
00001 #ifndef SteeringServo_H 00002 #define SteeringServo_H 00003 #include "mbed.h" 00004 00005 /** NAME: SteeringServo 00006 * AUTHOR: J.BATCHELAR 00007 * 00008 * @section LICENSE 00009 * 00010 * Permission is hereby granted, free of charge, to any person obtaining a copy 00011 * of this software and associated documentation files (the "Software"), to deal 00012 * in the Software without restriction, including without limitation the rights 00013 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00014 * copies of the Software, and to permit persons to whom the Software is 00015 * furnished to do so, subject to the following conditions: 00016 * 00017 * The above copyright notice and this permission notice shall be included in 00018 * all copies or substantial portions of the Software. 00019 * 00020 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00021 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00022 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00023 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00024 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00025 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00026 * THE SOFTWARE. 00027 * 00028 * @section DESCRIPTION 00029 * 00030 * Used with Tower Pro 9g Servo Motors (http://www.micropik.com/PDF/SG90Servo.pdf) to create a steering mechanism. 00031 * 00032 * Example: 00033 * @code 00034 00035 // -- Code to move steering wheel between extreme limits 00036 #include "mbed.h" 00037 #include "SteeringServo.h" 00038 00039 DigitalIn bttn(PC_13); 00040 DigitalOut led(LED1); 00041 00042 Serial pc(USBTX, USBRX); 00043 SteeringServo steerMech(PA_10, 1650, 1000, 2300); 00044 00045 int main() { 00046 led = 1; 00047 pc.printf("\nServo Example\n"); 00048 00049 while(1){ 00050 steerMech.goStraight(); //-- Don't call constantly(as you are writing into register need to allow time for value to set)! 00051 //-- Wait for button to be pressed 00052 while(bttn){}; 00053 steerMech.goToAngle(1000); //-- Go Left 00054 wait(5); 00055 steerMech.goToAngle(2300); //-- Go Left 00056 wait(5); 00057 } 00058 } 00059 00060 * @endcode 00061 */ 00062 00063 class SteeringServo{ 00064 public: 00065 /** Create a Clamp Servo Object 00066 * 00067 * @param pin The PWM Pin that the Servo Is Connected To 00068 * @param centrePW (us) - Pulse Width to move to drive straight 00069 * @param minPW (us) - Minimum pulse width that servo can move to (due to mechanical constraints) 00070 * @param maxPW (us) - Maximum pulse width that servo can move to (due to mechanical constraints) 00071 */ 00072 SteeringServo(PinName pin, int centrePW, int minPW, int maxPW); 00073 00074 /** Check if the Clamp is Open 00075 * @param pulseWidth (us) - Pulse Width to move rotate to (is internally constrained by limits) 00076 */ 00077 void goToAngle(int pulseWidth); 00078 00079 00080 /** Goto the centre position. (Drive Straight) 00081 * 00082 */ 00083 void goStraight(void); 00084 00085 /** Get the currentPulseWidth 00086 * 00087 */ 00088 int getPulseWidth(void); 00089 00090 private: 00091 PwmOut servo_; // -- PWM Object 00092 int minimumPulseWidth_; // -- (us) Minimum pulse width that servo can move to (due to mechanical constraints) 00093 int maximumPulseWidth_; // -- (us) Maximum pulse width that servo can move to (due to mechanical constraints) 00094 int centrePulseWidth_; // -- (us) Pulse Width to move to drive straight 00095 int currentPulseWidth_; // -- (us) Current Pulse Width of the servo 00096 }; 00097 00098 #endif
Generated on Wed Jul 13 2022 17:25:00 by
1.7.2
