Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Python (http://www.chiefdelphi.com/forums/forumdisplay.php?f=187)
-   -   CANTalon Python Help (http://www.chiefdelphi.com/forums/showthread.php?t=154335)

StrMNX 27-01-2017 16:27

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)


virtuald 27-01-2017 16:52

Re: CANTalon Python Help
 
Quote:

Originally Posted by StrMNX (Post 1637187)
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?

StrMNX 27-01-2017 17:03

Re: CANTalon Python Help
 
Quote:

Originally Posted by virtuald (Post 1637196)
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.

virtuald 27-01-2017 17:15

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

StrMNX 29-01-2017 13:33

Re: CANTalon Python Help
 
Quote:

Originally Posted by virtuald (Post 1637205)
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?

StrMNX 29-01-2017 13:51

Re: CANTalon Python Help
 
Quote:

Originally Posted by StrMNX (Post 1637789)
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?

virtuald 29-01-2017 15:21

Re: CANTalon Python Help
 
Quote:

Originally Posted by StrMNX (Post 1637792)
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.

virtuald 29-01-2017 15:28

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.

StrMNX 29-01-2017 16:09

Re: CANTalon Python Help
 
Quote:

Originally Posted by virtuald (Post 1637827)
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.


All times are GMT -5. The time now is 05:10.

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