0

I am trying to read force and torque values from an FT300 Force Torque Sensor using my Raspberry Pi 4. I used the code below on my Mac taken from this GitHub project: https://github.com/castetsb/pyFT300

It works perfectly as long as I changed the port name to the port name on my Mac.

However, when doing the same on the Raspberry Pi 4 I get this error:

raise NoResponseError("No communication with the instrument (no answer)") minimalmodbus.NoResponseError: No communication with the instrument (no answer)

I've enabled the serial port on my Raspberry Pi but still have no clue why I keep getting this error. Currently, I am using the port name "/dev/ttyACM0".

Here is the manual for the sensor:

https://assets.robotiq.com/website-assets/support_documents/document/FT_Sensor_Instruction_Manual_PDF_20181218.pdf

Here is the USB to RS485 adapter I am using:

https://www.amazon.com/Industrial-Bidirectional-Resettable-Protection-300bps-3MbpsBaudrateSupport/dp/B0B8DWLT1V/ref=sr_1_8?keywords=usb+to+rs485+adapter&qid=1689020262&sr=8-8

#!/usr/bin/env python
import minimalmodbus as mm
import time
from math import *
import serial

######################
#Connection parameters
######################
print("hello")
#Communication setup
BAUDRATE=19200
BYTESIZE=8
PARITY="N"
STOPBITS=1
TIMEOUT=1

PORTNAME="/dev/ttyACM0"

SLAVEADDRESS=9

############################
#Desactivate streaming mode
############################


#To stop the data stream, communication must be interrupted by sending a series of 0xff characters to the Sensor. Sending for about
#0.5s (50 times)will ensure that the Sensor stops the stream.

ser=serial.Serial(port=PORTNAME, baudrate=BAUDRATE, bytesize=BYTESIZE, parity=PARITY, stopbits=STOPBITS, timeout=TIMEOUT)

packet = bytearray()
sendCount=0
while sendCount<50:
  packet.append(0xff)
  sendCount=sendCount+1
ser.write(packet)
ser.close()

####################
#Setup minimalmodbus
####################

#Communication setup
mm.BAUDRATE=BAUDRATE
mm.BYTESIZE=BYTESIZE
mm.PARITY=PARITY
mm.STOPBITS=STOPBITS
mm.TIMEOUT=TIMEOUT

#Create FT300 object
ft300=mm.Instrument(PORTNAME, slaveaddress=SLAVEADDRESS)

#Uncomment to see binary messages for debug
#ft300.debug=True
#ft300.mode=mm.MODE_RTU

####################
#Functions
####################

def forceConverter(forceRegisterValue):
  """Return the force corresponding to force register value.
  
  input:
    forceRegisterValue: Value of the force register
    
  output:
    force: force corresponding to force register value in N
  """
  force=0

  forceRegisterBin=bin(forceRegisterValue)[2:]
  forceRegisterBin="0"*(16-len(forceRegisterBin))+forceRegisterBin
  if forceRegisterBin[0]=="1":
    #negative force
    force=-1*(int("1111111111111111",2)-int(forceRegisterBin,2)+1)/100
  else:
    #positive force
    force=int(forceRegisterBin,2)/100
  return force

def torqueConverter(torqueRegisterValue):
  """Return the torque corresponding to torque register value.
  
  input:
    torqueRegisterValue: Value of the torque register
    
  output:
    torque: torque corresponding to force register value in N.m
  """
  torque=0

  torqueRegisterBin=bin(torqueRegisterValue)[2:]
  torqueRegisterBin="0"*(16-len(torqueRegisterBin))+torqueRegisterBin
  if torqueRegisterBin[0]=="1":
    #negative force
    torque=-1*(int("1111111111111111",2)-int(torqueRegisterBin,2)+1)/1000
  else:
    #positive force
    torque=int(torqueRegisterBin,2)/1000
  return torque


####################
#Main program
####################

if __name__ == '__main__':
#Get FT300 force and torque
  try:
    #Initialisation
  
    #Read registers where are saved force and torque values.
    registers=ft300.read_registers(180,6)

    #Save measured values at rest. Those values are use to make the zero of the sensor.
    fxZero=forceConverter(registers[0])
    fyZero=forceConverter(registers[1])
    fzZero=forceConverter(registers[2])
    txZero=torqueConverter(registers[3])
    tyZero=torqueConverter(registers[4])
    tzZero=torqueConverter(registers[5])
    
    #main loop
    while True:
      #Read registers where are saved force and torque values.
      registers=ft300.read_registers(180,6)
      
      #Calculate measured value form register values
      fx=round(forceConverter(registers[0])-fxZero,0)
      fy=round(forceConverter(registers[1])-fyZero,0)
      fz=round(forceConverter(registers[2])-fzZero,0)
      tx=round(torqueConverter(registers[3])-txZero,2)
      ty=round(torqueConverter(registers[4])-tyZero,2)
      tz=round(torqueConverter(registers[5])-tzZero,2)
      
      #Display result
      print("***Press Ctrl+C to stop the program***")
      # print("fx=",fx,"N")
      # print("fy=",fy,"N")
      # print("fz=",fz,"N")
      # print("tx=",tx,"N.m")
      # print("ty=",ty,"N.m")
      # print("tz=",tz,"N.m")
      
      print("fx=",fx,"N  fy=",fy,"N   fz=",fz,"N   tx=",tx,"N.m   ty=",ty,"N.m   tz=",tz,"N.m")

      time.sleep(0.5)
      
  except KeyboardInterrupt:
    print("Program ended")
    pass
  • 1
    This question may yield more help over at [Raspberry PI](https://raspberrypi.stackexchange.com/) stackexchange where folks can speak to both the programming and the physical set up to help troubleshoot further. – itprorh66 Jul 10 '23 at 20:56
  • According to the modbus register info described in manual, you can use any modpoll tool like [modpoll](https://github.com/gavinying/modpoll) to retrieve sensor values (e.g. FC03). – balun Jul 16 '23 at 09:50

0 Answers0