Giter Club home page Giter Club logo

Comments (6)

P4STA avatar P4STA commented on August 16, 2024 2

Oh, I guess you're right. I haven't considered controlling multiple joystick at once, so in my case the simplification works just fine. I have already implemented it this way withou issues. But yes, If I wanted to use more joysticks at once your solution is better.

from ros-mobile-android.

nicostudt avatar nicostudt commented on August 16, 2024

Yep, thats a big problem. Just to explain this:
Each Joystick widget create its own publisher. If two of them use the same topic name, one of them discards the other. It's only possible with ROS2 but there is also some kind of priority involved..

You could for example create an additional node which combines all the latest values from your 3 topics into one Twist message.

from ros-mobile-android.

nicostudt avatar nicostudt commented on August 16, 2024

Okay, this would be one of the simplest solution I came up with:

#! /usr/bin/env python

import rospy
from geometry_msgs.msg import Twist


def msgCallback(inputMsg: Twist):
    if inputMsg.linear.x:
        outputMsg.linear.x = inputMsg.linear.x

    if inputMsg.linear.y:
        outputMsg.linear.y = inputMsg.linear.y

    if inputMsg.linear.z:
        outputMsg.linear.z = inputMsg.linear.z

    if inputMsg.angular.x:
        outputMsg.angular.x = inputMsg.angular.x

    if inputMsg.angular.y:
        outputMsg.angular.y = inputMsg.angular.y

    if inputMsg.angular.z:
        outputMsg.angular.z = inputMsg.angular.z

    publisher.publish(outputMsg)


if __name__ == "__main__":
    outputMsg = Twist()

    rospy.init_node('combiner', anonymous=True)

    subscriber1 = rospy.Subscriber("/twistX", Twist, msgCallback)
    subscriber2 = rospy.Subscriber("/twistY", Twist, msgCallback)
    subscriber3 = rospy.Subscriber("/twistZ", Twist, msgCallback)
    publisher = rospy.Publisher("/twist", Twist, queue_size=10)

    rospy.spin()

Please dont judge me on that... :D

So basically this node subscribes to all of your three joystick topics, which you have to change, and republish the combination via another topic (here "/twist", but of cause you can name however you like).

from ros-mobile-android.

P4STA avatar P4STA commented on August 16, 2024

Thanks, I will use the workaround.
I didn't realize multiple publishers on the same topic will be overriding each other.

Edit: By the way :D The callback could be just like this

def msgCallback(msg):
    publisher.publish(msg)

from ros-mobile-android.

nicostudt avatar nicostudt commented on August 16, 2024

Regarding your edit:
I think you are not right, because only the values of the individual topics have to be copied to the tmp message if their not zero. Otherwise, you wouldnt get any benefits besides three times the message amount and a lot of zeros ^^

from ros-mobile-android.

nicostudt avatar nicostudt commented on August 16, 2024

I hope I was able to help you. I will close the issue, but feel free to open it again if you continue to have problems with that :)

from ros-mobile-android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.