Merge pull request #3 from Rooholla-KhorramBakht/cleanup

Cleanup
This commit is contained in:
Rooholla-KhorramBakht 2024-04-17 19:50:21 -04:00 committed by GitHub
commit abe4a84fab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 3032 additions and 290 deletions

31
.devcontainer/Dockerfile Normal file
View File

@ -0,0 +1,31 @@
FROM ros:humble
ENV DEBIAN_FRONTEND=noninteractive
SHELL ["/bin/bash", "-c"]
RUN apt-get update && apt-get install -y -qq --no-install-recommends \
libglvnd-dev \
libgl1-mesa-dev \
libegl1-mesa-dev \
libgles2-mesa-dev \
libxext6 \
libx11-6 \
freeglut3-dev \
git \
python3-pip \
ros-humble-rmw-cyclonedds-cpp ros-humble-rosidl-generator-dds-idl \
libyaml-cpp-dev \
ros-humble-xacro \
libboost-all-dev\
build-essential \
cmake \
&& rm -rf /var/lib/apt/lists/*
RUN pip3 install mujoco pin matplotlib
RUN cd / && git clone https://github.com/unitreerobotics/unitree_ros2 && cd /unitree_ros2/cyclonedds_ws/src && \
git clone https://github.com/ros2/rmw_cyclonedds -b humble && git clone https://github.com/eclipse-cyclonedds/cyclonedds -b releases/0.10.x &&\
cd .. && colcon build --packages-select cyclonedds && source /opt/ros/humble/setup.bash && colcon build
# Env vars for the nvidia-container-runtime.
ENV NVIDIA_VISIBLE_DEVICES all
ENV NVIDIA_DRIVER_CAPABILITIES graphics,utility,compute

View File

@ -0,0 +1,13 @@
// https://containers.dev/implementors/json_reference/
{
"name": "go2py",
"dockerComposeFile": "docker-compose.yaml",
"workspaceFolder": "/home/Go2Py",
"service": "go2py-dev",
"remoteUser": "root",
"customizations": {
"vscode": {
"extensions": ["dbaeumer.vscode-eslint"]
}
}
}

View File

@ -0,0 +1,17 @@
version: "3.9"
services:
go2py-dev:
build: .
container_name: go2py-dev
network_mode: host
privileged: true
command: bash
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix
- ..:/home/Go2Py
environment:
- DISPLAY=${DISPLAY}
- QT_X11_NO_MITSHM=1
runtime: nvidia
stdin_open: true
tty: true

View File

@ -1,50 +1,68 @@
# Go2Py
Python interface, example controllers, and calibration tools for the Unitree Go2 robot.
## System Setup
Go2Py is a Pythonic interface and driver for low-level and high-level control of Unitree Go2 quadruped robots. The motivation of this project is to remove the burden of developing interface, safety systems, and basic components required for starting locomotion reserach using the Go2 quadruped robot. It provides a modular pipeline for real-time communication with the robot in both simulated and real world environment with a unified interface.
The GO2 EDU comes with an onbard Jetson Orin NX, a Hessai LX-16 LiDAR sensor, and an intel Realsense D435i camera. This setup procedure targets the onboard Jetson Orin with IP `192.168.123.18` and presents the installation proceudures of nodes for reading the sensors and robot states and publisheing them as ROS2 topics plus some basic configurations for setting up the autostart services and sharing internet. The architecture of the GO2 system is illustrated in the following image:
TODO: add image
<p align="center">
<img src="docs/assets/openfig.png" alt="image" width="60%" height="auto"/>
</p>
### Internet Sharing
This project is comprised of the following components:
- **C++ Bridge:** A dockerized ROS2 bridge built upon the [unitree_ros2](https://github.com/unitreerobotics/unitree_ros2) that implements a remote controlled emergency stop and publishes the robot states as standard ROS2 topics usable by upstream systems such as NAV2.
- **Robot Interface:** A simple Python class that represents the robot and communicates with the C++ bridge through either DDS (ROS independent) or ROS2 interfaces.
- **Robot Management FSM:** A finite state machine for controlling the behavior of the robot up to the point of handover to the user low-level controller (sitting down, standing up) with safety monitors (motor temperatures, emergency stops).
- **Robot Model:** A simple to use [Pinocchio](https://github.com/stack-of-tasks/pinocchio) wrapper for computing the kinematics and dynamics parameters of the robot.
- **Simulation Interface:** Simulation environments based on Mujoco and Nvidia Orbit (To be added) with a Python interface identical to the real robot.
In order to access internet on the Jetson computer, we hook the robot to a host development computer with internet access and configure it to share its connection with the robot. To cofigure the host computer, the follwoing steps should be taken:
#### Host Computer
The following steps configures the host computer to share its intentrent with the robot.
##### Enable IP forwarding:
## How Does Using it Look Like?
Communication with the robot will be as simple as importing a Python class:
```python
from Go2Py.robot.interface.dds import GO2Real
from Go2Py.robot.model import Go2Model
robot = GO2Real(mode='lowlevel')
model = Go2Model()
robot.standDownReset()
while running:
joint_state = robot.getJointStates()
imu = robot.getIMU()
remote = robot.getRemoteState()
model.update(state['q'], state['dq'],T,vel) # T and vel from the EKF
info = model.getInfo()
#User control computations ...
```bash
sudo sysctl -w net.ipv4.ip_forward=1
robot.setCommands(q_des, dq_des, kp, kd, tau_ff)
```
##### Configure the iptables:
An identical workflow is can be followed for simulation:
```python
from Go2Py.sim.mujoco import Go2Sim
from Go2Py.robot.model import Go2Model
robot = Go2Sim()
model = Go2Model()
robot.standDownReset()
while running:
joint_state = robot.getJointStates()
imu = robot.getIMU()
remote = robot.getRemoteState()
model.update(state['q'], state['dq'],T,vel) # T and vel from the EKF
info = model.getInfo()
```bash
sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
sudo iptables -A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT
#User control computations ...
robot.setCommands(q_des, dq_des, kp, kd, tau_ff)
robot.step()
```
Note that `wlan0` should be replaced with the actual name of the network interface over which the internet is provided to the host computer, and eth0 should be replaced with the name of the Ethernet interface connected to the robot and having a local IP address in robot's network range.
## Installation
Follow through the steps in here to [setup](docs/setup.md) the robot and Go2Py.
##### Storing the Settings
Make the iptables rules persistent by installing the `iptables-persistent`:
```bash
sudo apt-get install iptables-persistent
sudo iptables-save > /etc/iptables/rules.v4
sudo ip6tables-save > /etc/iptables/rules.v6
```
#### Robot
Now tell the computer on the robot to use the internet shared by the host computer. SSH into the robot's computer with IP address `192.168.123.18`, username `unitree` and password `123`. Note that the host computer's IP reange should have already been set to static mode with an IP in `192.168.123.*` range.
```bash
sudo ip route add default via <host computer IP address>
```
Finally, configure the DNS server by adding the following to the `/etc/resolv.conf` file:
```bash
nameserver 8.8.8.8
```
**Note:** Similarly to the host computer, you can make save this configuration using the `iptables-persistent` tool.
If everything has been successful, you should be able to access the internet on the robot. Run `ping www.google.com` to verify this.
## Further Examples
A set of sorted examples are provided in the [examples](examples) directory to get you up and running quickly:
- High-level body velocity interface (ROS2)
- High-level body velocity interface (DDS)
- Low-level joint interface (ROS2)
- Low-level joint interface (DDS)
- Low-level simulation interface
- Contact Force Estimation
- Foot Contact Estimation
- Extended Kalman Filter Legged Inertial State Estimator
- Walk These Ways RL Controller

File diff suppressed because one or more lines are too long

BIN
docs/assets/openfig.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

47
docs/setup.md Normal file
View File

@ -0,0 +1,47 @@
# System Setup
The GO2 EDU comes with an onbard Jetson Orin NX, a Hessai LX-16 LiDAR sensor, and an intel Realsense D435i camera. This setup procedure targets the onboard Jetson Orin with IP `192.168.123.18` and presents the installation proceudures of nodes for reading the sensors and robot states and publisheing them as ROS2 topics plus some basic configurations for setting up the autostart services and sharing internet. The architecture of the GO2 system is illustrated in the following image:
TODO: add image
### Internet Sharing
In order to access internet on the Jetson computer, we hook the robot to a host development computer with internet access and configure it to share its connection with the robot. To cofigure the host computer, the follwoing steps should be taken:
#### Host Computer
The following steps configures the host computer to share its intentrent with the robot.
##### Enable IP forwarding:
```bash
sudo sysctl -w net.ipv4.ip_forward=1
```
##### Configure the iptables:
```bash
sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
sudo iptables -A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT
```
Note that `wlan0` should be replaced with the actual name of the network interface over which the internet is provided to the host computer, and eth0 should be replaced with the name of the Ethernet interface connected to the robot and having a local IP address in robot's network range.
##### Storing the Settings
Make the iptables rules persistent by installing the `iptables-persistent`:
```bash
sudo apt-get install iptables-persistent
sudo iptables-save > /etc/iptables/rules.v4
sudo ip6tables-save > /etc/iptables/rules.v6
```
#### Robot
Now tell the computer on the robot to use the internet shared by the host computer. SSH into the robot's computer with IP address `192.168.123.18`, username `unitree` and password `123`. Note that the host computer's IP reange should have already been set to static mode with an IP in `192.168.123.*` range.
```bash
sudo ip route add default via <host computer IP address>
```
Finally, configure the DNS server by adding the following to the `/etc/resolv.conf` file:
```bash
nameserver 8.8.8.8
```
**Note:** Similarly to the host computer, you can make save this configuration using the `iptables-persistent` tool.
If everything has been successful, you should be able to access the internet on the robot. Run `ping www.google.com` to verify this.

Binary file not shown.

Binary file not shown.

View File

@ -47,7 +47,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"pygame 2.5.2 (SDL 2.28.2, Python 3.8.18)\n",
"pygame 2.5.2 (SDL 2.28.2, Python 3.8.10)\n",
"Hello from the pygame community. https://www.pygame.org/contribute.html\n"
]
}
@ -56,7 +56,7 @@
"from Go2Py.robot.interface.ros2 import GO2Real, ros2_init, ROS2ExecutorManager\n",
"import time\n",
"ros2_init()\n",
"robot = GO2Real(mode='lowlevel')\n",
"robot = GO2Real(mode='highlevel')\n",
"ros2_exec_manager = ROS2ExecutorManager()\n",
"ros2_exec_manager.add_node(robot)\n",
"ros2_exec_manager.start()"
@ -89,24 +89,46 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 50,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'stamp_nanosec': 1707447716.9414463,\n",
" 'position': array([0.01655228, 0.00701126, 0.30197507]),\n",
" 'orientation': array([-0.00573182, 0.0074235 , 0.08994701, 0.99590236])}"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"robot.getOdometry()"
"odometry = []\n",
"imus = []\n",
"joints = []\n",
"foot_contacts = []\n",
"stamps = []\n",
"\n",
"for i in range(60*200):\n",
" time.sleep(1/200)\n",
" odom = robot.getOdometry()\n",
" contact = robot.getFootContacts()\n",
" joint = robot.getJointStates()\n",
" imu = robot.getIMU()\n",
" imus.append(imu)\n",
" joints.append(joint)\n",
" foot_contacts.append(contact)\n",
" stamps.append(time.time())\n",
" odometry.append(odom)\n"
]
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {},
"outputs": [],
"source": [
"import pickle\n",
"with open('data/april16-seq2.pkl', 'wb') as f:\n",
" pickle.dump(\n",
" {\n",
" 'imu':imus,\n",
" 'odometry':odometry,\n",
" 'joints':joints,\n",
" 'foot_contacts':foot_contacts,\n",
" 'stamps':stamps\n",
" }, f\n",
" )"
]
}
],
@ -126,7 +148,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.18"
"version": "3.8.10"
}
},
"nbformat": 4,

File diff suppressed because one or more lines are too long

View File

@ -188,20 +188,6 @@
"text": [
"p_gains: [20. 20. 20. 20. 20. 20. 20. 20. 20. 20. 20. 20.]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"frq: 0.10237921921805228 Hz\n",
"frq: 46.14348108298404 Hz\n",
"frq: 44.397794032030994 Hz\n",
"frq: 45.603148715941465 Hz\n",
"frq: 45.86595514341641 Hz\n",
"frq: 44.16591026356524 Hz\n",
"frq: 45.82636627843454 Hz\n",
"frq: 45.51950772169346 Hz\n"
]
}
],
"source": [
@ -213,31 +199,9 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"frq: 45.741406386320016 Hz\n",
"frq: 44.6901430961184 Hz\n",
"frq: 44.451434445775085 Hz\n",
"frq: 45.19042385846963 Hz\n",
"frq: 45.1087737411542 Hz\n",
"frq: 46.690013692073066 Hz\n",
"frq: 45.09228519824546 Hz\n",
"frq: 45.70053825535531 Hz\n",
"frq: 46.01388873651992 Hz\n",
"frq: 44.94924554183813 Hz\n",
"frq: 45.49383372200228 Hz\n",
"frq: 44.522684330085134 Hz\n",
"frq: 44.42130458266699 Hz\n",
"frq: 43.71525649844704 Hz\n",
"frq: 44.37383889464886 Hz\n"
]
}
],
"outputs": [],
"source": [
"controller.command_profile.pitch_cmd=0.0\n",
"controller.command_profile.body_height_cmd=0.0\n",