My team is using a limelight sensor that controls our turret motor depending on where the target is. How can i make our motor stop after 60 degrees left and right? I think that it might be a get statement but we still could use the advice anyone can give us.
So there is two ways you can do this, but the easiest way is to simply rotate the turret and count how many encoder ticks it takes then just do a simple if statement in the isFinished encoderValue-encoderValueAtStartOfCommand >= valueYouFoundFromTelemetry. You could do that with a bang bang controller seeing as the turret will probs rotate slowly however if you desire you could also use a PD controller so it is criticially damped
So how would I be able to get the ticks from the rotations?
For Falcon 500’s, the talonFX has made it really easy. First, in robotInit() (or whereever you set your motor settings) you will want to first tell the API what type of encoder you are using. The Falcon’s use an integrated sensor so you’d use that. The second parameter is the port to use for the closed-loop control. This is neccesary if you want PID or anything like that so not only do you not have to hard-code it, but more importantly it runs at a much higher FPS. The last parameter is like the second parameter in WaitForChild() if you ever did roblox coding, it will display that it couldnt find a talonFX if it doesnt show up. I like to set it to atleast 100 ms that way I can see the error if it does not work.
talonFX.configSelectedFeedbackSensor(TalonFXFeedbackDevice.IntegratedSensor, 0, 100)
you should then call the setSensorPhasePosition
function in teleopInit passing 0 to reset it, then if you want to get the sensor position you’d call getSelectedSensorPosition()
and you’d pass in 0 as you are using the primary PID port, 0.
If you don’t want to to run past 60 degrees because of possible physical damage, I would also include forward and reverse soft limits in the falcon configs.
You can tell the motors to not apply output current if the encoder reads a certain value when traveling in a certain direction.
We are using forward and reverse soft limits.
We have a method converting degrees to ticks.
Public void ticksToDegrees (double degrees){
Return degrees/360gear ratio of turret2048;
}
2048 is the ticks per rev of a falcon
Then when you set soft limit of your turret motor just use this method
CongigReverseSoftLimit (degreesToTicks(60) );
Don’t forget to set the soft limit to true so it works.
We went one step further …. When it hits soft limit or target is outside of that we swivel around to find the target on the other side.
This isn’t our latest code so I don’t think the search command is correct but the turret subsystem is current
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.