If you haven't done so already, please see the Installation instructions.
Writing your first program
Open up your favorite editor, and type:
-- robot.lua module(..., package.seeall)
The first line isn't strictly necessary: it's a comment. Lua ignores any text after the
-- to the end of the line, so you can keep notes on what the code does. The second line tells Lua that you want to start a new module. Continuing on:
function run() -- Main loop while true do if wpilib.IsDisabled() then disabled() repeat wpilib.Wait(0.01) until not wpilib.IsDisabled() elseif wpilib.IsAutonomous() then autonomous() repeat wpilib.Wait(0.01) until not wpilib.IsAutonomous() or not wpilib.IsEnabled() else teleop() repeat wpilib.Wait(0.01) until not wpilib.IsOperatorControl() or not wpilib.IsEnabled() end end end
This is a lot of code, and the details aren't too important, but it's basically making sure that when the robot changes modes (e.g. autonomous to teleoperated), the right part of your code is called.
So what happens what teleoperated period starts? That's what we're going to write next:
function teleop() while wpilib.IsOperatorControl() and wpilib.IsEnabled() do -- Run one cycle of teleoperated here... wpilib.Wait(0.01) end end
Basically, this just waits for the robot to disable. You'll change that later. And to complete our example:
function autonomous() -- Run autonomous code here... end function disabled() -- Do something in disabled mode here... end
Downloading to the robot
You download your code to the robot using an FTP client (like Cyberduck). Your computer's IP address must be statically set to
XXYY is your team number. Inside the FTP program, connect to
ftp://10.XX.YY.2/##, again, substituting XXYY
for your team number.
On the robot, create a folder called
lua (case is important), copy
into it, along with your new
Power cycle, and you are running Lua!
For more examples, see the samples/ directory.