
27-01-2017, 16:52
|
 |
RobotPy Guy
AKA: Dustin Spicuzza
 FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
|
|
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,105
|
|
|
Re: CANTalon Python Help
Quote:
Originally Posted by StrMNX
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)
|
Have you started with just a simple example, making sure that when you tell the motor to move it moves? Or did you start with this?
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/ pynetworktables2js (NetworkTables for Python & Javascript)
2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award
Resources: FIRSTWiki (relaunched!) | My Software Stuff
|