public void setChannel(int channel, joystickaxis axis, bool reverse, int expo) { JoyChannel joy = new JoyChannel(); joy.axis = axis; joy.channel = channel; joy.expo = expo; joy.reverse = reverse; JoyChannels[channel] = joy; }
public void setAxis(int channel, joystickaxis axis) { JoyChannels[channel].axis = axis; }
ushort pickchannel(int chan, joystickaxis axis, bool rev, int expo) { int min, max, trim = 0; if (MainV2.comPort.MAV.param.Count > 0) { try { if (MainV2.comPort.MAV.param.ContainsKey("RC" + chan + "_MIN")) { min = (int)(float)(MainV2.comPort.MAV.param["RC" + chan + "_MIN"]); max = (int)(float)(MainV2.comPort.MAV.param["RC" + chan + "_MAX"]); trim = (int)(float)(MainV2.comPort.MAV.param["RC" + chan + "_TRIM"]); } else { min = 1000; max = 2000; trim = 1500; } } catch { min = 1000; max = 2000; trim = 1500; } } else { min = 1000; max = 2000; trim = 1500; } if (chan == 3) { trim = (min + max) / 2; // trim = min; // throttle } int range = Math.Abs(max - min); int working = 0; switch (axis) { case joystickaxis.None: working = ushort.MaxValue / 2; break; case joystickaxis.Pass: working = (int)(((float)(trim - min) / range) * ushort.MaxValue); break; case joystickaxis.ARx: working = state.ARx; break; case joystickaxis.ARy: working = state.ARy; break; case joystickaxis.ARz: working = state.ARz; break; case joystickaxis.AX: working = state.AX; break; case joystickaxis.AY: working = state.AY; break; case joystickaxis.AZ: working = state.AZ; break; case joystickaxis.FRx: working = state.FRx; break; case joystickaxis.FRy: working = state.FRy; break; case joystickaxis.FRz: working = state.FRz; break; case joystickaxis.FX: working = state.FX; break; case joystickaxis.FY: working = state.FY; break; case joystickaxis.FZ: working = state.FZ; break; case joystickaxis.Rx: working = state.Rx; break; case joystickaxis.Ry: working = state.Ry; break; case joystickaxis.Rz: working = state.Rz; break; case joystickaxis.VRx: working = state.VRx; break; case joystickaxis.VRy: working = state.VRy; break; case joystickaxis.VRz: working = state.VRz; break; case joystickaxis.VX: working = state.VX; break; case joystickaxis.VY: working = state.VY; break; case joystickaxis.VZ: working = state.VZ; break; case joystickaxis.X: working = state.X; break; case joystickaxis.Y: working = state.Y; break; case joystickaxis.Z: working = state.Z; break; case joystickaxis.Slider1: int[] slider = state.GetSlider(); working = slider[0]; break; case joystickaxis.Slider2: int[] slider1 = state.GetSlider(); working = slider1[1]; break; case joystickaxis.Hatud1: hat1 = (int)Constrain(hat1, 0, 65535); working = hat1; break; case joystickaxis.Hatlr2: hat2 = (int)Constrain(hat2, 0, 65535); working = hat2; break; case joystickaxis.Custom1: custom1 = (int)Constrain(custom1, 0, 65535); working = custom1; break; case joystickaxis.Custom2: custom2 = (int)Constrain(custom2, 0, 65535); working = custom2; break; } // between 0 and 65535 - convert to int -500 to 500 working = (int)(working / 65.535) - 500; if (rev) { working *= -1; } // save for later int raw = working; working = (int)Expo(working, expo, min, max, trim); /* * // calc scale from actualy pwm range * float scale = range / 1000.0f; * * * * * double B = 4 * (expo / 100.0); * double A = 1 - 0.25 * B; * * double t_in = working / 1000.0; * double t_out = 0; * double mid = trim / 1000.0; * * t_out = A * (t_in) + B * Math.Pow((t_in), 3); * * t_out = mid + t_out * scale; * * // Console.WriteLine("tin {0} tout {1}",t_in,t_out); * * working = (int)(t_out * 1000); * * * if (expo == 0) * { * working = (int)(raw) + trim; * }*/ //add limits to movement working = Math.Max(min, working); working = Math.Min(max, working); return((ushort)working); }
ushort pickchannel(int chan, joystickaxis axis, bool rev, int expo) { int min, max, trim = 0; if (MainV2.comPort.MAV.param.Count > 0) { try { min = (int)(float)(MainV2.comPort.MAV.param["RC" + chan + "_MIN"]); max = (int)(float)(MainV2.comPort.MAV.param["RC" + chan + "_MAX"]); trim = (int)(float)(MainV2.comPort.MAV.param["RC" + chan + "_TRIM"]); } catch { min = 1000; max = 2000; trim = 1500; } } else { min = 1000; max = 2000; trim = 1500; } if (chan == 3) { trim = (min + max) / 2; // trim = min; // throttle } int range = Math.Abs(max - min); int working = 0; switch (axis) { case joystickaxis.None: working = ushort.MaxValue / 2; break; case joystickaxis.Pass: working = (int)(((float)(trim - min) / range) * ushort.MaxValue); break; case joystickaxis.ARx: working = state.ARx; break; case joystickaxis.ARy: working = state.ARy; break; case joystickaxis.ARz: working = state.ARz; break; case joystickaxis.AX: working = state.AX; break; case joystickaxis.AY: working = state.AY; break; case joystickaxis.AZ: working = state.AZ; break; case joystickaxis.FRx: working = state.FRx; break; case joystickaxis.FRy: working = state.FRy; break; case joystickaxis.FRz: working = state.FRz; break; case joystickaxis.FX: working = state.FX; break; case joystickaxis.FY: working = state.FY; break; case joystickaxis.FZ: working = state.FZ; break; case joystickaxis.Rx: working = state.Rx; break; case joystickaxis.Ry: working = state.Ry; break; case joystickaxis.Rz: working = state.Rz; break; case joystickaxis.VRx: working = state.VRx; break; case joystickaxis.VRy: working = state.VRy; break; case joystickaxis.VRz: working = state.VRz; break; case joystickaxis.VX: working = state.VX; break; case joystickaxis.VY: working = state.VY; break; case joystickaxis.VZ: working = state.VZ; break; case joystickaxis.X: working = state.X; break; case joystickaxis.Y: working = state.Y; break; case joystickaxis.Z: working = state.Z; break; case joystickaxis.Slider1: int[] slider = state.GetSlider(); working = slider[0]; break; case joystickaxis.Slider2: int[] slider1 = state.GetSlider(); working = slider1[1]; break; } // between 0 and 65535 - convert to int -500 to 500 working = (int)(working / 65.535) - 500; if (rev) working *= -1; // calc scale from actualy pwm range float scale = range / 1000.0f; // save for later int raw = working; double B = 4 * (expo / 100.0); double A = 1 - 0.25*B; double t_in = working / 1000.0; double t_out = 0; double mid = trim / 1000.0; t_out = A * (t_in) + B * Math.Pow((t_in), 3); t_out = mid + t_out * scale; // Console.WriteLine("tin {0} tout {1}",t_in,t_out); working = (int)(t_out * 1000); if (expo == 0) { working = (int)(raw) + trim; } //add limits to movement working = Math.Max(min, working); working = Math.Min(max, working); return (ushort)working; }
protected short pickchannel(int chan, joystickaxis axis, bool rev, int expo) { int min, max, trim = 0; if (Interface.MAV.param.Count > 0) { try { if (Interface.MAV.param.ContainsKey("RC" + chan + "_MIN")) { min = (int)(float)(Interface.MAV.param["RC" + chan + "_MIN"]); max = (int)(float)(Interface.MAV.param["RC" + chan + "_MAX"]); trim = (int)(float)(Interface.MAV.param["RC" + chan + "_TRIM"]); } else { min = 1000; max = 2000; trim = 1500; } } catch { min = 1000; max = 2000; trim = 1500; } } else { min = 1000; max = 2000; trim = 1500; } if (manual_control) { min = -1000; max = 1000; trim = 0; } if (chan == 3) { trim = (min + max) / 2; // trim = min; // throttle } int range = Math.Abs(max - min); int working = 0; switch (axis) { case joystickaxis.None: working = ushort.MaxValue / 2; break; case joystickaxis.Pass: working = (int)(((float)(trim - min) / range) * ushort.MaxValue); break; case joystickaxis.ARx: working = state.ARx; break; case joystickaxis.ARy: working = state.ARy; break; case joystickaxis.ARz: working = state.ARz; break; case joystickaxis.AX: working = state.AX; break; case joystickaxis.AY: working = state.AY; break; case joystickaxis.AZ: working = state.AZ; break; case joystickaxis.FRx: working = state.FRx; break; case joystickaxis.FRy: working = state.FRy; break; case joystickaxis.FRz: working = state.FRz; break; case joystickaxis.FX: working = state.FX; break; case joystickaxis.FY: working = state.FY; break; case joystickaxis.FZ: working = state.FZ; break; case joystickaxis.Rx: working = state.Rx; break; case joystickaxis.Ry: working = state.Ry; break; case joystickaxis.Rz: working = state.Rz; break; case joystickaxis.VRx: working = state.VRx; break; case joystickaxis.VRy: working = state.VRy; break; case joystickaxis.VRz: working = state.VRz; break; case joystickaxis.VX: working = state.VX; break; case joystickaxis.VY: working = state.VY; break; case joystickaxis.VZ: working = state.VZ; break; case joystickaxis.X: working = state.X; break; case joystickaxis.Y: working = state.Y; break; case joystickaxis.Z: working = state.Z; break; case joystickaxis.Slider1: int[] slider = state.GetSlider(); working = slider[0]; break; case joystickaxis.Slider2: int[] slider1 = state.GetSlider(); working = slider1[1]; break; case joystickaxis.Hatud1: hat1 = (int)Constrain(hat1, 0, 65535); working = hat1; break; case joystickaxis.Hatlr2: hat2 = (int)Constrain(hat2, 0, 65535); working = hat2; break; case joystickaxis.Custom1: working = (int)(((float)(custom0 - min) / range) * ushort.MaxValue); working = (int)Constrain(working, 0, 65535); break; case joystickaxis.Custom2: working = (int)(((float)(custom1 - min) / range) * ushort.MaxValue); working = (int)Constrain(working, 0, 65535); break; case joystickaxis.UINT16_MAX: return((short)-1); } // between 0 and 65535 - convert to int -500 to 500 working = (int)map(working, 0, 65535, -500, 500); if (rev) { working *= -1; } // save for later int raw = working; working = (int)Expo(working, expo, min, max, trim); //add limits to movement working = Math.Max(min, working); working = Math.Min(max, working); return((short)working); }