Giter Site home page Giter Site logo

pyrocketsim's Introduction

pyrocketsim

Python bindings for RocketSim using pybind11

Clone & Build

git clone https://github.com/uservar/pyrocketsim
cd pyrocketsim
cmake -B ./build -DCMAKE_BUILD_TYPE=Release
cmake --build ./build --config Release --parallel

The built binaries will either be in ./build/ or ./build/Release/

Note: As a limitation of using pybind, binaries will only work with the specific python version that was used in building them.

Example Usage

import pyrocketsim as RS


# setup rocketsim arena
tick_rate = 120
arena = RS.Arena(RS.SOCCAR, tick_rate)
print(f"Arena tick rate: {arena.tick_rate}")


# setup ball initial state
ball_state = arena.ball.get_state()
ball_state.pos = RS.Vec(0, 0, 500)
ball_state.vel = RS.Vec(0, -6000, 0)  # A ball with 0 vel will not fall
arena.ball.set_state(ball_state)
print("Set ball state")

# setup rocketsim cars
for i in range(2):
    team = RS.BLUE if i % 2 else RS.ORANGE
    car = arena.add_car(team, RS.OCTANE)
    car_state = car.get_state()
    car_state.boost = 100
    car_state.pos = RS.Vec(car.id * 200, car.id * 200, 200)
    car_state.vel = RS.Vec(100, 100, 100)
    car_state.ang_vel = RS.Vec(0, 0, 5.5)
    car.set_state(car_state)
    print(f"Car added to team {team} with id {car.id}")

# set car controls
car = arena.get_cars()[0]
car_controls = RS.CarControls(throttle=1, pitch=-1)
car.set_controls(car_controls)

# do any number of steps
arena.step(6)

# some classes have custom __format__ functions
car_state = car.get_state()
print(f"{car_state.last_controls = }")
print(f"{car_state.pos = :.2f}")
print(f"{car_state.rot_mat = :.2f}")

# there's some helper functions
arena.set_goal_score_call_back(lambda arena, team: print(f"{team} scored!"))
arena.step(100)

old_arena = arena.clone(copy_callbacks=False)
old_arena.write_to_file("arena_file_path")
same_old_arena = RS.Arena.load_from_file("arena_file_path")

arena.reset_to_random_kickoff()

If you want an idea of what's included in the bindings you can either read the source code or pydoc pyrocketsim.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.