Git Product home page Git Product logo

bt-studio's Introduction

BT Studio

version distro Forks License

Introduction

BT Studio is an open-source tool crafted for the development of robotic applications. Its primary objective is to facilitate the quick deployment of behavior tree-based robotic applications within ROS 2. In BT Studio, a robotic app is defined as an graphical tree coupled with actions scripted in Python, which the tool then translates into a ROS 2 package. This process circumvents the unnecessary complexities often associated with ROS-specific configurations, offering developers a more streamlined approach.

Usage

Installation

  1. Clone the repo and enter it
git clone https://github.com/JdeRobot/bt-studio
cd bt-studio
  1. Install the necessary packages
sudo apt update
sudo apt install npm python3-vcstool python3-pip python3-rosdep python3-colcon-common-extensions python3-autopep8 -y
  1. Install the backend dependencies
cd backend
pip install virtualenv
virtualenv backend_env
source backend_env/bin/activate
pip install django djangorestframework
  1. Launch the backend
python3 manage.py runserver

Do not close the terminal where this is executing!. Django provides the necessary backend funcionalities. For continuing the process, simply open a new terminal.

  1. Install the appropiate nodejs version
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
source ~/.bashrc
nvm install 16
nvm use 16
  1. Install Yarn
sudo npm install --global yarn
  1. Setup the frontend

From the bt_studio folder:

cd frontend
yarn install
yarn start

A new window in the browser should have opened. If not, go to BT Studio

Generating apps

  1. Create new app

You may create a new app clicking the + button in the upper right corner, or swap to the the demo project clicking the change button next to it and typing demo. In the demo project, you may find a reference implementation of a bump and go app for a differential robot using a LIDAR. Feel free to explore and use whatever you need!

  1. Write actions

You may create as many actions as needed using the file browser. The actions must have a .py extension and follow this structure:

import py_trees

class TemplateAction(py_trees.behaviour.Behaviour):

    def __init__(self, name, ports = None):

        """ Constructor, executed when the class is instantiated """

        # Configure the name of the behaviour
        super().__init__(name)
        self.logger.debug("%s.__init__()" % (self.__class__.__name__))

        # Get the ports
        self.ports = ports

        ...

    def setup(self, **kwargs: int) -> None:

        """ Executed when the setup function is called upon the tree """

        # Get the node passed from the tree (needed for interaction with ROS)
        try:
            self.node = kwargs['node']
        except KeyError as e:
            error_message = "Couldn't find the tree node"
            raise KeyError(error_message) from e

        ...

    def initialise(self) -> None:

        """ Executed when coming from an idle state """

        ...

    def update(self) -> py_trees.common.Status:

        """ Executed when the action is ticked. Do not block! """

        ....
    
        return new_status

    def terminate(self, new_status: py_trees.common.Status) -> None:

        """ Called whenever the behavior switches to a non-running state """
        ...

For examples of how to use ports in your actions, please refer to the example actions provided with the repo in the actions folder. The structure is the same as py_trees actions, as this project uses the library underneath. Kudos to @stonier!

  1. Define the tree structure

Using the existing blocks, you may define the logic of your app. Here you have available all the defined actions. This can be done previously to step 2 if you prefer to define the logic of the tree before its implementation!

  1. Downloading the app

Clicking the green download button, a ROS 2 app is generated. This can be unziped in a ROS 2 workspace and installed as any other package.

Using the generated app

  1. You need to ROS 2 humble installed in your system. Please follow this guide if you haven't. After that, source the ros underlay. It is highly recommended to add this line at the end of your .basrhc file.
source /opt/ros/humble/setup.bash
  1. Moving the app to a ROS 2 ws
mkdir -p your_ws/src
mv your_app.zip your_ws/src
unzip your_ws/src/your_app.zip
  1. Init rosdep

You may have to init the ROS dependency manager if you haven't done it before.

sudo rosdep init
rosdep update
  1. Downloading auxiliary tools and dependencies

These are a testing environment in the Webots simulator and a tree execution visualizer.

cd src/your_app/
vcs import < demo/thirdparty.repos
cd ../..
rosdep install --from-paths src -r -y --ignore-src
  1. Compiling
colcon build --symlink-install
source install/setup.bash
  1. Launching a testing environment

You may choose whatever environment for your app to execute into, but we provide some prepared packages for convenience.

ros2 launch tb4_sim tb4_launcher.py
py-trees-tree-viewer
  1. Launching the app

Now, using the app executor, you may launch the app itself.

ros2 run your_app_name executor

Showcase

You can see a running application as reference here:

Showcase video

Roadmap

In the future, this project will have total integration with RoboticsAcademy, so developers will be able to deploy the trees in a dockerized environment.

bt-studio's People

Contributors

javizqh avatar jmplaza avatar omartinez2020b avatar oscarmrz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

bt-studio's Issues

shifted figures, buttons don't work (frontend)

Hi! I am a MacOS user and everything executes without error(in both terminals). However, I was trying to write&download some code to test in ROS afterward. But cannot download since I keep getting such display and some buttons are not active. What can be the reason?

Screenshot 2024-04-19 at 18 47 01

Proper execution time dependencies

tree_gardener creates executable trees and handles port access in the actions. Currently, It is a python package that the user has to install to run the generated package. It should be a ROS 2 package and included in the generated app.

Question

how does creating new actions, for example turn.py create a new node in your frontend.
What is the logic behind your node creation for action nodes.
image

tree_gardener module documentation

tree_gardener is the python module that provides the tree creation functionality to client programs like the generator and the executor.

It needs an API documentation, with proper formatting.

Web GUI for tree creation.

Currently, the app is generated by writing the XML structure and executing the different generation scripts. The goal of the next version is to develop a web frontend for writing action and tree creation. This opens the door to future integrations with a dockerized ROS 2 environment.

Upgrades before going online

This is a list of all of changes that will be done to BT Studio before the merge is done.

  • #94
  • #95
  • #96
  • #107
  • New dialog window for creating new files
  • #97
  • #104
  • #98
  • When creating a file always en with .py
  • #102
  • #99
  • #100
  • #105
  • BT sort button
  • #103
  • #101
  • Horizontal Bt (Maybe)
  • Add toggle between horizontal bt and vertical (Maybe)
  • Solving the Tab inconsistency from ACE
  • #106

Add interface buttons

The web frontend lacks some key interface buttons:

  • File deletion and creation
  • Saving a file
  • Removing blocks (and connections between them)

Working example: helloword

In order to illustrate the capabilities of the offline execution, a detailed guide of how to use the package must be created. It must comprise exact instructions in a md file. A video should also be recorded.

Serve the frontend through webpack

Currently, the execution of BT Studio uses two separate testing servers: the django for the backend and yarn for the frontend.

It would be a better approach to serve the frontend as another django webapp using webpack to bundle it.

Project support

The user should be able to save and load different projects, that is BT diagrams.

New documentation

There have been a lot of changes from version 0.1, the readme should explain the usage and the installation properly

Diagram json to tree xml translator

Once the user created a diagram, the library provides function to serialize its structure into a json file. This should be converted to a xml tree file

Tree editor improvement

Really nice project!

However I think there may be a few improvements:
1.- The zoom is really anti-intuitive.
2.- The selected node should be highlighted.
3.- A node should not have two parents.
4.- Baobab could be a great name for this project!!

Port GUI support

Currently, there is no port representation and no mechanism to input a value in them.

Offline execution

To do:

  • Implementation of remaining BT.cpp decorators.
  • Proper code structure. Translator must be ROS agnostic.
  • Usage example. Hello world.

Add indicator of when an app is running

When using the dockerized environment, the state of the execution is known. This could be used to change the run icon to a pause button, as in RA, leveraging the new RADI capabilities.

Proper dependencies handling

There are two different types of dependencies in BehaviorTrees:

  • Execution tools, such as tb4_sim, that should be handled via vcs.
  • User defined imports in the actions, that should be installable via rosdep. The translator should edit the xml so they can be found.

starting of the frontend doesnt work

Start the front end with the following code:

cd ..
 cd frontend
yarn install
yarn start

produced the following error:

00h00m00s 0/0: : ERROR: [Errno 2] No such file or directory: 'install'
00h00m00s 0/0: : ERROR: [Errno 2] No such file or directory: 'start'

Also, I think the installation process is still not very streamlined. I would recommend using a container for development. I asked bard how to add the installation process to a Docker container. Maybe this will help you:
Dockerfile:

FROM ros:humble

RUN source /opt/ros/humble/setup.bash

WORKDIR /opt/bt-studio
RUN git clone https://github.com/JdeRobot/bt-studio

RUN sudo apt update && sudo apt install python3-vcstool python3-pip python3-rosdep python3-colcon-common-extensions -y

WORKDIR /opt/bt-studio/backend
RUN pip install virtualenv
RUN virtualenv backend_env
RUN source backend_env/bin/activate
RUN pip install django djangorestframework
https://github.com/Guelakais
CMD python3 manage.py runserver

WORKDIR /opt/bt-studio/frontend
RUN yarn install
RUN yarn start

EXPOSE 3000

And now how to start it:

docker build -t bt-studio .
docker run -it -p 3000:3000 bt-studio

You should find the frontend at http://localhost:3000

Order of actions not according to what is shown in screen

The order of the actions is not updated properly and this causes the behavior tree to misbehave when executed.

Here is the video of how to recreate this behavior:

bug_order.mp4

And here is the incorrect bt:

<Root name="Tree Root">
  <BehaviorTree>
    <ReactiveSequence name="ReactiveSequence">
      <ReactiveFallback name="ReactiveFallback">
        <Inverter name="Inverter">
          <CheckObstacle name="CheckObstacle" amplitude="20" obs_dist="1.0" />
        </Inverter>
        <!-- The order should be the opposite -->
        <Turn name="Turn" />
        <Forward name="Forward" />
        <!--  -->
      </ReactiveFallback>
      <Forward name="Forward" speed="0.5" />
    </ReactiveSequence>
  </BehaviorTree>
    <Code>

Tree finishes without stopping the robot

Altough proper terminate() methods are written in the actions, in the Gazebo Simulator (doesn't happen in Webots), when the user finishes the execution, the terminate methods aren't called and the last command keeps executing. This could be dangerous in a real robot.

GUI improvements

The GUI needs a design revision. There are placeholder buttons yet and the button hovers are badly placed.

Proper code structure

Currently, the code is structured as a ROS 2 package. As the aim of the project is to provide a web based solution, the code needs a more agnostic structure.

Proper separation between tree generation and executing

The generation of a self contained tree is a key function of the system, and as such, it should be properly separated: the package should allow an ros-agnostic step of generation based on the tree xml and the actions, which can later be used to generate an executable tree.

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.