Hello, I am using the Swerve Template from SDS, but I am stumped on how to plug numbers into the drive command. I am trying to get a limelight targeting and autonomous driving. I know the general idea of how they work, but the way the drive command is setup confuses me. This is my current build. If anyone has experience with this template or how the parameters work, any help is greatly appreciated. Thank you.
LIttle update
After looking at where the command gets called, I think I will try to replace the leftJoy.getY and leftJoy.getX with 0 and set the rightJoy.getZ at like .1 to see if it will actually run the command. SInce the command has already been made, I can just create a new button to call that command with the new values.
So for limelight specifically, all you need to do is plugin the limelight x error into a PID loop (we only use a copious amount of P and a little D gain) to output a rotation command, and then spit that out into a rotation for chassis speeds, which the swerve drivetrain can read.
That will work to spin the robot, yes.
Okay So using this from the limelights docs, I would have it setup similarly, but instead of left and right commands, would I run the default drive command and use the steering adjust value instead of the getZ value or would I have to make 2 seperate commands for left and right? Also I am a little confused on what exactly the Kp is.
Tx is the x offset, so lets say the robot is 10px too far right, it would do 10*-.1 and give -1. But if the motors are controlled from -1 to 1, what would happen if it was 11px off or even 20. It would set the motor values beyond what the max is? Or am I missing something.
Kind of, so we used WPILIB’s Pid controller. Do you know how to use it? That code is for a WCD, which will not work very well for swerve.
I’m just brainstorming at this point, but I would assume I can run all of this alongside the previous stuff, but I I was wondering If i could get the distance adjust and plug it into the Y axis of the drive command, get the steering adjust, throw that into the Z axis command, so it auto ranges and targets at the same time. Cause ultimately I have a goal of mine to make this thing strafe the target in a circle. I want to be able to auto target the goal while maintaining a set distance and just circle the hub along the loading area or whatever it is called. Just wondering if I have multiple if statements running at once, while driving, it will cause overlaps and screw everything up. Trying to find a way to make that feasible.
Edit:
Also I was thinking that I needed two if statements because the aiming will only run if the offset is a certain amount, so if the angle is accurate, but the distance is wrong, then it will not run the distance if I combine them. Actually, now that I am thinking about it again, I would do (tx < 1.0 || distanceError != 0)
Since in the limelight configure stuff you put the robot at a set distance, calibrate the camera, so that distance becomes 0.
I have no knowledge regarding WPI’s PID controller.
I see, so what the PID controller will do is do all the imbedded math for you (kp * error, calculation for your i term, and for your D term) it then spits out an output that your drivetrain can use. Running it with just P will do fundamentally the same thing as what you have above, but you are going to need to add both I and D terms, or else your robot will never actually center itself on the target cleanly.
Oh okay. I checked out wpi’s docs on it and it kind of makes sense. Would it be possible to see your code and how you implemented it and how it gets everything fed into it?
Sure https://github.com/northwoodrobotics/6300-2022-Code
Specifically look at the Vision (in subsystems) file, and the DriveAutoRotate (in commands.drivecommands) file. The “VisionSubsytem” file is a redundant legacy, and the AutoRotateToTarget file is for auton only. We used a modified copy of bearswerve by 6391. It works pretty much the same way as your code, just with some file nesting.
Thank you. A lot more complex looking than I was expecting. Also you were right, the general layout seems pretty much the same, just things named and called a bit different.
From the looks of it, I cannot just use the drivetrain command, but have to make new versions of it for each instance I use it? I’m just having some trouble figuring out how to get things setup.
Yes, you need to create a new instance of the drive command. We specifically call it with a button, along with several other commands, such as limelight led mode, in a sequential command group. The driver technically has control over driving during this, but this is going to be removed (just interning the chassis speeds as zero). Specifically for your implementation, you would use the “drive” command within your drive subsystem.
Okay, so from the looks of it, if I could just copy paste the defaultdrivecommand and place that into a new command files named limelightAim for example, I would just need to change the public defaultdriveCommand( all the parameters) to public limelightAim( parameters) it should allow me to control the robot using constant values, or values fed using the limelight? and then from there I am use a similar method you used, or just the limelight websites version for a quick and dirty test run. Where do you recommend putting all of the get networktable stuff. Our old code has it in the robot.java periodic, but i was thinking it would clean stuff up to make a limelight subsystem and run it all in that periodic.
Sorry if the messages are hard to follow, I am typing as I try to figure stuff out.
Also, I just want to say thank you man. You are being so patient with me and I greatly appreciate it.
I’ve been having a lot of issues implementing the stuff you have in there, and it may be due to my project being in 2021 rather than2022, so I will have to get everything updated before I can start using the stuff you have.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.