|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
CANTalon Python Help
So i'm trying to run a CANTalon at some RPM. i decided on PIDF control. i chose 1366 RPM because its the speed done in the Software Reference Manual. i've tried to convert the java code into python, but the shooter refuses to run. can anyone help me?
Code:
#!/usr/bin/env python3
import wpilib
import ctre
from networktables import NetworkTable
class MyRobot(wpilib.IterativeRobot):
def robotInit(self):
self.Shooter = ctre.CANTalon(1)
self.Shooter.reverseOutput(False)
self.Shooter.setFeedbackDevice(ctre.CANTalon.FeedbackDevice.CtreMagEncoder_Relative)
self.Shooter.configNominalOutputVoltage(float(+0.0), float(-0.0))
self.Shooter.configPeakOutputVoltage(float(+12.0), float(-12.0))
self.Shooter.setProfile(0)
self.Shooter.setF(0.1097)
self.Shooter.setP(0)
self.Shooter.setI(0)
self.Shooter.setD(0)
self.Shooter.changeControlMode(ctre.CANTalon.ControlMode.Speed)
self.xb = wpilib.Joystick(2)
self.sd = NetworkTable.getTable('SmartDashboard')
def teleopPeriodic(self):
self.sd.putNumber("Velocity", self.Shooter.getSpeed())
if(self.xb.getRawButton(5)):
self.Shooter.set(1366)
else:
self.Shooter.set(0)
if __name__ == "__main__":
wpilib.run(MyRobot)
|
|
#2
|
||||
|
||||
|
Re: CANTalon Python Help
Quote:
|
|
#3
|
|||
|
|||
|
Re: CANTalon Python Help
Quote:
It works when I disable the speed change mode and run it on Normal .set(1) for percentage. But when I enable the speed change mode and set it to 1366 it won't run. Plus even with the .set(1), getSpeed() always returns 0. |
|
#4
|
||||
|
||||
|
Re: CANTalon Python Help
I know last year we used the speed mode and it worked.
One difference between your code and theirs is that they set P to something: https://github.com/CrossTheRoadElec/...Robot.java#L46 |
|
#5
|
|||
|
|||
|
Re: CANTalon Python Help
Quote:
but the getSpeed() command simply returns 0. any reason why that would be? |
|
#6
|
|||
|
|||
|
Re: CANTalon Python Help
Quote:
so i've tried both sending the getSpeed() value to smartdashboard and having them printed out in the console, and either one report 0 while the roborio dashboard reports a RPM value. any way i can resolve this? |
|
#7
|
||||
|
||||
|
Re: CANTalon Python Help
Quote:
There's one more difference in their code and your code: You call reverseOutput, they call reverseSensor. Might make a difference? Are you using the MagEncoder, or a different sensor? Unfortunately, I don't own the hardware for this device, so I can't perform a test. I'm fairly certain getSpeed worked last year though. What does .get() return? Also, you might try seeing what getEncVelocity() returns. |
|
#8
|
||||
|
||||
|
Re: CANTalon Python Help
Also, have you upgraded to RobotPy 2017.0.6? There was a bug in prior versions that could cause weird issues because HAL was initialized twice.
|
|
#9
|
|||
|
|||
|
Re: CANTalon Python Help
Quote:
i will have to on the next meeting. and i'll play around with the code to see what else i can get. the RPM was in the self test function fine. i was using a TalonSRX wired up over the CANBus with a CTRE mag encoder hooked up to the Talon. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|