OCCRA
Go to Post FRC is about what we collectively make of it. - Tristan Lall [more]
Home
Go Back   Chief Delphi > Technical > Programming > Python
CD-Events   CD-Media   CD-Spy   FRC-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rating: Thread Rating: 17 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 10-25-2010, 11:49 PM
Peter Johnson Peter Johnson is offline
With great power comes great I^2*R
FRC #0294 (Beach Cities Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Redondo Beach, CA
Posts: 139
Peter Johnson is a splendid one to beholdPeter Johnson is a splendid one to beholdPeter Johnson is a splendid one to beholdPeter Johnson is a splendid one to beholdPeter Johnson is a splendid one to beholdPeter Johnson is a splendid one to beholdPeter Johnson is a splendid one to beholdPeter Johnson is a splendid one to behold
RobotPy: Python for FRC

After being inspired by Ross Light and Team 973's success in porting Lua to the cRIO (see the "Announcing FIRSTLua" thread), I have completed a port of Python to the cRIO, called RobotPy.

RobotPy is a fully functioning port of Python 3.1.2 that can be used for programming your FRC robot. The full set of WPILib functions, including CANJaguar, is available in Python via "import wpilib".

As with the Lua port,
  • Python is easier to learn than C
  • Live code reloads
  • Errors won't crash the robot
  • Python provides automatic garbage collection
  • WindRiver isn't needed after the base code is installed. Just a text editor and an FTP client.

I've performed some initial testing on Team 294's 2010 robot, including running CAN bus Jaguars and compressors and pneumatics. Examples and installation documentation are available on the website and are also included in the download. Also, the download .zip file includes a prebuilt FRC_UserProgram.out, so you don't need to have any programming software installed to get up and running (just FTP a bunch of files to your robot)! Please report any bugs you find via the RobotPy website's ticket system (note: registration is required).

RobotPy website: http://www.tortall.net/projects/robotpy/

While the download .zip doesn't include the source code, it is available via a git repository. See the Download page on the website for details.

With the exception of modules with large dependencies (e.g. databases), almost all of the Python standard library is included. So yes, you can parse XML files with expat on the robot if you so choose . Much of this is untested however (I have not tried to run the Python test suite on the robot).

Major thanks go to Ross Light and Team 973; this project would not have happened without them creating FIRSTLua first to inspire me to port Python. RobotPy uses the WPILib SWIG wrapper created by Ross, with the addition of CANJaguar. The idea of using a boot script to auto-reload the user code is also taken from FIRSTLua.
__________________
Creator of RobotPy - Python for FRC

2010 FRC World Champions (294, 67, 177)
2007 FTC World Champions (30, 74, 23)
2001 FRC National Champions (71, 294, 125, 365, 279)
Reply With Quote
  #2   Spotlight this post!  
Unread 10-26-2010, 12:18 AM
Robototes2412's Avatar
Robototes2412 Robototes2412 is offline
1 * 4 != 14
FRC #2412 (Robototes)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2007
Location: Bellevue
Posts: 312
Robototes2412 is on a distinguished road
Re: RobotPy: Python for FRC

thank you so much

I'm already porting my team's high level motor grouper and pneumatics classes, I'm hoping these can be included with your permission, of course
Reply With Quote
  #3   Spotlight this post!  
Unread 10-26-2010, 12:42 AM
Peter Johnson Peter Johnson is offline
With great power comes great I^2*R
FRC #0294 (Beach Cities Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Redondo Beach, CA
Posts: 139
Peter Johnson is a splendid one to beholdPeter Johnson is a splendid one to beholdPeter Johnson is a splendid one to beholdPeter Johnson is a splendid one to beholdPeter Johnson is a splendid one to beholdPeter Johnson is a splendid one to beholdPeter Johnson is a splendid one to beholdPeter Johnson is a splendid one to behold
Re: RobotPy: Python for FRC

