A simple library for controlling robots using Ruby.
Bots is a simple library for controlling robots. You can use the library to create controller scripts that manipulate robots. The current version only controls legged robots. The example hex.rb
controller script allow you to control a hexapod robot.
Bots has a built-in simulator created using the Bullet Physics Library. You can use the simulator to test run your controller scripts. You can either run it real-time or dump the output of your controller script to a sequence file to be loaded on the simulator.
This library uses the hexapod simulator by Bill Hsu.
Here's a hexapod controlled using Bots in action.
To run this in simulator mode:
- Clone this repository
- Run
bundle install
to install the files - Create a robot controller file by requiring
bots.rb
- Run the robot controller file in REPL using pry
pry -r ./hex.rb
(assuming your controller file is namedhex.rb
) - To exit the REPL enter
!!!
and press enter
To run this in the sequence dump mode:
- Clone this repository
- Run
bundle install
to install the files - Create a robot controller file by requiring
bots.rb
- Run the robot controller file in REPL using pry
pry -r ./hex.rb
- When have finished your activities the REPL would have dumped your activities into a
.seq
file - Exit the REPL
- Run
./load.rb xxx.seq
wherexxx.seq
is your sequence file
Creating a robot controller is straightforward.
class Hexapod < Bots::Controller
...
end
You should call the constructor of your superclass with the type of engine, create legs and do whatever else you want to initialize the robot. In the example below I am creating legs for a hexapod i.e. robot with 6 legs.
def initialize(type=:sim)
super(type)
@legs = {}
@legs[:front_left] = Leg3DOF.new(:left, 1, 2, 3)
@legs[:middle_left] = Leg3DOF.new(:left, 4, 5, 6)
@legs[:back_left] = Leg3DOF.new(:left, 7, 8, 9)
@legs[:front_right] = Leg3DOF.new(:right, 32, 31, 30)
@legs[:middle_right] = Leg3DOF.new(:right, 29, 28, 27)
@legs[:back_right] = Leg3DOF.new(:right, 26, 25, 24)
@left_legs = [:front_left, :middle_right, :back_left]
@right_legs = [:front_right, :middle_left, :back_right]
end
In the example below we're creating a method to simplify moving the bot.
def move(leg, c, f, t)
execute @legs[leg].actuate(c, f, t)
end
the Leg3DOF
has a method actuate
that moves the 3 servos controlling the leg (coxa, femur and tibia) at the same time. In the move
method we call actuate on the chosen leg, then execute the action. the execute
method executes the leg actuation and creates the command that is then sent to the controller's engine.
For more information please read the source code for the sample hexapod hex.rb