openhumanoids / signal-scope

A live plotting tool for LCM message fields.
BSD 3-Clause "New" or "Revised" License
13 stars 18 forks source link

have addSignalFunction support tuples or lists #11

Open mauricefallon opened 9 years ago

mauricefallon commented 9 years ago

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)

patmarion commented 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.

patmarion commented 9 years ago

Note, you will need to pull signal-scope master in order to get the "label" keyword argument that I used in my previous reply.

patmarion commented 9 years ago

Oh wait, the example I posted won't quite work, don't try it. I'll post a working version in a minute.

patmarion commented 9 years ago

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')