How to transfer RC joystick control to ROV movement (math)?

Control Boards, Controllers, Tethers, Ect.
Post Reply
mandigit
Posts: 1
Joined: Sep 8th, 2018, 4:44 pm
Location: Russia, Moscow
Contact:

How to transfer RC joystick control to ROV movement (math)?

Post by mandigit »

Hi guys, i 'am building ROV. Recently i have tested watertight of ROV and now it's time for horizontal movement. I shall try to use 6ch rc control unit and it rise the question about how to use sticks for control movement.
if we have X and Y pos (view pic.) of sticks then control signal may be obtained by differencial formulas like
L=Y+X, R=Y-X and this calculation is continious over all values of X,Y
but for negative Y (sectors 2, 3) we have inverse behaviour then we expect.
For example when Y=-1, X=1 differencial math give us L=0, R=-2 and this mean fast motion back and left but in everyday life we may expect back and RIGHT.
Have you any suggestion about how to transfer joystick X,Y coordinate to L,R coordinate? Or is there more common type of assigning joystick stick movement to ROV movement?
Attachments
2.jpg
2.jpg (14.27 KiB) Viewed 3963 times
rokenbuzz
Posts: 12
Joined: Sep 11th, 2017, 8:17 am

Re: How to transfer RC joystick control to ROV movement (mat

Post by rokenbuzz »

I'm using an xbox controller, but I haven't really done any real driving. My project is just controllers, wires, and motors on a bench.
I use a trigger button as a throttle and the thumb stick for direction.
I figured it would be easier to control if the direction and throttle were not all in one control.
But like I said, I'm not actually driving it for real.

You probably can use this as is, but maybe you'll glean something from it:

Code: Select all

// *** Right Trigger ***
// Percent of total thruster power is based on right trigger (0 to 255)
float rightTriggerPercent = gamePad.RightTrigger / 255.0f;

// *** Left Thumb ***
if (rightTriggerPercent <= 0.01 || (Math.Abs(leftThumbX) < DeadZone && Math.Abs(leftThumbY) < DeadZone))
{
    this.leftThrusterPercent = 0.0f;
    this.rightThrusterPercent = 0.0f;
}
else
{
    double leftThumbRadians = Math.Atan2(leftThumbY, leftThumbX);
    bool isLeftThumbLeftish = leftThumbRadians <= 0.0;
    double leftThrusterPositionPercent = isLeftThumbLeftish ? -1.0 : 1.0;
    double rightThrusterPositionPercent = leftThrusterPositionPercent;

    leftThumbRadians = Math.Abs(leftThumbRadians);

    bool isLeftThumbBackish = leftThumbRadians > HalfPi;
    leftThumbRadians -= (isLeftThumbBackish ? HalfPi : 0);

    double leftThumbQuadrantRange = isLeftThumbLeftish == isLeftThumbBackish ? 2.0 : -2.0;
    double leftRightThrusterShift = isLeftThumbLeftish == isLeftThumbBackish ? -1.0 : 1.0;

    leftThrusterPositionPercent = leftThumbQuadrantRange * (leftThumbRadians / HalfPi) + leftRightThrusterShift;

    if (isLeftThumbBackish == isLeftThumbLeftish)
    {
        // Swap
        double swapDouble = rightThrusterPositionPercent;
        rightThrusterPositionPercent = leftThrusterPositionPercent;
        leftThrusterPositionPercent = swapDouble;
    }

    // Split percent of total thruster power between left and right thrusters
    this.leftThrusterPercent = (float)(rightTriggerPercent * leftThrusterPositionPercent);
    this.rightThrusterPercent = (float)(rightTriggerPercent * rightThrusterPositionPercent);
}
Post Reply