Programming Help (Accepting multiple double inputs)

Hi!

I am having issues accepting multiple doubles from an Xbox Controller. I wanted to test out tank drive with an Xbox Controller, however whenever it set it to accept left stick y and right stick y, it completely ignores any right stick inputs (sets it to left input).

I am using command based coding in java, I have both properly set as Supplier . If needed, I can send the code but right now my laptop is at the shop. It looks somewhat like this:

// subsystem method
public void drive(double ly, double ry){
//sets deadband already
Left.set(ly);
Right.set(ry);
}

//command
(Supplier lyFunc, Supplier ryFunc, DriveTrain drivetrain){
this.lyFunc = lyFunc;
this.ryFunc = ryFunc;
this.drivetrain = drivetrain;
addrequirement(drivetrain);
}

//execute
Ly = lyFunc.get();
Ry = ryFunc.get();
drivetrain.drive(Ly, Ry);

//robot container
Drivetrain drivetrain = new DriveTrain();
XboxController Xbox = new XboxController(0);
drivetrain.setDefaultCommand(
new driveCommand(
() → Xbox.getLeftY(),
() → Xbox.getRightY()
));

//Any help would be greatly appreciated!

What you sent looks correct, so we’ll need to see your actual code.

Sheesh that was quick! I’ll try to get it to you on Friday. Would you like me to send it to GitHub or send it as a Zip?

Thank you so much for your help!

Github is generally preferred

Just a shot in the dark since we don’t have complete code yet, but it could be because you haven’t defined the TYPE of the Supplier. You should make sure that you define the command’s Supplier (this.lyFunc/this.ryFunc) as a double Supplier. You can do this by either using a type identifier like this:

Supplier<double> lyFunc;

or use a DoubleSupplier object instead of a generic Supplier like this:

DoubleSupplier lyFunc;

It looks like your code in your GitHub is a bit different than what you’ve shared here. One thing I did notice is that you’re using one SlewRateLimiter for all your axes. You should use one per double supplier. (Source)

Your value is also very high for it. I suspect that is also an issue. The example used 0.5 instead of 8.5.

I did not realize that it was still on my attempted fix. It has now been set back to what I had typed in the thread.

public void execute() {
   
    
    ly = (Math.abs(ly) > 0.17) ? slew.calculate(ly) : 0.0;
    ry = (Math.abs(ry) > 0.17) ? slew.calculate(ry) : 0.0;
    rx = (Math.abs(rx) > 0.17) ? slew.calculate(rx) : 0.0;
    
    
    driveTrain.drive(ly, rx, ry);
  }

You seem to have forgot to update ly,ry,rx based on the suplliers.
Something like ly=inLy.get() before ly = (Math.abs(ly) > 0.17) ? slew.calculate(ly) : 0.0; (for each value) should fixed that issue

I forgot to bring that back when updating the git but I don’t think thats the main issue. It isn’t that I am getting no inputs whatsoever, it’s that all my other inputs are being overridden by my Left Y (first input listed).

The git has now been edited to reflect my error. I’ll send results on Monday when I get into the shop. Thank you all so much for the help so far!

It might be worth asking sanity check to look at the Xbox controller’s values in the driver station. see the controller itself doesn’t have any misbehaviour.

I will make sure to check that! Now thinking about it, I am using a really sketch controller. However, I don’t think that is the main reason because I was able to make it work in a really scuffed way (having the two sides in different commands and subsystems). I had the right stick and left stick values as what they should be when I had it work that abominable way. I had them print out for the sake of seeing what they were.

Yep, my vote is that this is because one stick is reusing the slew rate limiter of another stick.

Let each stick (and each axis too) have their own rate limiter

1 Like

After checking my old code for swerve I 100% agree with this. I don’t know how I didn’t catch this sooner but thank you so much! I’ll make sure to post results when I go to the shop this Monday

IT WORKS :partying_face:.

For anyone who has the same issue as me here’s how to fix it:
Make sure to have separate slew rate values per axis. Otherwise the slew calculates over all other values but the first