ロケット用プログラム

Dependencies:   mbed

Committer:
ishiyamayuto
Date:
Wed Sep 11 06:37:20 2019 +0000
Revision:
0:d58274531d38
BMP180,MPU6050

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ishiyamayuto 0:d58274531d38 1 /* mbed R/C Servo Library
ishiyamayuto 0:d58274531d38 2 * Copyright (c) 2007-2010 sford, cstyles
ishiyamayuto 0:d58274531d38 3 *
ishiyamayuto 0:d58274531d38 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
ishiyamayuto 0:d58274531d38 5 * of this software and associated documentation files (the "Software"), to deal
ishiyamayuto 0:d58274531d38 6 * in the Software without restriction, including without limitation the rights
ishiyamayuto 0:d58274531d38 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
ishiyamayuto 0:d58274531d38 8 * copies of the Software, and to permit persons to whom the Software is
ishiyamayuto 0:d58274531d38 9 * furnished to do so, subject to the following conditions:
ishiyamayuto 0:d58274531d38 10 *
ishiyamayuto 0:d58274531d38 11 * The above copyright notice and this permission notice shall be included in
ishiyamayuto 0:d58274531d38 12 * all copies or substantial portions of the Software.
ishiyamayuto 0:d58274531d38 13 *
ishiyamayuto 0:d58274531d38 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
ishiyamayuto 0:d58274531d38 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
ishiyamayuto 0:d58274531d38 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
ishiyamayuto 0:d58274531d38 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
ishiyamayuto 0:d58274531d38 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ishiyamayuto 0:d58274531d38 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
ishiyamayuto 0:d58274531d38 20 * THE SOFTWARE.
ishiyamayuto 0:d58274531d38 21 */
ishiyamayuto 0:d58274531d38 22
ishiyamayuto 0:d58274531d38 23 #ifndef MBED_SERVO_H
ishiyamayuto 0:d58274531d38 24 #define MBED_SERVO_H
ishiyamayuto 0:d58274531d38 25
ishiyamayuto 0:d58274531d38 26 #include "mbed.h"
ishiyamayuto 0:d58274531d38 27
ishiyamayuto 0:d58274531d38 28 /** Servo control class, based on a PwmOut
ishiyamayuto 0:d58274531d38 29 *
ishiyamayuto 0:d58274531d38 30 * Example:
ishiyamayuto 0:d58274531d38 31 * @code
ishiyamayuto 0:d58274531d38 32 * // Continuously sweep the servo through it's full range
ishiyamayuto 0:d58274531d38 33 * #include "mbed.h"
ishiyamayuto 0:d58274531d38 34 * #include "Servo.h"
ishiyamayuto 0:d58274531d38 35 *
ishiyamayuto 0:d58274531d38 36 * Servo myservo(p21);
ishiyamayuto 0:d58274531d38 37 *
ishiyamayuto 0:d58274531d38 38 * int main() {
ishiyamayuto 0:d58274531d38 39 * while(1) {
ishiyamayuto 0:d58274531d38 40 * for(int i=0; i<100; i++) {
ishiyamayuto 0:d58274531d38 41 * myservo = i/100.0;
ishiyamayuto 0:d58274531d38 42 * wait(0.01);
ishiyamayuto 0:d58274531d38 43 * }
ishiyamayuto 0:d58274531d38 44 * for(int i=100; i>0; i--) {
ishiyamayuto 0:d58274531d38 45 * myservo = i/100.0;
ishiyamayuto 0:d58274531d38 46 * wait(0.01);
ishiyamayuto 0:d58274531d38 47 * }
ishiyamayuto 0:d58274531d38 48 * }
ishiyamayuto 0:d58274531d38 49 * }
ishiyamayuto 0:d58274531d38 50 * @endcode
ishiyamayuto 0:d58274531d38 51 */
ishiyamayuto 0:d58274531d38 52 class Servo {
ishiyamayuto 0:d58274531d38 53
ishiyamayuto 0:d58274531d38 54 public:
ishiyamayuto 0:d58274531d38 55 /** Create a servo object connected to the specified PwmOut pin
ishiyamayuto 0:d58274531d38 56 *
ishiyamayuto 0:d58274531d38 57 * @param pin PwmOut pin to connect to
ishiyamayuto 0:d58274531d38 58 */
ishiyamayuto 0:d58274531d38 59 Servo(PinName pin);
ishiyamayuto 0:d58274531d38 60
ishiyamayuto 0:d58274531d38 61 /** Set the servo position, normalised to it's full range
ishiyamayuto 0:d58274531d38 62 *
ishiyamayuto 0:d58274531d38 63 * @param percent A normalised number 0.0-1.0 to represent the full range.
ishiyamayuto 0:d58274531d38 64 */
ishiyamayuto 0:d58274531d38 65 void write(float percent);
ishiyamayuto 0:d58274531d38 66
ishiyamayuto 0:d58274531d38 67 /** Read the servo motors current position
ishiyamayuto 0:d58274531d38 68 *
ishiyamayuto 0:d58274531d38 69 * @param returns A normalised number 0.0-1.0 representing the full range.
ishiyamayuto 0:d58274531d38 70 */
ishiyamayuto 0:d58274531d38 71 float read();
ishiyamayuto 0:d58274531d38 72
ishiyamayuto 0:d58274531d38 73 /** Set the servo position
ishiyamayuto 0:d58274531d38 74 *
ishiyamayuto 0:d58274531d38 75 * @param degrees Servo position in degrees
ishiyamayuto 0:d58274531d38 76 */
ishiyamayuto 0:d58274531d38 77 void position(float degrees);
ishiyamayuto 0:d58274531d38 78
ishiyamayuto 0:d58274531d38 79 /** Allows calibration of the range and angles for a particular servo
ishiyamayuto 0:d58274531d38 80 *
ishiyamayuto 0:d58274531d38 81 * @param range Pulsewidth range from center (1.5ms) to maximum/minimum position in seconds
ishiyamayuto 0:d58274531d38 82 * @param degrees Angle from centre to maximum/minimum position in degrees
ishiyamayuto 0:d58274531d38 83 */
ishiyamayuto 0:d58274531d38 84 void calibrate(float range = 0.0005, float degrees = 45.0);
ishiyamayuto 0:d58274531d38 85
ishiyamayuto 0:d58274531d38 86 /** Shorthand for the write and read functions */
ishiyamayuto 0:d58274531d38 87 Servo& operator= (float percent);
ishiyamayuto 0:d58274531d38 88 Servo& operator= (Servo& rhs);
ishiyamayuto 0:d58274531d38 89 operator float();
ishiyamayuto 0:d58274531d38 90
ishiyamayuto 0:d58274531d38 91 protected:
ishiyamayuto 0:d58274531d38 92 PwmOut _pwm;
ishiyamayuto 0:d58274531d38 93 float _range;
ishiyamayuto 0:d58274531d38 94 float _degrees;
ishiyamayuto 0:d58274531d38 95 float _p;
ishiyamayuto 0:d58274531d38 96 };
ishiyamayuto 0:d58274531d38 97
ishiyamayuto 0:d58274531d38 98 #endif