The Toast Module that allows you to code in Ruby!
Ruby on Wheels is a Toast Module that allows loading and compiling of Ruby scripts into the classpath, much like the inbuilt Groovy support. This is made possible by the JRuby API. A simple Ruby file to be loaded by RubyOnWheels is shown below:
#TestScript.rbputs"Hello World!"# Prints to Toast's loggermotor=Toast::Motor.new:talon,:can,1# Creates a new Talon on the CAN Bus with ID 1motor.set0.4# Set the motor speed to 0.4 (40%)Additionally, other ruby files can be loaded within these scripts like so
#RequireMe.rbclassRequireMedefexecuteputs"Require Me!"endend#Module.rbclassModulerequire'RequireMe'req=RequireMe.newreq.executeend#->Require Me!Additionally, Ruby code can be compiled immediately via the CommandBus, similar to the 'Script' command present in the Toast core. This command can be executed as such.
rubyputs"Hello from the Command Bus!"#->Hello from the Command Bus!Here is an example of many of RubyOnWheels' most notable functions. For more details, look in the repository to see the Ruby SRC
Toast::Log << "Ruby Program Starting!"# These 2 methods do the same thingputs"Ruby Program also Starting!"# They write to Toast's LoggerToast::Log.puts:error,"Oh no!"# Writes an error to Toast's Loggerputs"Am I connected to FMS? #{Toast.FMS?}"# We include hooks for FMS, Simulation, whateverputs"Am I in a simulated environment? #{Toast.simulation?}"motor_1=Toast::Motor.new1# Most subclasses havemotor_2=Toast.motor2# a method shortcut to the constructormotor_1.set0.5motor_2.set -0.5motor_3=Toast::Motor.new:jaguar,:pwm,3# Define your motor type and interfacedrive=Toast::Drive.new5,6,7,8# RobotDrive is implemented as welldrive.tank0.75,0.75drive.mecanum0.8,0.4,0.2# Mecanum drive was never easierdrive.polar1,20,0.4Toast.go{# Need a new thread? Got ya famputs"Hello World!"}Toast.tick:autonomousdo# Equivilant of autonomousPeriodic# ...endToast.tick{# Periodic for all modes (disabled, autonomous, teleop, test)# ...}Toast.transition:teleopdo |state,oldState| # Need to check when we switch modes? No probputs"I'm now in #{state} (I was in #{oldState})"endToast.command"test_command_pls_ignore"do |args| # Easy access to the CommandBusputs"Test: #{args}"endjava_import"some.non.toast.package.MyClass"# Did we miss a hook? No problem, it's easy to call it yourself.MyClass.my_methodFor more information on how Ruby implements with Java, take a look at the JRuby Repository
Downloads (stable) can be found on the releases, and is similar in deployment to any other Toast module. For more details, refer to the Toast Repository.
If you wish to build the Module yourself from the SRC, you may do the following:
- Fork this Repo
- Mirror it to your local machine
- Run
gradlew ideaorgradlew eclipse, depending on your Development Environment. - Run
gradlew deployto deploy to the RoboRIO