Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add servo feedback interface #30

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Python_Module/MangDang/mini_pupper/HardwareInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ def set_actuator_postions(self, joint_angles):
def set_actuator_position(self, joint_angle, axis, leg):
send_servo_command(self.pwm_params, self.servo_params, joint_angle, axis, leg)

def get_actuator_positions(self):
return get_servo_positions(self.pwm_params, self.servo_params)

def get_actuator_efforts(self):
return get_servo_efforts(self.pwm_params, self.servo_params)


def angle_to_position(angle, servo_params, axis_index, leg_index):
"""Converts a desired servo angle into the corresponding position command
Expand All @@ -38,6 +44,10 @@ def angle_to_position(angle, servo_params, axis_index, leg_index):
return servo_position


def servo_position_to_angle(servo_position, servo_params, axis_index, leg_index):
raise NotImplementedError("Not implemented yet")


def angle_to_servo_position(angle, pwm_params, servo_params, axis_index, leg_index):
servo_position_f = angle_to_position(angle, servo_params, axis_index, leg_index)
if np.isnan(servo_position_f):
Expand Down Expand Up @@ -69,3 +79,23 @@ def deactivate_servos(pi, pwm_params):
for leg_index in range(4):
for axis_index in range(3):
pi.set_pwm(pwm_params.servo_ids[axis_index, leg_index], 0, 0)


def get_servo_positions(pwm_params, servo_params):
positions = pwm_params.esp32.servos_get_position()
if positions is None:
return None
angles = np.zeros((3, 4))
for leg_index in range(4):
for axis_index in range(3):
angles[axis_index, leg_index] = servo_position_to_angle(
positions[pwm_params.servo_ids[axis_index, leg_index] - 1],
servo_params,
axis_index,
leg_index,
)
return angles


def get_servo_efforts(pwm_params, servo_params):
raise NotImplementedError("Not implemented yet")