Arcade Help

So my problem right now is, I can’t get my holonomic drive to drive forward and turn at the same time. This is the code. How do I fix this problem.

while(true){
if (Controller1.Axis3.position() != 0){
LeftFront.spin(directionType::fwd, Controller1.Axis3.value(), velocityUnits::pct);
LeftBack.spin(directionType::fwd, Controller1.Axis3.value(), velocityUnits::pct);
RightFront.spin(directionType::fwd, Controller1.Axis3.value(), velocityUnits::pct);
RightBack.spin(directionType::fwd, Controller1.Axis3.value(), velocityUnits::pct);
}

else if (Controller1.Axis1.position() !=0){
LeftFront.spin(directionType::fwd, Controller1.Axis1.value(), velocityUnits::pct);
LeftBack.spin(directionType::fwd, Controller1.Axis1.value(), velocityUnits::pct);
RightFront.spin(directionType::rev, Controller1.Axis1.value(), velocityUnits::pct);
RightBack.spin(directionType::rev, Controller1.Axis1.value(), velocityUnits::pct);
}

else{
  LeftBack.stop();
LeftFront.stop();
RightBack.stop();
RightFront.stop();
}

In this case, you’ll want to use the layering technique I mentioned in my other post instead of the if statements.

An example of a layered motor spin command would be:

Motor1.spin(directionType::fwd, Controller.Axis3.value() - Controller.Axis1.value(), velocityUnits::pct);

In the example, you’re directly subtracting the values of axis 3 and axis 1 to “layer” them. Why are we subtracting in this example? Because in this case, if my robot is turning, Motor1 will need to spin backward. So however much you turn is however much is subtracted from the motor percentage. Similarly, on the other side of the robot, say Motor4, it would be added instead of subtracted because if my robot is turning then I would need Motor4’s speed value to increase in order to turn.

Hope that helps!

8 Likes

My problem now is I can’t get it to strafe with axis 4 without using an if statement. Any fix to this?

As always, uploading the code in question makes these things go a lot faster.
A few questions:
1- Have you layered all the code?
2- Did you make all the possible movement diagrams to help you layer your code?

5 Likes

if(Controller1.Axis4.position() !=0 ){
LeftFront.spin(directionType::fwd, Controller1.Axis3.position() - Controller1.Axis1.position(), velocityUnits::pct);
RightFront.spin(directionType::fwd, Controller1.Axis3.position() + Controller1.Axis1.position(), velocityUnits::pct);
LeftBack.spin(directionType::fwd, Controller1.Axis3.position() - Controller1.Axis1.position(), velocityUnits::pct);
RightBack.spin(directionType::fwd, Controller1.Axis3.position() + Controller1.Axis1.position(), velocityUnits::pct);
}
else{
LeftFront.spin(directionType::fwd, Controller1.Axis4.position(), velocityUnits::pct);
RightFront.spin(directionType::rev, Controller1.Axis4.position(), velocityUnits::pct);
LeftBack.spin(directionType::rev, Controller1.Axis4.position(),velocityUnits::pct);
RightBack.spin(directionType::fwd, Controller1.Axis4.position(), velocityUnits::pct);
wait(20, msec); }

You should do what @Str0ngkatTh1rteen was saying and “layer” the joystick values by adding them so that you don’t have to use if/else statements. Something like

FL = Axis3 - Axis1 + Axis4
FR = Axis3 + Axis1 + Axis4
BL = Axis3 - Axis1 - Axis4
BR = Axis3 + Axis1 - Axis4

(idk if all the signs are correct, it depends on how you set up the motors, but that’s the basic concept)

4 Likes

Yeah, don’t put the commands in any if statements. As @ashatoolsidas said,

Your code should look something like this:

LeftFront.spin(directionType::fwd, Controller1.Axis1.position() + Controller1.Axis3.position() - Controller1.Axis4.position(), velocityUnits::pct);

outside of any if/else statements. If you’re unsure about the signs of the axis values, check with your base motion diagrams.

Hope that helps!

5 Likes

Thank You ALL so much for helping me finally get our drive working correctly. You will all get credit in our notebook and we appreciate you so much!
Sincerely,
21050A

2 Likes

It is, probably, beyond the scope of this topic, but just adding or subtracting joystick axis’ values and passing the sum as the motor control value is less than optimal.

It will kind of work, but if user pushes both sticks to the max - the value will end up 100+100 => 200 and any value over 100 pct will be clipped to 100 percent motor power, which will make controls more sensitive over the narrower range of joystick positions when inputs are combined.

The drivers will eventually learn how to control it, but there are alternative ways to map dual inputs that preserve full usable control range:

Also, some people feel like exponential joystick mapping gives them better control and precision over the robot movements both at low and high speeds:

Guide to Exponential Drive Function

Controller Sensitivity

4 Likes