walk these ways controller and example updated

This commit is contained in:
Rooholla-KhorramBakht 2024-10-01 14:45:06 -04:00
parent 44299643e8
commit b8aec5e825
4 changed files with 60 additions and 17 deletions

View File

@ -12,6 +12,6 @@ services:
environment: environment:
- DISPLAY=${DISPLAY} - DISPLAY=${DISPLAY}
- QT_X11_NO_MITSHM=1 - QT_X11_NO_MITSHM=1
# runtime: nvidia runtime: nvidia
stdin_open: true stdin_open: true
tty: true tty: true

View File

@ -425,8 +425,8 @@ class WalkTheseWaysAgent:
self.actions = torch.clip(actions[0:1, :], -clip_actions, clip_actions) self.actions = torch.clip(actions[0:1, :], -clip_actions, clip_actions)
self.publish_action(self.actions, hard_reset=hard_reset) self.publish_action(self.actions, hard_reset=hard_reset)
# time.sleep(max(self.dt - (time.time() - self.time), 0)) # time.sleep(max(self.dt - (time.time() - self.time), 0))
if self.timestep % 100 == 0: # if self.timestep % 100 == 0:
print(f"frq: {1 / (time.time() - self.time)} Hz") # print(f"frq: {1 / (time.time() - self.time)} Hz")
self.time = time.time() self.time = time.time()
obs = self.get_obs() obs = self.get_obs()

View File

@ -103,7 +103,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.8.18" "version": "3.10.12"
} }
}, },
"nbformat": 4, "nbformat": 4,

View File

@ -9,7 +9,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 1,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -22,7 +22,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -31,18 +31,18 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"remote = KeyboardRemote()\n", "remote = KeyboardRemote()\n",
"robot.standUpReset()\n", "robot.sitDownReset()\n",
"safety_hypervisor = SafetyHypervisor(robot)" "safety_hypervisor = SafetyHypervisor(robot)"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -71,9 +71,9 @@
" def update(self, robot, remote):\n", " def update(self, robot, remote):\n",
" action = self.policy(self.obs, self.policy_info)\n", " action = self.policy(self.obs, self.policy_info)\n",
" self.obs, self.ret, self.done, self.info = self.agent.step(action)\n", " self.obs, self.ret, self.done, self.info = self.agent.step(action)\n",
" vy = -robot.getRemoteState().lx\n", " vy = 0. # Update these based on your implementation of the remote controller\n",
" vx = robot.getRemoteState().ly\n", " vx = 0.\n",
" omega = -robot.getRemoteState().rx*2.2\n", " omega = 0.\n",
" self.command_profile.x_vel_cmd = vx*1.5\n", " self.command_profile.x_vel_cmd = vx*1.5\n",
" self.command_profile.y_vel_cmd = vy*1.5\n", " self.command_profile.y_vel_cmd = vy*1.5\n",
" self.command_profile.yaw_vel_cmd = omega" " self.command_profile.yaw_vel_cmd = omega"
@ -81,9 +81,38 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 5,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"p_gains: [20. 20. 20. 20. 20. 20. 20. 20. 20. 20. 20. 20.]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"frq: 0.06860146952866389 Hz\n",
"frq: 43.78233593252539 Hz\n",
"frq: 44.41613012538123 Hz\n",
"frq: 46.552687074074896 Hz\n",
"frq: 46.25288370349132 Hz\n",
"frq: 45.19091075603633 Hz\n",
"frq: 46.16786095609198 Hz\n",
"frq: 45.455376979181345 Hz\n",
"frq: 45.34774899450763 Hz\n",
"frq: 46.05987129647932 Hz\n",
"frq: 45.999758721663504 Hz\n",
"frq: 46.80150414532633 Hz\n",
"frq: 45.81385238828631 Hz\n",
"frq: 45.29241401652179 Hz\n",
"frq: 45.742902947880424 Hz\n"
]
}
],
"source": [ "source": [
"checkpoint = \"../Go2Py/assets/checkpoints/walk_these_ways/\"\n", "checkpoint = \"../Go2Py/assets/checkpoints/walk_these_ways/\"\n",
"controller = walkTheseWaysController(robot, remote, checkpoint)\n", "controller = walkTheseWaysController(robot, remote, checkpoint)\n",
@ -92,7 +121,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 6,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -106,9 +135,16 @@
"controller.command_profile.setGaitType(\"trotting\")" "controller.command_profile.setGaitType(\"trotting\")"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Pressing `u` on the keyboard will make the robot stand up. This is equivalent to the `L2+A` combo of the Go2 builtin state machine. After the the robot is on its feet, pressing `s` will hand over the control the RL policy. This action is equivalent to the `start` key of the builtin controller. When you want to stop, pressing `u` again will act similarly to the real robot and locks it in standing mode. Finally, pressing `u` again will command the robot to sit down."
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 7,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -230,6 +266,13 @@
"fsm = FSM(robot, remote, safety_hypervisor, user_controller_callback=controller.update)" "fsm = FSM(robot, remote, safety_hypervisor, user_controller_callback=controller.update)"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Pressing `L2+A` to command the robot to stand up. After the the robot is on its feet, pressing `start` will hand over the control the RL policy. When you want to stop, pressing `L2+A` again will act similarly to the factory controller and locks the robot in standing mode. Finally, pressing `L2+A` again will command the robot to sit down."
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
@ -256,7 +299,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.8.18" "version": "3.10.12"
} }
}, },
"nbformat": 4, "nbformat": 4,