Quote:
Originally Posted by Robototes2412 View Post
I'm already porting my team's high level motor grouper and pneumatics classes, I'm hoping these can be included with your permission, of course
Of course! I'd love to build up and include (maybe as a separate download) a library of team-built robot-oriented Python modules. And if anyone has suggestions on any other common/useful modules to include, I'll look at adding them as well (NumPy and SciPy come to mind, for example).
__________________
Creator of RobotPy - Python for FRC

2010 FRC World Champions (294, 67, 177)
2007 FTC World Champions (30, 74, 23)
2001 FRC National Champions (71, 294, 125, 365, 279)
Reply With Quote
  #4   Spotlight this post!  
Unread 10-26-2010, 12:47 AM
Robototes2412's Avatar
Robototes2412 Robototes2412 is offline
1 * 4 != 14
FRC #2412 (Robototes)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2007
Location: Bellevue
Posts: 312
Robototes2412 is on a distinguished road
Re: RobotPy: Python for FRC

I have most of the common inputs that my team used coded in python for prototyping, so I will be done with the whole thing by tomorrow
Reply With Quote
  #5   Spotlight this post!  
Unread 10-26-2010, 01:09 AM
AustinSchuh AustinSchuh is offline
Registered User
FRC #0971 (Spartan Robotics) #254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Feb 2005
Rookie Year: 1999
Location: Los Altos, CA
Posts: 591
AustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond repute
Re: RobotPy: Python for FRC

Quote:
Originally Posted by Peter Johnson View Post
Of course! I'd love to build up and include (maybe as a separate download) a library of team-built robot-oriented Python modules. And if anyone has suggestions on any other common/useful modules to include, I'll look at adding them as well (NumPy and SciPy come to mind, for example).
If you don't get to it first, I'm going to try to port NumPy and SciPy to the cRIO. I've been using those for prototyping up control loops on my desktop, and they are really nice.

Do sockets work? That would make it easy to add a telnet server to the robot, and allow remote execution of code to aid testing. Also, does print work correctly?

Thanks again for doing this! I'm really excited.
Reply With Quote
  #6   Spotlight this post!  
Unread 10-26-2010, 01:22 AM
Peter Johnson Peter Johnson is offline
With great power comes great I^2*R
FRC #0294 (Beach Cities Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Redondo Beach, CA
Posts: 139
Peter Johnson is a splendid one to beholdPeter Johnson is a splendid one to beholdPeter Johnson is a splendid one to beholdPeter Johnson is a splendid one to beholdPeter Johnson is a splendid one to beholdPeter Johnson is a splendid one to beholdPeter Johnson is a splendid one to beholdPeter Johnson is a splendid one to behold
Re: RobotPy: Python for FRC

Quote:
Originally Posted by AustinSchuh View Post
If you don't get to it first, I'm going to try to port NumPy and SciPy to the cRIO. I've been using those for prototyping up control loops on my desktop, and they are really nice.

Do sockets work? That would make it easy to add a telnet server to the robot, and allow remote execution of code to aid testing. Also, does print work correctly?
I haven't tested sockets yet. Theoretically they should work, but a lot has to be correct for them to work, and I might have missed something.

Yes, print works correctly.

Feel free to tackle NumPy and SciPy. FYI, to date, I've been integrating C/C++ modules directly into Python/Lib and Python/Modules/ (and updating Modules/config.c to add them to _PyImport_Inittab), because it's all a static executable anyway.
__________________
Creator of RobotPy - Python for FRC

2010 FRC World Champions (294, 67, 177)
2007 FTC World Champions (30, 74, 23)
2001 FRC National Champions (71, 294, 125, 365, 279)
Reply With Quote
  #7   Spotlight this post!  
Unread 10-26-2010, 01:49 AM
AustinSchuh AustinSchuh is offline
Registered User
FRC #0971 (Spartan Robotics) #254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Feb 2005
Rookie Year: 1999
Location: Los Altos, CA
Posts: 591
AustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond repute
Re: RobotPy: Python for FRC

Quote:
Originally Posted by Peter Johnson View Post
I haven't tested sockets yet. Theoretically they should work, but a lot has to be correct for them to work, and I might have missed something.

