|
|
@@ -17,21 +17,27 @@ class ContrlService {
|
|
|
}
|
|
|
})
|
|
|
console.log('测试开始');
|
|
|
- // test
|
|
|
- let a = 128
|
|
|
- setInterval(() => {
|
|
|
- this.PWM.setPulseLength(3, this.Servo2pwm(a));
|
|
|
+ let a = 90
|
|
|
+ const t = setInterval(() => {
|
|
|
+ if(a >= 160) {
|
|
|
+ clearInterval(t)
|
|
|
+ // this.PWM.setPulseLength(1, this.Servo2pwm(130));
|
|
|
+ return
|
|
|
+ }
|
|
|
+ a++
|
|
|
+ this.PWM.setPulseLength(1, this.Servo2pwm(a));
|
|
|
console.log(a);
|
|
|
- }, 50);
|
|
|
+ }, 20);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 舵机换算比例:摇杆范围0-256,PWM范围1000~1500~2000
|
|
|
+ * 舵机换算比例:摇杆范围0-256,PWM范围500~1500~2500
|
|
|
* @param {number} v
|
|
|
* @returns
|
|
|
*/
|
|
|
Servo2pwm(v) {
|
|
|
- return parseInt(v / (256 / 1000)) + 1000
|
|
|
+ return parseInt(v / (256 / 2000)) + 500
|
|
|
+ // return parseInt(v / (256 / 1000)) + 1000
|
|
|
}
|
|
|
}
|
|
|
new ContrlService()
|