Log in

View Full Version : Announcing FIRSTLua


zombiezen
19-10-2010, 01:26
Hello, teams!

I would like to announce a project that we (Team 973) have been working on during the off-season: FIRSTLua. FIRSTLua is a fully functioning Lua interpreter that can be used for developing robot control code.

Some advantages of using Lua:

Lua is (arguably) easier to learn than C
Live code reloads
Errors won't crash the robot
Lua provides automatic garbage collection
WindRiver isn't needed after the base code is installed. Just a text editor and an FTP client. :)


This is beta-quality software: we have had success using Lua on our robot, but your mileage may vary. Examples and documentation are included. We are announcing this project now in the hopes that other teams will find it useful and will want to test it and contribute to it. By the time build season comes around, we'd like this to be a viable option for writing FIRST control code. Please help us out by reporting any bugs you find, and happy coding!

Project Page:
http://redmine.zombiezen.com/projects/firstlua

README:
http://redmine.zombiezen.com/projects/firstlua/repository/entry/README.txt

Download:
http://redmine.zombiezen.com/projects/firstlua/files

FIRSTLua is released under an MIT Open Source License, as detailed in the README.

AdamHeard
19-10-2010, 01:28
We'll be running two different and unique robots in 1323's offseason in November running Lua to fully test it out.

Peter Johnson
19-10-2010, 02:14
What a great idea and great work putting it all together! Since you're using SWIG, given the work you've done so far, it will make life easier for people who want to try adding other scripting languages in the future (Python anyone?).

zombiezen
19-10-2010, 12:00
What a great idea and great work putting it all together! Since you're using SWIG, given the work you've done so far, it will make life easier for people who want to try adding other scripting languages in the future (Python anyone?).

I would love to see Python working on the cRIO! I am a hard-core Python user and advocate, and that's what we first tried, but we ran into some troubles with that. Not to say that Python is impossible to get working or shouldn't be done, but let me give you a little history of the FIRSTLua project.

Before settling on Lua, one of our first attempts was getting the Python 3 interpreter working. However, Python rather heavily depends on having Unicode strings, which vxWorks doesn't provide. Along with that and a multitude of other compiler and linker errors to sort out, we decided we didn't have the development time to get it done. It's certainly possible to get Python working (and I'd love to see it), but after evaluating the performance characteristics and necessary development time, we settled on Lua.

We also found that Lua gives some flexibility that Python doesn't offer (though it pains me to admit it). Lua's core library is small, so it gives the team the option to pick what they need. Also, Lua's handling of modules is more favorable when trying to implement live code reloading (it can be done in Python, but it would be less straightforward). All of that aside, Lua is also designed to work on a smaller footprint than Python. The bulk of the code size when fully built is the WPILib wrapper (~20K lines of generated code), not Lua.

None of this is to say teams shouldn't try to get Python working. I would love that. :) I just would like to warn everybody of some of the difficulties we ran into while trying to do it.

AustinSchuh
19-10-2010, 13:15
I would love to see Python working on the cRIO! I am a hard-core Python user and advocate, and that's what we first tried, but we ran into some troubles with that.

If you are interested in working on getting Python working some time, let me know. I'd love to use Python for testing out algorithms. And nice work getting Lua to run!

Dustin Shadbolt
19-10-2010, 14:49
Amazing idea! I hope it goes well.

demosthenes2k8
19-10-2010, 16:07
YES! Now I have an excuse to learn Lua!

lynca
19-10-2010, 20:12
Before settling on Lua, one of our first attempts was getting the Python 3 interpreter working. However, Python rather heavily depends on having Unicode strings, which vxWorks doesn't provide. Along with that and a multitude of other compiler and linker errors to sort out, we decided we didn't have the development time to get it done. It's certainly possible to get Python working (and I'd love to see it), but after evaluating the performance characteristics and necessary development time, we settled on Lua.

We also found that Lua gives some flexibility that Python doesn't offer (though it pains me to admit it). Lua's core library is small, so it gives the team the option to pick what they need. Also, Lua's handling of modules is more favorable when trying to implement live code reloading (it can be done in Python, but it would be less straightforward). All of that aside, Lua is also designed to work on a smaller footprint than Python. The bulk of the code size when fully built is the WPILib wrapper (~20K lines of generated code), not Lua.

None of this is to say teams shouldn't try to get Python working. I would love that. :) I just would like to warn everybody of some of the difficulties we ran into while trying to do it.

Thank you for writing this, I was waiting for Python to be ported but sadly too many hurdles for now.

Regardless, Lua is also an interpreted language that will open up programming to a much broader audience than C++/Java

Universities teach Computer Science freshmen interpreted Languages (Scheme, Python) with great success.

Robototes2412
19-10-2010, 22:21
Can this interpreter be adapted to use perl grammar?

davidthefat
19-10-2010, 23:55
Oh man, our team is a mess... I think I will be the only full time competent programmer in our team. I would have to teach rest of the programmers. One guys didn't know C++ had classes -__- I know, thats pretty bad. I been talking about off season work ever since the end of the competition, it never happened, especially me working on the autonomous mode of the robot. So I also had the plan of creating a LUA interpretor for the robot, but you guys did it for me, thank you, I am not sure if I would be using it but thank you in advance and I will give you credit if I ever use it

zombiezen
20-10-2010, 00:54
Can this interpreter be adapted to use perl grammar?

No, not directly. The interpreter being used is just a patched version of off-the-shelf Lua; you would have to get Perl working from scratch. I haven't looked at the Perl codebase too extensively, but it looks like it would be an effort.

