Skip to content

Instantly share code, notes, and snippets.

@yoneken
Last active August 23, 2021 16:31
Show Gist options
  • Save yoneken/bdf8907c1cbecc6d7640c3e3c393ebd3 to your computer and use it in GitHub Desktop.
Save yoneken/bdf8907c1cbecc6d7640c3e3c393ebd3 to your computer and use it in GitHub Desktop.
Minimum sample code to read from a DynPick 6-axis force sensor.
# coding: utf-8
import serial
import time
def calibration(s):
s.write(str.encode('p'))
time.sleep(0.1)
reply = s.read(100).decode("shift_jis")
s_calib = reply.split(",")
return [float(s) for s in s_calib]
def main():
ser = serial.Serial("COM8", 921600, timeout=0)
calib = calibration(ser)
print(calib)
ser.write(str.encode('0'))
time.sleep(0.1)
for i in range(200):
ser.write(str.encode('R'))
time.sleep(0.1)
line = ser.read(100)
force = [(int(line[i * 4 + 1:i * 4 + 5], 16) - 8192)/calib[i] for i in range(6)]
print(force)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment