Skip to content

Commit

Permalink
Refactor: use servo_id instead of sid
Browse files Browse the repository at this point in the history
  • Loading branch information
iory committed Dec 23, 2024
1 parent fa4f137 commit 6c8a3b0
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions rcb4/ics.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ def set_servo_id(self, servo_id):
ret = self.ics.read(5)
return 0x1F & ret[4]

def get_current(self, sid=None, interpolate=True):
if sid is None:
sid = self.get_servo_id()
self.ics.write(bytes([0xA0 | (sid & 0x1F), 0x03]))
def get_current(self, servo_id=None, interpolate=True):
if servo_id is None:
servo_id = self.get_servo_id()
self.ics.write(bytes([0xA0 | (servo_id & 0x1F), 0x03]))
time.sleep(0.05)
v = self.ics.read(5)
current = v[4]
Expand All @@ -217,10 +217,10 @@ def get_current(self, sid=None, interpolate=True):
return sign * interpolate_currents(current)
return sign * current

def get_temperature(self, sid=None, interpolate=True):
if sid is None:
sid = self.get_servo_id()
self.ics.write(bytes([0xA0 | (sid & 0x1F), 0x04]))
def get_temperature(self, servo_id=None, interpolate=True):
if servo_id is None:
servo_id = self.get_servo_id()
self.ics.write(bytes([0xA0 | (servo_id & 0x1F), 0x04]))
time.sleep(0.05)
v = self.ics.read(5)
if interpolate:
Expand Down Expand Up @@ -640,10 +640,10 @@ def get_status(self, option, param=None, selected=False):
free = self.read_free()
return f"{Fore.GREEN if free else Fore.RED}{'Enabled' if free else 'Disabled'}{Style.RESET_ALL}"

def read_angle(self, sid=None):
if sid is None:
sid = self.get_servo_id()
self.ics.write(bytes([0xA0 | (sid & 0x1F), 5]))
def read_angle(self, servo_id=None):
if servo_id is None:
servo_id = self.get_servo_id()
self.ics.write(bytes([0xA0 | (servo_id & 0x1F), 5]))
time.sleep(0.1)
v = self.ics.read(6)
angle = ((v[4] & 0x7F) << 7) | (v[5] & 0x7F)
Expand Down

0 comments on commit 6c8a3b0

Please sign in to comment.