The only thing that may be of use from here (if you were determined) is the SWIG interface file that I assembled from the WPILib headers.

Peter Johnson
24-10-2010, 01:02
I would love to see Python working on the cRIO! I am a hard-core Python user and advocate, and that's what we first tried, but we ran into some troubles with that.

I was inspired by your work and... ported Python to the cRIO. It's working well enough to initialize and print sys.modules.keys() using PyRun_SimpleString(). Next steps: load and run a .py file rather than using PyRun_SimpleString(), and port your SWIG WPILib wrappers to Python.

Not yet ready for prime time like your Lua port is, but I wanted to let folks know I've got it at least minimally running. I'll make another announcement when I've got WPILib-using code running and it's ready for other people to really experiment with.

Git repo at: http://git.tortall.net/cgit.cgi/RobotPy.git/
I recommend TortoiseGit for getting a copy on Windows.

On another note: you may want to rename your project to not use the FIRST name. FIRST recently became more sensitive about such things as they've trademarked the "FIRST" name and thus have to protect it from dilution. I named my Python port "RobotPy" for this reason; you might want to rename yours to "RobotLua" or something similar.

AustinSchuh
24-10-2010, 01:06
I was inspired by your work and... ported Python to the cRIO. It's working well enough to initialize and print sys.modules.keys() using PyRun_SimpleString().

Thanks a bunch for doing this! I'm very excited! While I don't have access to a robot to try to help right now, I'd love to help test it and fix it up. Unfortunately, I'm probably booked until the semester ends. Please keep me/us updated.

Robototes2412
24-10-2010, 18:26
Python? <3

I can finally teach the freshmen how to do more with less.

see http://teddziuba.com/2010/10/taco-bell-programming.html

Robototes2412
24-10-2010, 18:50
sorry for the double-post, but I can't get it compile.

it spat out this:

MainRobot.cpp:28:20: Python.h: No such file or directory
MainRobot.cpp: In member function `virtual void PyRobot::StartCompetition()':
MainRobot.cpp:75: error: `Py_SetPythonHome' undeclared (first use this function)
MainRobot.cpp:75: error: (Each undeclared identifier is reported only once for each function it appears in.)
MainRobot.cpp:76: error: `Py_Initialize' undeclared (first use this function)
MainRobot.cpp:79: error: `PyRun_SimpleFile' undeclared (first use this function)
MainRobot.cpp:86: error: `Py_Finalize' undeclared (first use this function)
make: *** [PPC603gnu_DEBUG/MainRobot.o] Error 1

Robototes2412
24-10-2010, 19:04
triple-posing aside, I got it to compile.

I had to put a pyconfig.h file in EVERY folder in the Python subdir, please update this on your git tree

jhersh
24-10-2010, 19:20
triple-posing aside, I got it to compile.

I had to put a pyconfig.h file in EVERY folder in the Python subdir, please update this on your git tree

Of you could just add the include dir in your make process. "-I"

Robototes2412
24-10-2010, 20:59
when compiling it on linux, you can't edit the makefile or BAD THINGS HAPPEN

AustinSchuh
24-10-2010, 22:02
when compiling it on linux, you can't edit the makefile or BAD THINGS HAPPEN

You can easily modify the makefile. It just takes a little care and understanding what the commands do. Adding the -I flag has worked for me before, and is probably used in the makefile already to include the WPILib headers.

Peter Johnson
24-10-2010, 23:06
What may have happened is originally the git repo included a PPC603gnu/Makefile; this generated file pointed to specific paths on my machine and is not regenerated by default. I've since removed it from the repo so now WindRiver should generate it for you with the correct include paths.

In other news, I'm now running robot teleop code in Python. I need to make a couple of release .zip's so people don't have to build it from scratch, then I'll create a new Chief Delphi thread with a formal announcement.

I also added a new branch to the repo for those using CAN bus. Unfortunately the CAN bus version needs some symbols that are only available when the CAN bus driver is installed on the robot, so I have to have two separate releases.

Radical Pi
24-10-2010, 23:22
I also added a new branch to the repo for those using CAN bus. Unfortunately the CAN bus version needs some symbols that are only available when the CAN bus driver is installed on the robot, so I have to have two separate releases.

Are you sure about that? I thought the CAN drivers didn't provide the public symbols and the ones that are called by user code come from the NetworkCommunication library (for security reasons).

Peter Johnson
24-10-2010, 23:29
Are you sure about that? I thought the CAN drivers didn't provide the public symbols and the ones that are called by user code come from the NetworkCommunication library (for security reasons).

Hmm, you might be right, as the external symbols just seem to be FRC_NetworkCommunication_JaguarCANDriver_sendMessa ge/receiveMessage. I just didn't have a cRIO without CAN configured to test on today, so wasn't sure. If someone could test it to confirm, I'll merge the branch into master. If someone else doesn't get to it first, I'll test it myself on Wednesday (when I have access to the robot again). Thanks!

zombiezen
26-10-2010, 23:24
On another note: you may want to rename your project to not use the FIRST name. FIRST recently became more sensitive about such things as they've trademarked the "FIRST" name and thus have to protect it from dilution. I named my Python port "RobotPy" for this reason; you might want to rename yours to "RobotLua" or something similar.

Good point. Renamed everything to "Greyhound Lua". Updating links shortly.

EDIT: Darn, guess I can't update the main links. Here are the new ones:

Project Page:
http://redmine.zombiezen.com/projects/greyhoundlua

README:
http://redmine.zombiezen.com/projects/greyhoundlua/repository/entry/README.txt

Download:
http://redmine.zombiezen.com/projects/greyhoundlua/files