Skip to content

sausheong/bots

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bots

A simple library for controlling robots using Ruby.

What is this?

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.

Bots library simulator demo

This library uses the hexapod simulator by Bill Hsu.

Here's a hexapod controlled using Bots in action.

Bots hexapod in action

How to use

To run this in simulator mode:

  1. Clone this repository
  2. Run bundle install to install the files
  3. Create a robot controller file by requiring bots.rb
  4. Run the robot controller file in REPL using pry pry -r ./hex.rb (assuming your controller file is named hex.rb)
  5. To exit the REPL enter !!! and press enter

To run this in the sequence dump mode:

  1. Clone this repository
  2. Run bundle install to install the files
  3. Create a robot controller file by requiring bots.rb
  4. Run the robot controller file in REPL using pry pry -r ./hex.rb
  5. When have finished your activities the REPL would have dumped your activities into a .seq file
  6. Exit the REPL
  7. Run ./load.rb xxx.seq where xxx.seq is your sequence file

How to create a robot controller

Creating a robot controller is straightforward.

Subclass Bots::Controller

class Hexapod < Bots::Controller 
  ...
end

Create a constructor for your controller

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

Do stuff with the robot!

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

About

Simple library for controlling robots using Ruby

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages