ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I figured out the problem. The linear filter that I used lfilter accepts "Array-Like" objects therefore I appended the incoming signals to empty arrays within the callback function as follows:

import rospy
from scipy import signal
from geometry_msgs.msg import WrenchStamped

def callback(data):

time = data.header.stamp.secs  +  data.header.stamp.nsecs * 1e-9

fx = data.wrench.force.x
fy = data.wrench.force.y
fz = data.wrench.force.z
tx = data.wrench.torque.x
ty = data.wrench.torque.y
tz = data.wrench.torque.z

FX = []
FY = []
FZ = []

TX = []
TY = []
TZ = []

FX.append(fx)
FY.append(fy)
FZ.append(fz)

TX.append(tx)
TY.append(ty)
TZ.append(tz)

fs = 124.956672444 #sampling frequency

fc = 55 # Cut-off frequency of the filter
w = fc / (fs / 2) # Normalize the frequency

b, a = signal.butter(5, w, 'low')


fx_low = signal.lfilter(b, a, FX) #Forward filter
fy_low = signal.lfilter(b, a, FY)
fz_low = signal.lfilter(b, a, FZ)

tx_low = signal.lfilter(b, a, TX)
ty_low = signal.lfilter(b, a, TY)
tz_low = signal.lfilter(b, a, TZ)

It may not be best practice but I hope it helps someone else!