Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9ba030869f | |||
| cedb1332fd |
+54
-18
@@ -14,18 +14,30 @@ class NaoTeleop:
|
|||||||
self.session = session
|
self.session = session
|
||||||
self.motion = session.service("ALMotion")
|
self.motion = session.service("ALMotion")
|
||||||
self.posture = session.service("ALRobotPosture")
|
self.posture = session.service("ALRobotPosture")
|
||||||
|
|
||||||
|
# New: Hook into the battery service
|
||||||
|
try:
|
||||||
|
self.battery = session.service("ALBattery")
|
||||||
|
except:
|
||||||
|
self.battery = None
|
||||||
|
print("⚠️ ALBattery service not found")
|
||||||
|
|
||||||
self.video = None
|
self.video = None
|
||||||
self.video_client = None
|
self.video_client = None
|
||||||
self.running = True
|
self.running = True
|
||||||
|
|
||||||
self.head_yaw = 0.0
|
self.head_yaw = 0.0
|
||||||
self.head_pitch = 0.0
|
self.head_pitch = 0.0
|
||||||
|
|
||||||
|
# Battery tracking
|
||||||
|
self.battery_level = 100
|
||||||
|
self.last_batt_check = 0
|
||||||
|
|
||||||
self._init_video_maxfps()
|
self._init_video_maxfps()
|
||||||
|
|
||||||
pygame.init()
|
pygame.init()
|
||||||
self.screen = pygame.display.set_mode((320, 240))
|
self.screen = pygame.display.set_mode((320, 240))
|
||||||
pygame.display.set_caption("NAO Teleop - Wave on 1")
|
pygame.display.set_caption("NAO Teleop | Battery: Checking...")
|
||||||
self.clock = pygame.time.Clock()
|
self.clock = pygame.time.Clock()
|
||||||
|
|
||||||
def _init_video_maxfps(self):
|
def _init_video_maxfps(self):
|
||||||
@@ -34,7 +46,7 @@ class NaoTeleop:
|
|||||||
self.video_client = self.video.subscribeCamera("TeleopCam", 0, 0, 11, 25)
|
self.video_client = self.video.subscribeCamera("TeleopCam", 0, 0, 11, 25)
|
||||||
print("✅ Camera ready")
|
print("✅ Camera ready")
|
||||||
except:
|
except:
|
||||||
print("Camera not available")
|
print("❌ Camera not available")
|
||||||
|
|
||||||
def get_image(self):
|
def get_image(self):
|
||||||
if not self.video or not self.video_client:
|
if not self.video or not self.video_client:
|
||||||
@@ -53,29 +65,33 @@ class NaoTeleop:
|
|||||||
def wave_gesture(self):
|
def wave_gesture(self):
|
||||||
print("🤚 Waving hello...")
|
print("🤚 Waving hello...")
|
||||||
try:
|
try:
|
||||||
|
# Stiffen arm for accurate wave
|
||||||
self.motion.setStiffnesses("RArm", 1.0)
|
self.motion.setStiffnesses("RArm", 1.0)
|
||||||
|
|
||||||
# Friendly high wave
|
# Use all 6 joints to prevent xAssertArraySize crash
|
||||||
names = ["RShoulderPitch", "RShoulderRoll", "RElbowYaw", "RElbowRoll", "RWristYaw"]
|
names = ["RShoulderPitch", "RShoulderRoll", "RElbowYaw", "RElbowRoll", "RWristYaw", "RHand"]
|
||||||
|
|
||||||
# Better motion: arm raised higher + side-to-side wave
|
|
||||||
angles = [
|
angles = [
|
||||||
[-1.0, -0.8, -1.0, -0.8, -1.0], # RShoulderPitch (raise arm high)
|
[-1.5, -1.5, -1.5, -1.5, -1.5], # RShoulderPitch (high up)
|
||||||
[ 0.2, -0.5, 0.2, -0.5, 0.2], # RShoulderRoll
|
[-0.4, -0.7, -0.4, -0.7, -0.4], # RShoulderRoll
|
||||||
[ 0.8, 1.2, 0.8, 1.2, 0.8], # RElbowYaw
|
[ 0.6, 1.1, 0.6, 1.1, 0.6], # RElbowYaw
|
||||||
[-1.0, -0.3, -1.0, -0.3, -1.0], # RElbowRoll
|
[ 0.8, 0.3, 0.8, 0.3, 0.8], # RElbowRoll (proper bending)
|
||||||
[ 0.0, 1.5, 0.0, -1.5, 0.0] # RWristYaw (hand wave)
|
[ 0.0, 1.5, 0.0, -1.5, 0.0], # RWristYaw (the wave)
|
||||||
|
[ 1.0, 1.0, 1.0, 1.0, 1.0] # RHand (keep open)
|
||||||
]
|
]
|
||||||
|
|
||||||
times = [[0.5, 1.0, 1.5, 2.0, 2.5]] * 5
|
times = [[0.5, 1.0, 1.5, 2.0, 2.5]] * 6
|
||||||
|
|
||||||
self.motion.angleInterpolation(names, angles, times, True)
|
self.motion.angleInterpolation(names, angles, times, True)
|
||||||
|
|
||||||
# Strong return to neutral position
|
# Safely lower arm to true neutral
|
||||||
self.motion.setAngles("RArm", [0.0] * 5, 0.6)
|
neutral_angles = [1.5, -0.15, 1.2, 0.5, 0.0, 0.0]
|
||||||
time.sleep(0.8) # Give time to settle
|
self.motion.angleInterpolationWithSpeed(names, neutral_angles, 0.3)
|
||||||
|
|
||||||
print("✅ Better wave completed")
|
# Relax the arm's stiffness to let the motors cool and walk naturally
|
||||||
|
self.motion.setStiffnesses("RArm", 0.6)
|
||||||
|
|
||||||
|
print("✅ Proper wave completed and arm relaxed")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Wave error: {e}")
|
print(f"Wave error: {e}")
|
||||||
@@ -97,10 +113,27 @@ class NaoTeleop:
|
|||||||
if changed:
|
if changed:
|
||||||
self.motion.setAngles(["HeadYaw", "HeadPitch"], [self.head_yaw, self.head_pitch], 0.3)
|
self.motion.setAngles(["HeadYaw", "HeadPitch"], [self.head_yaw, self.head_pitch], 0.3)
|
||||||
|
|
||||||
|
def check_battery(self):
|
||||||
|
# Only ping the robot for battery data once every 10 seconds to save FPS
|
||||||
|
if not self.battery:
|
||||||
|
return
|
||||||
|
|
||||||
|
now = time.time()
|
||||||
|
if now - self.last_batt_check > 10:
|
||||||
|
try:
|
||||||
|
self.battery_level = self.battery.getBatteryCharge()
|
||||||
|
pygame.display.set_caption(f"NAO Teleop | Battery: {self.battery_level}%")
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
self.last_batt_check = now
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.motion.wakeUp()
|
self.motion.wakeUp()
|
||||||
self.posture.goToPosture("StandInit", 0.5)
|
self.posture.goToPosture("StandInit", 0.5)
|
||||||
|
|
||||||
|
# Turn natural arm swinging back on so his walk looks normal!
|
||||||
|
self.motion.setMoveArmsEnabled(True, True)
|
||||||
|
|
||||||
print("🎮 Controls:")
|
print("🎮 Controls:")
|
||||||
print(" WASD / Arrows = Walk")
|
print(" WASD / Arrows = Walk")
|
||||||
print(" I J K L = Head")
|
print(" I J K L = Head")
|
||||||
@@ -108,6 +141,9 @@ class NaoTeleop:
|
|||||||
print(" ESC = Quit")
|
print(" ESC = Quit")
|
||||||
|
|
||||||
while self.running:
|
while self.running:
|
||||||
|
# Zero-impact battery checker
|
||||||
|
self.check_battery()
|
||||||
|
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
self.running = False
|
self.running = False
|
||||||
@@ -145,7 +181,7 @@ class NaoTeleop:
|
|||||||
self.clock.tick(0)
|
self.clock.tick(0)
|
||||||
|
|
||||||
# Shutdown
|
# Shutdown
|
||||||
print("Shutting down...")
|
print("🛑 Shutting down...")
|
||||||
self.motion.stopMove()
|
self.motion.stopMove()
|
||||||
self.motion.rest()
|
self.motion.rest()
|
||||||
if self.video and self.video_client:
|
if self.video and self.video_client:
|
||||||
@@ -164,9 +200,9 @@ if __name__ == "__main__":
|
|||||||
session = qi.Session()
|
session = qi.Session()
|
||||||
try:
|
try:
|
||||||
session.connect(f"tcp://{args.ip}:{args.port}")
|
session.connect(f"tcp://{args.ip}:{args.port}")
|
||||||
print(f"Connected to {args.ip}")
|
print(f"✅ Connected to {args.ip}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Connection failed: {e}")
|
print(f"❌ Connection failed: {e}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
NaoTeleop(session).run()
|
NaoTeleop(session).run()
|
||||||
|
|||||||
Reference in New Issue
Block a user