forked from iNavFlight/inav-configurator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmotorMixRule.js
71 lines (52 loc) · 1.61 KB
/
motorMixRule.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'use strict';
const { constrain } = require('./helpers')
var MotorMixRule = function (throttle, roll, pitch, yaw) {
var self = {};
self.fromMsp = function (mspThrottle, mspRoll, mspPitch, mspYaw) {
throttle = Math.round(((mspThrottle / 1000) - 2) * 1000) / 1000;
roll = Math.round(((mspRoll / 1000) - 2) * 1000) / 1000;
pitch = Math.round(((mspPitch / 1000) - 2) * 1000) / 1000;
yaw = Math.round(((mspYaw / 1000) - 2) * 1000) / 1000;
};
self.isUsed = function () {
return throttle !== 0;
};
self.getThrottle = function () {
return constrain(parseFloat(throttle, 10), -2, 2);
};
self.getThrottleForMsp = function () {
return (self.getThrottle()+2) * 1000;
};
self.setThrottle = function (data) {
throttle = data;
};
self.getRoll = function () {
return constrain(parseFloat(roll, 10), -2, 2);
};
self.getRollForMsp = function () {
return (self.getRoll() + 2) * 1000;
};
self.setRoll = function (data) {
roll = data;
};
self.getPitch = function () {
return constrain(parseFloat(pitch, 10), -2, 2);
};
self.getPitchForMsp = function () {
return (self.getPitch() + 2) * 1000;
};
self.setPitch = function (data) {
pitch = data;
};
self.getYaw = function () {
return constrain(parseFloat(yaw, 10), -2, 2);
};
self.getYawForMsp = function () {
return (self.getYaw() + 2) * 1000;
};
self.setYaw = function (data) {
yaw = data;
};
return self;
};
module.exports = MotorMixRule;