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

Add directionnal widget #96

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

victorlohezic
Copy link

@victorlohezic victorlohezic commented Jul 28, 2022

Add a widget to control a robot with buttons. We can add some buttons in order to move and to turn the robot like in the following screenshot :
photo_5985510563540743941_y
photo_5985510563540743942_y
photo_5985510563540743943_y

I had to add the following node to get information for the robot :

#! /usr/bin/python3.8

import rospy
from geometry_msgs.msg import Twist


def msgCallback(inputMsg: Twist):
    outputMsg.linear.x = 0
    outputMsg.linear.y = 0
    outputMsg.linear.z = 0
    outputMsg.angular.x = 0
    outputMsg.angular.y = 0
    outputMsg.angular.z = 0
    if inputMsg.linear.x:
        outputMsg.linear.x = inputMsg.linear.x
    elif inputMsg.linear.y:
        outputMsg.linear.y = inputMsg.linear.y
    elif inputMsg.linear.z:
        outputMsg.linear.z = inputMsg.linear.z
    elif inputMsg.angular.x:
        outputMsg.angular.x = inputMsg.angular.x
    elif inputMsg.angular.y:
        outputMsg.angular.y = inputMsg.angular.y
    elif 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("/twist_up", Twist, msgCallback)
    subscriber2 = rospy.Subscriber("/twist_down", Twist, msgCallback)
    subscriber3 = rospy.Subscriber("/twist_right", Twist, msgCallback)
    subscriber4 = rospy.Subscriber("/twist_left", Twist, msgCallback)
    subscriber5 = rospy.Subscriber("/twist_angular_left", Twist, msgCallback)
    subscriber6 = rospy.Subscriber("/twist_angular_right", Twist, msgCallback)
    publisher = rospy.Publisher("/cmd_vel", Twist, queue_size=10)

    rospy.spin()

This widget is useful for a holonomous robot. The robot can move only according to one direction (up, down, left, right) while the button is pressed. A button can also turn the robot. I have an example : https://www.eirlab.net/wp-content/uploads/2022/08/movie-2.mp4

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

Successfully merging this pull request may close these issues.

1 participant