Open mauricefallon opened 9 years ago
We could definitely do that. Note, you can also do something like this:
addSignalFunction('EST_ROBOT_STATE', lambda x: rpyFunction(x)[0], label='roll') addSignalFunction('EST_ROBOT_STATE', lambda x: rpyFunction(x)[1], label='pitch') addSignalFunction('EST_ROBOT_STATE', lambda x: rpyFunction(x)[2], label='yaw')
This might work fine for most purposes, but it will be slightly less efficient since it calls the quat_to_euler conversion three times.
We could definitely add new support for multi component signals, and that might introduce some nice features and generalities. You could then add support for applying common functions to the signals, conversions that are commonly used like quat-to-rpy, magnitude, component filters, etc.
Note, you will need to pull signal-scope master in order to get the "label" keyword argument that I used in my previous reply.
Oh wait, the example I posted won't quite work, don't try it. I'll post a working version in a minute.
Yeah it would have to be another function wrapper like:
def extractComponent(func, idx): def f(msg): t, v = func(msg) return t, v[idx] return f def rpyFunction(msg): quat = quat_to_euler([msg.pose.rotation.w, msg.pose.rotation.x, msg.pose.rotation.y, msg.pose.rotation.z]) rpy = (quat) return msg.utime, rpy addSignalFunction('EST_ROBOT_STATE', extractComponent(rpyFunction, 0), label='roll') addSignalFunction('EST_ROBOT_STATE', extractComponent(rpyFunction, 1), label='pitch') addSignalFunction('EST_ROBOT_STATE', extractComponent(rpyFunction, 2), label='yaw')
The snippet below fails as it requires a single float as output:
def rpyFunction(msg): quat = quat_to_euler([msg.pose.rotation.w, msg.pose.rotation.x, msg.pose.rotation.y, msg.pose.rotation.z]) rpy = (quat) return msg.utime, rpy
addSignalFunction('EST_ROBOT_STATE', rpyFunction)