PDA

View Full Version : Python WPILib Reference?


WizenedEE
08-27-2011, 02:10 AM
Hello there,

I'm looking to try out programming in python, but I can't figure out what functions/classes/etc exist. Is there some sort of simple reference that lists the functions, parameters, returns, and a sort description of what they do? Or is there a file in the robotpy folder that defines them? Going off examples involves a lot of guesswork, which is tough without a C-RIO.

I did find something that says, "They're basically the same as the c++ ones but some of them are different" which wasn't very helpful, especially since I don't know the c++ functions! If anyone has a page on the c++ functions, that would be nice also.

Thanks for the help!

Peter Johnson
08-27-2011, 11:25 PM
It's available in a couple of places online (just search for "WPILib reference"):

http://devildawgs549.com/2011_WPILib/WPILibC++Reference.html

http://amhsrobotics.com/wpilib/html/annotated.html

WizenedEE
08-28-2011, 02:58 AM
Thank you, those look great.

Is there a place where I can look at the source code of all the wpilib python functions, somewhere in the robotpy file that's on github?

Peter Johnson
08-28-2011, 11:09 PM
The Python WPILib is mostly just a wrapper around the C++ one, generated by a tool called SIP (this is unlike Java, where the Java WPILib is written entirely in Java itself). The code is located in https://github.com/robotpy/robotpy/tree/2011/Packages/wpilib

The wpilib.py file is what you get when you "import wpilib", and is the only real Python file. It reimplements the robot base classes (e.g. IterativeRobot) for technical reasons (the C++ robot class runs the Python interpreter so you can't overload it directly from Python).

The rest of the library is implemented through code generated from the sip files in the sip/ directory. These are (for the most part) just stripped down copies of the C++ header files with a few tweaks where necessary to support reasonable parameter passing to and from Python.

Ziv
09-02-2011, 11:26 PM
Peter, thanks for bringing Python to FRC!
I poked around for a while in the links you mention, but I still have one question: does one need to do anything special to specify values of types such as EncodingType? Is the proper syntax just "enc = wpilib.Encoder(1, 2, False, k4x)" or something fancier?

Peter Johnson
09-03-2011, 11:06 PM
Peter, thanks for bringing Python to FRC!
I poked around for a while in the links you mention, but I still have one question: does one need to do anything special to specify values of types such as EncodingType? Is the proper syntax just "enc = wpilib.Encoder(1, 2, False, k4x)" or something fancier?

Constants are scoped into the class where they are defined. E.g. "wpilib.Encoder.k4x", "wpilib.Relay.kReverse", etc.

DjMaddius
09-24-2011, 07:42 PM
Are we allowed to use Python this year? That would be incredible! Python is easily on the top of my favorite languages. It makes things that would normally take lots of code in one language into just a few short lines.

If we can use Python, we are all set this year. Not a fan of labview D:

Peter Johnson
09-24-2011, 11:27 PM
Are we allowed to use Python this year? That would be incredible! Python is easily on the top of my favorite languages. It makes things that would normally take lots of code in one language into just a few short lines.

If we can use Python, we are all set this year. Not a fan of labview D:

Until the 2012 game manual is released, we won't know for sure, but all indications are that it (and other scripting languages like Lua) will be legal. One positive indication: both teams 294 (ported Python) and 973 (ported Lua) are control system beta testers for 2012.

DjMaddius
09-25-2011, 12:38 PM
Awesome! Really looking forward to it this year. Thanks for the info.

virtuald
09-26-2011, 02:05 PM
We used python last year, it was fantastic. :)

DjMaddius
09-26-2011, 02:46 PM
Been talking with the others involved and it looks like we are going to do Labview and python parallel together this year! Im doing the python and one of the mentors is doing labview. He prefers labview because he did it at Comau.

Really looking forward to my third year programming for the team! Im glad their is a nice community on python now. I had no idea the opportunity was there last year.

LinuxArchitect
10-05-2011, 01:52 PM
it looks like we are going to do Labview and python parallel together this year!

You're not alone. We're doing the same thing, beta testing labview and developing our python skills in parallel. A third team might sneak in with Java as well. We'll have an in-house autonomous challenge in December and then decide on which language to use for competition season.

George/Team 53

DjMaddius
10-11-2011, 07:59 PM
Thats a good idea, put the students to the test to see which language to follow. See which one we are strongest at, and get some experience in as well. Im going to bring this idea up at our meeting on Thursday. Thanks haha.