Yes, print works correctly.

Feel free to tackle NumPy and SciPy. FYI, to date, I've been integrating C/C++ modules directly into Python/Lib and Python/Modules/ (and updating Modules/config.c to add them to _PyImport_Inittab), because it's all a static executable anyway.
Thanks for the information. Unfortunately my course load is quite high this semester, so it might be quite a number of weeks until I get to NumPy and SciPy. But they are definitely on the list of things to do, and I'll let you know when I get time and get somewhere with them.
Reply With Quote
  #8   Spotlight this post!  
Unread 10-26-2010, 08:44 AM
Robototes2412's Avatar
Robototes2412 Robototes2412 is offline
1 * 4 != 14
FRC #2412 (Robototes)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2007
Location: Bellevue
Posts: 312
Robototes2412 is on a distinguished road
Re: RobotPy: Python for FRC

where does print go?
Reply With Quote
  #9   Spotlight this post!  
Unread 10-26-2010, 11:39 AM
Peter Johnson Peter Johnson is offline
With great power comes great I^2*R
FRC #0294 (Beach Cities Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Redondo Beach, CA
Posts: 139
Peter Johnson is a splendid one to beholdPeter Johnson is a splendid one to beholdPeter Johnson is a splendid one to beholdPeter Johnson is a splendid one to beholdPeter Johnson is a splendid one to beholdPeter Johnson is a splendid one to beholdPeter Johnson is a splendid one to beholdPeter Johnson is a splendid one to behold
Re: RobotPy: Python for FRC

Quote:
Originally Posted by Robototes2412 View Post
where does print go?
The cRIO console. There's a couple different ways to see it; NetConsole is probably the best (see http://www.chiefdelphi.com/forums/sh...ad.php?t=80146).
__________________
Creator of RobotPy - Python for FRC

2010 FRC World Champions (294, 67, 177)
2007 FTC World Champions (30, 74, 23)
2001 FRC National Champions (71, 294, 125, 365, 279)
Reply With Quote
  #10   Spotlight this post!  
Unread 10-26-2010, 05:41 PM
Robototes2412's Avatar
Robototes2412 Robototes2412 is offline
1 * 4 != 14
FRC #2412 (Robototes)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2007
Location: Bellevue
Posts: 312
Robototes2412 is on a distinguished road
Re: RobotPy: Python for FRC

I have basic driving functions and inputs programmed:

output.py
Code:
#Made by Sam Dodrill for Team 2412, WTFPL

from wpilib import Victor, Solenoid
import wpilib
import math

class Driver:
    def __init__(self, FL, FR, RL = None, RR = None):
        self.FLvictor = Victor(FL)
        self.FRvictor = Victor(FR)
        
        if RL != None and RR != None:become standard for the interpreter :)
            self.RLvictor = Victor(RL)
            self.RRvictor = Victor(RR)
            self.fourWheel = True
            
        
    def drive(self, speed):
        self.FLvictor.Set(speed)
        self.FRvictor.Set(-speed)
        
        if fourWheel:
            self.RLvictor.Set(speed)
            self.RRvictor.Set(-speed)
    
    def tankDrive(self, left, right):
        self.FLvictor.Set(left)
        self.FRvictor.Set(-right)
        
        if fourWheel:
            self.RLvictor.Set(left)
            self.FRvictor.Set(-right)
    
    def limit(self, n):
        if n > 1:
            return 1
        elif n < -1:
            return -1
        else:
            return n
    
    def arcadeDrive(self, speed, direction):
        left  = speed - direction
        right = speed + direction
        
        maxi = max(left, right)
        
        if maxi > 1:
            left = left/maxi
            right = right/maxi
        
        left = limit(left)
        right = limit(right)
        
        self.tankDrive(left, right)
        
    def holonomicDrive(self, power, slide, spin):
        fl = power + slide + spin
        fr = power - slide - spin
        rl = power - slide + spin
        rr = power + slide - spin
        
        fl = limit(fl);
        fr = limit(fr);
        rl = limit(rl);
        rr = limit(rr);
        
        self.setSpeed(fl, fr, rl, rr)
        
    def setSpeed(self, fl, fr, rl, rr):
        self.FLvictor.Set(fl)
        self.FRvictor.Set(-fr)
        self.RLvictor.Set(rl)
        self.RRvictor.Set(-rr)
        
    def goLeft(self):
        self.holonomicDrive(0, 0.5, 0)
    
    def goRight(self):
        self.holonomicDrive(0, -0.5, 0)
    
    def goForward(self):
        self.holonomicDrive(0.5, 0, 0)
    
    def goBackward(self):
        self.holonomicDrive(-0.5, 0, 0)
    
    def turnLeft(self):
        self.holonomicDrive(0, 0, -0.5)
        
    def turnRight(self):
        self.holonomicDrive(0, 0, 0.5)
    
    def stop(self):
        print("OH CRAP")
        self.drive(0)
