Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

have addSignalFunction support tuples or lists #11

Open
mauricefallon opened this issue Aug 26, 2015 · 4 comments
Open

have addSignalFunction support tuples or lists #11

mauricefallon opened this issue Aug 26, 2015 · 4 comments

Comments

@mauricefallon
Copy link
Contributor

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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

@patmarion
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants