Skip to content

Commit

Permalink
adjust gains on the robot, move files and rename folders
Browse files Browse the repository at this point in the history
  • Loading branch information
pierfabre committed Jan 14, 2024
1 parent 750afcc commit da39fdb
Show file tree
Hide file tree
Showing 27 changed files with 305 additions and 425 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ repos:
"--extend-ignore",
"E203,E402,E501,F401,F841",
"--exclude",
"logs/*,data/*,furuta_gym/logging/protobuf/*",
"logs/*,data/*,furuta/logging/protobuf/*",
]

# yaml formatting
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,30 @@ In this repository you will find everything you need to build and train a rotary

If you have any question feel free to open an issue or DM me [@armand_dpl](twitter.com/armand_dpl).

## Usage
1. Plug-in the robot
2. Run `sudo dmesg | grep tty` in terminal to find which port is used for the device
3. run `python tests/interactive_robot_self_test.py`

## MLOps
During this project we leveraged [Weights and Biases](https://wandb.ai/site) MLOps tools to make our life easier. You can find our experiments, pre-trained models and reports [on our dashboard](https://wandb.ai/armandpl/furuta). You can also read more about [Training Reproducible Robots with W&B here](https://wandb.ai/armandpl/furuta/reports/Training-Reproducible-Robots-with-W-B--VmlldzoxMTY5NTM5).

## Credits
To make this robot work we built on top of existing work!
- We got the encoder precision and the idea to use a direct drive motor from the [Quanser Qube design](https://quanserinc.box.com/shared/static/5wnibclu7rp6xihm7mbxqxincu6dogur.pdf).
- We re-used bits from [Quanser's code](https://git.ias.informatik.tu-darmstadt.de/quanser/clients/-/tree/master/quanser_robots/qube). Notably:
- We re-used bits from [Quanser's code](https://git.ias.informatik.tu-darmstadt.de/quanser/clients/-/tree/master/quanser_robots/qube). Notably:
* their VelocityFilter class to compute the angular speeds
* their GentlyTerminating wrapper to send a zero command to the robot at the end of each episode
* their rotary inverted pendulum simulation
* their ActionLimiter class
- The arm assembly is inspired by this [YouTube video](https://www.youtube.com/watch?v=xowrt6ShdCw) by Mack Tang.
- The visualization we use for the simulation is copy-pasted from https://github.com/angelolovatto/gym-cartpole-swingup
- We use the [StableBaselines3](https://github.com/DLR-RM/stable-baselines3) library to train the robot.
- We use the [StableBaselines3](https://github.com/DLR-RM/stable-baselines3) library to train the robot.
- We implemented tricks from [Antonin Raffin's talk at RLVS 2021](https://www.youtube.com/watch?v=Ikngt0_DXJg).
* HistoryWrapper and continuity cost
* [gSDE](https://arxiv.org/abs/2005.05719)
- We use [code from Federico Bolanos](https://github.com/fbolanos/LS7366R/blob/master/LS7366R.py) to read the encoders counters.

## Authors
[Armand du Parc Locmaria](https://armandpl.com)
[Armand du Parc Locmaria](https://armandpl.com)
[Pierre Fabre](https://www.linkedin.com/in/p-fabre/)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ message PendulumState {
bool done = 6;
float action = 7;
float corrected_action = 8;
}
}
25 changes: 25 additions & 0 deletions furuta/logging/protobuf/pendulum_state_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np
from gym.spaces import Box

from furuta_gym.utils import ALPHA, ALPHA_DOT, THETA, THETA_DOT, Timing
from furuta.utils import ALPHA, ALPHA_DOT, THETA, THETA_DOT, Timing


def alpha_reward(state):
Expand Down
33 changes: 18 additions & 15 deletions furuta_gym/envs/furuta_real.py → furuta/rl/envs/furuta_real.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@

import numpy as np

from furuta_gym.common import VelocityFilter
from furuta_gym.envs.furuta_base import FurutaBase
from furuta_gym.envs.hardware.robot import FurutaRobot
from furuta.common import VelocityFilter
from furuta.envs.furuta_base import FurutaBase
from furuta.envs.hardware.robot import FurutaRobot


class FurutaReal(FurutaBase):

def __init__(self, fs=100, fs_ctrl=100,
action_limiter=False, safety_th_lim=1.5,
reward="simple", state_limits='low',
config_file="robot.ini"):
super().__init__(fs, fs_ctrl, action_limiter, safety_th_lim,
reward, state_limits)

self.robot = FurutaRobot()
def __init__(
self,
fs=100,
fs_ctrl=100,
action_limiter=False,
safety_th_lim=1.5,
reward="simple",
state_limits="low",
config_file="robot.ini",
):
super().__init__(fs, fs_ctrl, action_limiter, safety_th_lim, reward, state_limits)

self.robot = FurutaRobot()

self.vel_filt = VelocityFilter(2, dt=self.timing.dt)

Expand Down Expand Up @@ -61,15 +65,14 @@ def get_state(self):
def _reset_pendulum(self, tolerance=10, still_time=1, clear=True):
pass


def reset(self):
logging.info("Reset env...")
# reset pendulum
self._reset_pendulum(40, 0.5, False)
# reset motor
logging.debug("Reset motor")
while True:
state = self._read_state()*180/np.pi
state = self._read_state() * 180 / np.pi
motor_angle = state[0]
motor_speed = state[2]

Expand All @@ -83,7 +86,7 @@ def reset(self):
elif motor_angle > 0:
self.motor.set_speed(0.3)

sleep(10/100)
sleep(10 / 100)

self.motor.set_speed(0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
from numpy.linalg import inv

from furuta_gym.utils import ALPHA, ALPHA_DOT, THETA, THETA_DOT, VelocityFilter
from furuta.utils import ALPHA, ALPHA_DOT, THETA, THETA_DOT, VelocityFilter

from .furuta_base import FurutaBase

Expand Down
4 changes: 2 additions & 2 deletions furuta_gym/wrappers.py → furuta/rl/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

import gym
import numpy as np
import wandb
from gym.spaces import Box
from mcap_protobuf.writer import Writer

import wandb
from furuta_gym.logging.protobuf.pendulum_state_pb2 import PendulumState
from furuta.logging.protobuf.pendulum_state_pb2 import PendulumState


class GentlyTerminating(gym.Wrapper):
Expand Down
4 changes: 1 addition & 3 deletions furuta_gym/robot.py → furuta/robot.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import struct

import matplotlib.pyplot as plt
import numpy as np
import serial
import simple_pid


class Robot:
def __init__(self, device="dev/ttyACM0", baudrate=921600):
self.ser = serial.Serial(device, baudrate)

def step(self, motor_command: float):
"""motor command is a float between -1 and 1."""
"""Motor command is a float between -1 and 1."""
direction = motor_command < 0
# convert motor command to 16 bit unsigned int
int_motor_command = int(np.abs(motor_command) * (2**16 - 1))
Expand Down
File renamed without changes.
116 changes: 0 additions & 116 deletions furuta_gym/envs/hardware/LS7366R.py

This file was deleted.

60 changes: 0 additions & 60 deletions furuta_gym/envs/hardware/motor.py

This file was deleted.

Empty file.
25 changes: 0 additions & 25 deletions furuta_gym/logging/protobuf/pendulum_state_pb2.py

This file was deleted.

Loading

0 comments on commit da39fdb

Please sign in to comment.