xybotsim

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 26, 2022 License: MIT Imports: 9 Imported by: 0

README

XY Bot Simulator

Platform Tests GitHub tag (Latest by date) GitHub all releases

Run extremely simple simulations of "turtlebot" style robots.

Features

  • 🤖 Test robot controllers written in Go with software-in-the-loop simulations.
  • 💯 Run large scale multi-agent scenarios with hundreds of robots.
  • 💥 Simulate robot collisions with obstacles and other robots.
  • 📘 Connect your code easily with the most simple API.
  • 📺 Visualize simulations in real-time with a minimal GUI.

But don't get your hopes too high, this will be dots moving on a grid 😅 If you are looking for a proper robotics simulator, you should checkout Gazebo.

XY Bot Simulator's design is actually very minimalist :

  • Simulated world is a 2D squared grid.
  • Robot moves from cell to cell with a chosen velocity.
  • Movement is discrete & limited to adjacent cells (no diagonal).

Prerequisites

To run your simulations using XY Bot Simulator you will need Go version 1.17 or later, a C compiler and your system's development tools. Although XY Bot Simulator is virtually supported on any platforms with Go and a C compiler, it has been fully tested only with macOS 13 on Apple Silicon.

Using the standard Go tools you can install XY Bot Simulator's core library using:

go get github.com/floriankarydes/xybotsim

Getting Started

Open a new file my_simulation.go and you're ready to setup your first simulation!

package main

import (
  "github.com/floriankarydes/xybotsim"
)

func main() {

  // Create a new simulator with a 10x10 world grid.
  simulator := xybotsim.NewSimulator(10)

  // Spawn a new robot in simulator world on cell (5,5).
  // Set robot velocity to 1 cell per second
  robot, _ := simulator.AddRobot("robot", 5, 5, 1)

  // Command the robot in a 1x1 square pattern (async)
  go func() {
    for i := 0; i < 4*3; i++ {
      switch i % 4 {
      case 0:
        robot.EnqueueCommand(xybotsim.North)
      case 1:
        robot.EnqueueCommand(xybotsim.East)
      case 2:
        robot.EnqueueCommand(xybotsim.South)
      case 3:
        robot.EnqueueCommand(xybotsim.West)
      }
    }
  }()

  // Display the simulated world on screen
  simulator.Show()
}

And you can run that simply as:

go run my_simulation.go

It should look like this:

First simulation preview

The black square is a robot and the cells marked as occupied are greyed out. When moving from one cell to another, a robot occupy both cell for the duration of the movement.

Going further

Please checkout the examples available to learn how to run more complex simulation scenarios. Full documentation is available on pkg.go.dev.

Documentation

Overview

Run extremely simple simulation of a set of "turtlebot" style robots.

Index

Constants

View Source
const (
	North direction = iota + 1
	East
	South
	West
)

Cardinal directions.

Variables

This section is empty.

Functions

This section is empty.

Types

type Robot

type Robot struct {
	// contains filtered or unexported fields
}

Robot that lives on the world grid of a Simulator.

See AddRobot.

func (*Robot) EnqueueCommand

func (r *Robot) EnqueueCommand(d direction) error

Send a new command (i.e unit step in a given cardinal direction) to robot. Commands are processed one after the other at a rate constrained by the robot velocity.

See AddRobot.

func (*Robot) GetPosition

func (r *Robot) GetPosition() (x uint, y uint)

Get coordinates of the cell occupied by robot.

type Simulator

type Simulator struct {
	// contains filtered or unexported fields
}

Simulator for multi-robots scenario on 2D grid.

func NewSimulator

func NewSimulator(size uint) (s Simulator)

Create a new simulator instance with a given world size. World is a square grid of dimension `size` x `size`.

func (*Simulator) AddRobot

func (s *Simulator) AddRobot(id string, x uint, y uint, velocity float32) (*Robot, error)

Spawn a new robot on a give cell in the simulator's world grid. New robots are registered under a unique string ID on creation. Robots have constant velocity expressed in cell per second.

func (*Simulator) DeleteRobot

func (s *Simulator) DeleteRobot(id string) error

Remove an existing robot from the simulator's world.

func (*Simulator) ListRobots

func (s *Simulator) ListRobots() (robotArray []*Robot)

List all robots living in the simulator's world.

func (*Simulator) Show

func (s *Simulator) Show()

Display a minimal visualization of the simulator's world on screen.

This should be called near the end of a main() function as it will block until window is closed.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL