Skip to content

Commit

Permalink
Add get current and temperature function for ics
Browse files Browse the repository at this point in the history
  • Loading branch information
iory committed Dec 23, 2024
1 parent 7d23c9e commit d3deda5
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions rcb4/ics.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import serial.tools.list_ports
import yaml

from rcb4.rcb4interface import interpolate_currents
from rcb4.rcb4interface import interpolate_or_extrapolate_temperatures

degree_to_pulse = 29.633


Expand Down Expand Up @@ -199,6 +202,26 @@ 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]))
time.sleep(0.05)
v = self.ics.read(5)
if interpolate:
return interpolate_currents(v[4])
return v[4]

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]))
time.sleep(0.05)
v = self.ics.read(5)
if interpolate:
return interpolate_or_extrapolate_temperatures(v[4])
return v[4]

def set_response(self, value, servo_id=None):
"""
Set the response parameter to the specified value.
Expand Down

0 comments on commit d3deda5

Please sign in to comment.