input.py:
Code:
#made by Sam Dodrill for team 2412, but you can use it too

import wpilib, math

class Attack3:
    def __init__(self, port)
        self.joy = wpilib.Joystick(port)
    
    def getX(self):
        return self.joy.GetRawAxis(2)
    
    def getY(self):
        return self.joy.GetRawAxis(1)
    
    def getThrottle(self):
        return self.joy.GetRawAxis(3)
    
    def getTrigger(self):
        return self.joy.GetRawButton(1)
    
    def get2(self):
        return self.joy.GetRawButton(2)
    
    def get3(self):
        return self.joy.GetRawButton(3)
    
    def get4(self):
        return self.joy.GetRawButton(4)
    
    #yada yada yada, TODO: finish with all 11 buttons
    
def calcBuffer(self, n):
    buffers = 0.2
    if math.abs(n) < buffers:
        n = 0
        
    return n
    
class Xbox:
    def __init__(self, port):
        self.joy = wpilib.Joystick(port)
    
    def getStick(self, n1, n2): #returns a list in the form of [x,y]
        r = list()
        r.append(calcBuffer(self.joy.GetRawAxis(n1)))
        r.append(calcBuffer(self.joy.GetRawAxis(n2)))
        return r
    
    def getLeftStick(self):
        return self.getStick(1,2)
    
    def getRightStick(self):
        return self.getStick(4,5)
    
    def getButtons(self, n1, n2, n3, n4): #returns a list in the form of [b1, b2, b3, b4]
        r = list()
        r.append(self.joy.GetRawButton(n1))
        r.append(self.joy.GetRawButton(n2))
        r.append(self.joy.GetRawButton(n3))
        r.append(self.joy.GetRawButton(n4))
        
        return r
        
    def getMainButtons(self): #returns [a,b,x,y]
        return self.getButtons(1, 2, 3, 4)
Reply With Quote
  #11   Spotlight this post!  
Unread 10-26-2010, 06:43 PM
Robototes2412's Avatar
Robototes2412 Robototes2412 is offline
1 * 4 != 14
FRC #2412 (Robototes)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2007
Location: Bellevue
Posts: 312
Robototes2412 is on a distinguished road
Re: RobotPy: Python for FRC

Code Zipped up and is attatched.

First Release, nothing fancy
Attached Files
File Type: zip py.zip (3.0 KB, 34 views)
Reply With Quote
  #12   Spotlight this post!  
Unread 10-26-2010, 10:29 PM
Peter Johnson Peter Johnson is offline
With great power comes great I^2*R
FRC #0294 (Beach Cities Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Redondo Beach, CA
Posts: 139
Peter Johnson is a splendid one to beholdPeter Johnson is a splendid one to beholdPeter Johnson is a splendid one to beholdPeter Johnson is a splendid one to beholdPeter Johnson is a splendid one to beholdPeter Johnson is a splendid one to beholdPeter Johnson is a splendid one to beholdPeter Johnson is a splendid one to behold
Re: RobotPy: Python for FRC

