8f93f90fb8
Prevent hard Servo movements to Idle Position
35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
"""Smoothly returns the robot to its configured idle joint pose."""
|
|
from __future__ import annotations
|
|
from typing import TYPE_CHECKING, Optional
|
|
import numpy as np
|
|
|
|
import DataTypes as dt
|
|
import kinematics as kin
|
|
import robot_init as ri
|
|
from states.State import State
|
|
|
|
if TYPE_CHECKING:
|
|
from Robot import Robot
|
|
|
|
|
|
class StopState(State):
|
|
def enter(self, robot: "Robot") -> None:
|
|
pass
|
|
|
|
def execute(self, robot: "Robot") -> Optional[str]:
|
|
vx, vy, omega = robot.vector_dirmov
|
|
if abs(vx) > 0.01 or abs(vy) > 0.01 or abs(omega) > 0.01:
|
|
return "walking"
|
|
|
|
idle_pose = ri.init_deg if robot.start_pose == "init_deg" else ri.init90_deg
|
|
target_rad = idle_pose.to_rad()
|
|
robot.set_joint_angles(target_rad)
|
|
robot.current_pos = dt.PosArray(kin.ikpyForward(robot.current_rad).data.copy())
|
|
|
|
if np.allclose(robot.current_rad.data, target_rad.data, atol=1e-6):
|
|
return "idle"
|
|
|
|
return None
|
|
|
|
def exit(self, robot: "Robot") -> None:
|
|
pass |