Go to Post Several really good programming and control specialists haunt CD, but a thread titled "motor failure" might not attract their notice soon. - Richard Wallace [more]
Home
Go Back   Chief Delphi > Technical > Programming > Python
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #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
  #2   Spotlight this post!  
Unread 27-01-2017, 16:52
virtuald's Avatar
virtuald virtuald is online now
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,102
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
Re: CANTalon Python Help

Quote:
Originally Posted by StrMNX View Post
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
Reply With Quote
  #3   Spotlight this post!  
Unread 27-01-2017, 17:03
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
Re: CANTalon Python Help

Quote:
Originally Posted by virtuald View Post
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?
Yeah, it was tested and runs.
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.
Reply With Quote
  #4   Spotlight this post!  
Unread 27-01-2017, 17:15
virtuald's Avatar
virtuald virtuald is online now
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,102
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
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
__________________
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
Reply With Quote
  #5   Spotlight this post!  
Unread 29-01-2017, 13:33
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
Re: CANTalon Python Help

Quote:
Originally Posted by virtuald View Post
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
after running it with some P value it works
but the getSpeed() command simply returns 0.
any reason why that would be?
Reply With Quote
  #6   Spotlight this post!  
Unread 29-01-2017, 13:51
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
Re: CANTalon Python Help

Quote:
Originally Posted by StrMNX View Post
after running it with some P value it works
but the getSpeed() command simply returns 0.
any reason why that would be?

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?
Reply With Quote
  #7   Spotlight this post!  
Unread 29-01-2017, 15:21
virtuald's Avatar
virtuald virtuald is online now
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,102
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
Re: CANTalon Python Help

Quote:
Originally Posted by StrMNX View Post
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?
The RoboRIO dashboard? You mean in the self-test thing?

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.
__________________
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
Reply With Quote
  #8   Spotlight this post!  
Unread 29-01-2017, 15:28
virtuald's Avatar
virtuald virtuald is online now
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,102
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
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.
__________________
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
Reply With Quote
  #9   Spotlight this post!  
Unread 29-01-2017, 16:09
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
Re: CANTalon Python Help

Quote:
Originally Posted by virtuald View Post
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.
i did not update to 2017.0.6
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.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 11:25.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi