2/13 操舵翼端CAN
Dependencies: ADXL345_I2C Control_Yokutan_CANver1 mbed
Fork of Control_Yokutan_CAN_ver1 by
main.cpp
- Committer:
- YusukeWakuta
- Date:
- 2016-02-17
- Revision:
- 5:a839ccbf7f9a
- Parent:
- 3:4417217b4f66
File content as of revision 5:a839ccbf7f9a:
//翼端can program #include "mbed.h" #define INIT_SERVO_PERIOD_MS 20 #define WAIT_LOOP_TIME 0.2 Serial pc(USBTX,USBRX); PwmOut servo1(p22); PwmOut servo2(p23);// eruron DigitalOut led1(LED1); AnalogIn a(p20); AnalogIn b(p19); int neutral_a = 0; int neutral_b = 0; bool servoInit() { servo1.period_ms(INIT_SERVO_PERIOD_MS); servo2.period_ms(INIT_SERVO_PERIOD_MS); return true; } double calcPulse(int deg) { return (0.00093+(deg/180.0)*(0.00235-0.00077)); } void WriteServo(int a,int b) { servoInit(); servo1.pulsewidth(calcPulse(a * 90)); servo2.pulsewidth(calcPulse(b * 90)); } //servo1.pulsewidth(calcPulse(a.read()*170)); // servo2.pulsewidth(calcPulse(b.read()*170)); //pc.printf("%f", a.read()); int main() { while(1) { WriteServo(a,b); wait(WAIT_LOOP_TIME); } }