Quote:
Originally Posted by AustinSchuh View Post
Thanks for the information. Unfortunately my course load is quite high this semester, so it might be quite a number of weeks until I get to NumPy and SciPy. But they are definitely on the list of things to do, and I'll let you know when I get time and get somewhere with them.
I glanced at NumPy/SciPy. NumPy should be straightforward. SciPy, however, requires a Fortran compiler, which isn't included with WindRiver. It should be possible to build a cross-compiler but it will definitely take more work.
__________________
Creator of RobotPy - Python for FRC

2010 FRC World Champions (294, 67, 177)
2007 FTC World Champions (30, 74, 23)
2001 FRC National Champions (71, 294, 125, 365, 279)
Reply With Quote
  #13   Spotlight this post!  
Unread 10-26-2010, 11:58 PM
AustinSchuh AustinSchuh is offline
Registered User
FRC #0971 (Spartan Robotics) #254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Feb 2005
Rookie Year: 1999
Location: Los Altos, CA
Posts: 591
AustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond repute
Re: RobotPy: Python for FRC

Quote:
Originally Posted by Peter Johnson View Post
I glanced at NumPy/SciPy. NumPy should be straightforward. SciPy, however, requires a Fortran compiler, which isn't included with WindRiver. It should be possible to build a cross-compiler but it will definitely take more work.
Hmm. That does complicate things. Something else to add to the list of prereqs for SciPy. It looks like some of what I assumed was in SciPy is also in NumPy (matricies, for example) so NumPy might be enough. At the very least, it'll help quite a bit.
Reply With Quote
  #14   Spotlight this post!  
Unread 10-27-2010, 08:14 AM
virtuald virtuald is offline
Registered User
AKA: Dustin Spicuzza
FRC #1418
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Northern Virginia
Posts: 513
virtuald is a splendid one to beholdvirtuald is a splendid one to beholdvirtuald is a splendid one to beholdvirtuald is a splendid one to beholdvirtuald is a splendid one to beholdvirtuald is a splendid one to behold
Re: RobotPy: Python for FRC

This is totally awesome. When I saw the Lua thing, I was thinking the same thing, so I'm glad someone took the time to do it. I'll have to try it on the bot later.
__________________
Co-maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables (NetworkTables for Python)

Team #1418: 2014 VA Regional: Finalists, #2 seed overall, Industrial Design Award; DC Regional: Finalists, #6 alliance captain
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


FRC Software Resources (including 2014 python code): http://www.virtualroadside.com/FRC/
WPILib Doxygen Repo: http://www.virtualroadside.com/WPILib/index.html
Reply With Quote
  #15   Spotlight this post!  
Unread 10-27-2010, 06:42 PM
Zach O's Avatar
Zach O Zach O is offline
I probably text you
AKA: @FRCZach
no team
Team Role: Alumni
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Atlanta, GA
Posts: 505
Zach O has a reputation beyond reputeZach O has a reputation beyond reputeZach O has a reputation beyond reputeZach O has a reputation beyond reputeZach O has a reputation beyond reputeZach O has a reputation beyond reputeZach O has a reputation beyond reputeZach O has a reputation beyond reputeZach O has a reputation beyond reputeZach O has a reputation beyond reputeZach O has a reputation beyond repute
Send a message via Skype™ to Zach O
Re: RobotPy: Python for FRC

I'm super excited to see this! I love Python as a langue, and I can't wait to maybe load this on a practice robot.
__________________
Check out my sites - FRC Megaphone
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Im doing something wrong here (python) Robototes2412 Programming 9 08-30-2010 11:05 PM
Programing with Python Lord Byron Programming 5 08-25-2009 09:26 PM
Looking for FRC teams for calendar fundraiser SciDKelly134 Fundraising 9 06-18-2009 10:55 AM
Favorite Monty Python Sketch/Movie Joe Matt Chit-Chat 47 03-30-2004 08:45 PM
monty python [split from thread: big jump, up to 131] Carolyn Duncan Chit-Chat 23 07-30-2001 07:46 PM


All times are GMT -5. The time now is 03:39 PM.

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


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