added walk speed setting on [], refined walk posture
This commit is contained in:
+41
@@ -0,0 +1,41 @@
|
|||||||
|
---
|
||||||
|
title: "Refactoring Python project files and code"
|
||||||
|
tags: []
|
||||||
|
author: claude
|
||||||
|
count: 2
|
||||||
|
exporter: 3.1.0
|
||||||
|
date: 2026-07-16T17-38-58+0000
|
||||||
|
url: https://claude.ai/chat/313cfd88-e6b9-4256-b155-0b389d2b86c4
|
||||||
|
---
|
||||||
|
|
||||||
|
# Refactoring Python project files and code
|
||||||
|
|
||||||
|
## Table of Contents
|
||||||
|
|
||||||
|
- [1: make a requirements.txt, readme.md, and also remove the seek function…](#chat-1)
|
||||||
|
- [2: how much faster can i make it walk, can we make it adjustable during r…](#chat-2)
|
||||||
|
|
||||||
|
## chat-1
|
||||||
|
|
||||||
|
> make a requirements.txt, readme.md, and also remove the seek function completely and reduce the lines of code without hurting stability
|
||||||
|
|
||||||
|
Now the `pause()` method — simplify to a plain stop/restart toggle (no seek, no position math):
|
||||||
|
|
||||||
|
Now let's add the `_safe` helper to `NaoTeleop` and use it to collapse the repeated try/except boilerplate:
|
||||||
|
|
||||||
|
Now the shutdown block — this is where `_safe` pays off the most:
|
||||||
|
|
||||||
|
Good — that's stable. Now let's view the final file once more end-to-end to make sure everything reads cleanly before shipping it.
|
||||||
|
|
||||||
|
This looks clean and correct. Now let's write the `requirements.txt` and `README.md`.
|
||||||
|
|
||||||
|
Good, all confirmed. Now the README:
|
||||||
|
|
||||||
|
Now let's copy everything to outputs and present the files:
|
||||||
|
|
||||||
|
___
|
||||||
|
###### [top](#table-of-contents)
|
||||||
|
## chat-2
|
||||||
|
|
||||||
|
> how much faster can i make it walk, can we make it adjustable during runtime? we might need to change its posture so its less likely to fall and more balanced for carpet
|
||||||
|
|
||||||
+29
-10
@@ -325,6 +325,7 @@ class NaoTeleop:
|
|||||||
self.battery_level = 100
|
self.battery_level = 100
|
||||||
self.last_batt_check = 0
|
self.last_batt_check = 0
|
||||||
self.volume = 50
|
self.volume = 50
|
||||||
|
self.walk_speed = 0.6 # Default walking speed
|
||||||
|
|
||||||
self.typing_mode = False
|
self.typing_mode = False
|
||||||
self.chat_message = ""
|
self.chat_message = ""
|
||||||
@@ -436,7 +437,7 @@ class NaoTeleop:
|
|||||||
|
|
||||||
def update_title(self):
|
def update_title(self):
|
||||||
mode = "[TYPING] " if self.typing_mode else ""
|
mode = "[TYPING] " if self.typing_mode else ""
|
||||||
pygame.display.set_caption(f"NAO Teleop | {mode}Battery: {self.battery_level}% | Vol: {self.volume}%")
|
pygame.display.set_caption(f"NAO Teleop | {mode}Battery: {self.battery_level}% | Vol: {self.volume}% | Speed: {self.walk_speed:.2f}")
|
||||||
|
|
||||||
def change_volume(self, delta):
|
def change_volume(self, delta):
|
||||||
self.volume = int(min(100, max(0, self.volume + delta)))
|
self.volume = int(min(100, max(0, self.volume + delta)))
|
||||||
@@ -465,9 +466,7 @@ class NaoTeleop:
|
|||||||
self._safe("moveInit", self.motion.moveInit)
|
self._safe("moveInit", self.motion.moveInit)
|
||||||
print("🦶 Walk engine ready")
|
print("🦶 Walk engine ready")
|
||||||
|
|
||||||
carpet_config = [["StepHeight", 0.028], ["MaxStepFrequency", 0.6], ["TorsoWy", 0.05]]
|
print("\n🎮 Controls: WASD/Arrows=Walk | [/]=Speed | IJKL=Head | SPACE=Reset head | 1=Wave | M=Music search (↑↓ select, Enter confirm) | P=Pause | X=Stop | -/==Volume | T=TTS | ESC=Quit")
|
||||||
|
|
||||||
print("\n🎮 Controls: WASD/Arrows=Walk | IJKL=Head | SPACE=Reset head | 1=Wave | M=Music search (↑↓ select, Enter confirm) | P=Pause | X=Stop | -/==Volume | T=TTS | ESC=Quit")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while self.running:
|
while self.running:
|
||||||
@@ -565,15 +564,35 @@ class NaoTeleop:
|
|||||||
|
|
||||||
if not self.typing_mode and not self.music_search_mode:
|
if not self.typing_mode and not self.music_search_mode:
|
||||||
keys = pygame.key.get_pressed()
|
keys = pygame.key.get_pressed()
|
||||||
|
|
||||||
|
# Speed Adjustment with Title Bar Update
|
||||||
|
speed_changed = False
|
||||||
|
if keys[pygame.K_LEFTBRACKET]:
|
||||||
|
self.walk_speed = max(0.1, self.walk_speed - 0.01)
|
||||||
|
speed_changed = True
|
||||||
|
if keys[pygame.K_RIGHTBRACKET]:
|
||||||
|
self.walk_speed = min(1.0, self.walk_speed + 0.01)
|
||||||
|
speed_changed = True
|
||||||
|
if speed_changed:
|
||||||
|
self.update_title()
|
||||||
|
|
||||||
x = y = theta = 0.0
|
x = y = theta = 0.0
|
||||||
if keys[pygame.K_w] or keys[pygame.K_UP]: x = 0.6
|
if keys[pygame.K_w] or keys[pygame.K_UP]: x = self.walk_speed
|
||||||
if keys[pygame.K_s] or keys[pygame.K_DOWN]: x = -0.6
|
if keys[pygame.K_s] or keys[pygame.K_DOWN]: x = -self.walk_speed
|
||||||
if keys[pygame.K_a] or keys[pygame.K_LEFT]: theta = 0.5
|
if keys[pygame.K_a] or keys[pygame.K_LEFT]: theta = self.walk_speed * 0.8
|
||||||
if keys[pygame.K_d] or keys[pygame.K_RIGHT]: theta = -0.5
|
if keys[pygame.K_d] or keys[pygame.K_RIGHT]: theta = -self.walk_speed * 0.8
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if abs(x) > 0.1 or abs(theta) > 0.1:
|
if abs(x) > 0.05 or abs(theta) > 0.05:
|
||||||
self.motion.moveToward(x, y, theta, carpet_config)
|
# Fixed stable configuration mapping
|
||||||
|
stable_config = [
|
||||||
|
["StepHeight", 0.02],
|
||||||
|
["MaxStepFrequency", 0.5],
|
||||||
|
["TorsoWy", 0.08],
|
||||||
|
["MaxStepX", 0.03] # Replaced MaxStepLength
|
||||||
|
]
|
||||||
|
# Removed the forced stiffness block here
|
||||||
|
self.motion.moveToward(x, y, theta, stable_config)
|
||||||
else:
|
else:
|
||||||
self.motion.stopMove()
|
self.motion.stopMove()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user