// Drive Switcher public void DriveJoystick() { forward_joystick.SetActive(true); forward_linear.gameObject.SetActive(false); forward_manual.SetActive(false); socket.SetAutoHeading(false, 0); socket.SetForwardMotorsSpeed(0, 0); drivemode = DriveMode.Joystick; }
void DifferentialDrive(float x, float y) { float nMotPremixL = 0; // Motor (left) premixed output (-70..+70) float nMotPremixR = 0; // Motor (right) premixed output (-70..+70) nMotPremixL = (x >= 0) ? 70f : (70f + x); nMotPremixR = (x >= 0) ? (70f - x) : 70f; // Scale Drive output due to Joystick Y input (throttle) nMotPremixL = nMotPremixL * y / 70f; nMotPremixR = nMotPremixR * y / 70f; // Now calculate pivot amount // - Strength of pivot (nPivSpeed) based on Joystick X input // - Blending of pivot vs drive (fPivScale) based on Joystick Y input float nPivSpeed = x; float fPivScale = (Mathf.Abs(y) > fPivYLimit) ? 0f : (1f - Mathf.Abs(y) / fPivYLimit); // Calculate final mix of Drive and Pivot float nMotMixL = ((1f - fPivScale) * nMotPremixL + fPivScale * (nPivSpeed)) / 70f; float nMotMixR = ((1f - fPivScale) * nMotPremixR + fPivScale * (-nPivSpeed)) / 70f; int left = (int)Mathf.Round(nMotMixL * 100f); int right = (int)Mathf.Round(nMotMixR * 100f); socket.SetForwardMotorsSpeed(right, left); }
public void SliderChanged() { socket.SetForwardMotorsSpeed((int)slider.value, (int)slider.value); }
public void SliderChanged() { socket.SetForwardMotorsSpeed((int)right.value, (int)left.value); }