View Single Post
  #1   Spotlight this post!  
Unread 27-01-2017, 16:27
StrMNX StrMNX is offline
Registered User
no team
 
Join Date: Oct 2016
Location: Youngstown Ohio
Posts: 12
StrMNX is an unknown quantity at this point
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)
Reply With Quote