ROS based Joystick Control with Custom GUI

Joystick Control with KivyMD GUI

GUI & Joystick data transfer (ROS communication) (Special Thanks to Mr.Anouar Dhouibi )

ROS based GUI implementation using python 3.6 include the following procedure.
1) Ubuntu or Linux kernel
2) ROS installation
3) Python PIP3 installation (make sure you use python 3.6>=)
4) kivy
installation
5) kivyMD installation
6) Joystick driver installation
7) Joystick node installation & mapping to publisher
8) Verification and testing of nodes

Figure 1: GUI Output Figure 2: GUI Control

Code explanation

Public Member Functions

def __init__ (self, **kwargs)def callback (self, data)def build (self)

Public Attributes

screenpose_subscriber2rate

Detailed Description

Constructor & Destructor Documentation

◆ __init__()def robot_gui_JoyStick.RobotApp.__init__(self,** kwargs )

Member Function Documentation

build()def robot_gui_JoyStick.RobotApp.build (self) Definition at line 290 of file robot_gui_JoyStick.py.
◆ callback()
def robot_gui_JoyStick.RobotApp.callback(self,data ) Definition at line 24 of file robot_gui_JoyStick.py.
Member Data Documentation
◆ pose_subscriber2robot_gui_JoyStick.RobotApp.pose_subscriber2Definition at line 21 of file robot_gui_JoyStick.py.
ratescreen
robot_gui_JoyStick.RobotApp.screenDefinition at line 18 of file robot_gui_JoyStick.py.robot_gui_JoyStick.RobotApp.rateDefinition at line 22 of file robot_gui_JoyStick.py.

Classesclass robot_gui_JoyStick.RobotApp Namespacesrobot_gui_JoyStick
#!/usr/bin/env python3.6 import rospy from kivy.lang import Builder from kivymd.app import MDApp from sensor_msgs.msg import Joy import sys import signal class RobotApp(MDApp): def __init__(self, **kwargs): super().__init__(**kwargs) self.screenscreen=Builder.load_file('/home/nabeel/catkin_ws/src/autonomous_robot/src/kv_files/main_1.kv') #Joy_data.callback(data) #without this, getting error rospy.init_node('robot_controller', anonymous=True) self.pose_subscriber2pose_subscriber2 = rospy.Subscriber('/joy',Joy,self.callbackcallback) self.raterate = rospy.Rate(10) def callback(self, data): joy_button = data.buttons Joy_axis= data.axes #print(list(self.joy())) #for x in range(len(data.buttons)): # print(data.buttons[x]) print(*(data.buttons),) print(*(data.axes),) try: Left_x=self.screenscreen.ids.Left_X Left_x.text = "Left X: %f" % float(Joy_axis[0]) ann=int((Joy_axis[0]+1)*50) Left_Horizontal=self.screenscreen.ids.Left_horizontal Left_Horizontal.value=ann except: print("Left_x Failed") pass try: Left_y=self.screenscreen.ids.Left_Y Left_y.text = "Left Y: %f" % float(Joy_axis[1]) ann=int((Joy_axis[1]+1)*50) Left_Vertical=self.screenscreen.ids.Left_vertical Left_Vertical.value=ann except: print("Left_y Failed") pass try: Right_x=self.screenscreen.ids.Right_X Right_x.text = "Right X: %f" % float(Joy_axis[2]) ann=int((Joy_axis[2]+1)*50) Right_Horizontal=self.screenscreen.ids.Right_horizontal Right_Horizontal.value=ann except: print("Right_x Failed") pass try: Right_y=self.screenscreen.ids.Right_Y Right_y.text = "Right Y: %f" % float(Joy_axis[3]) ann=int((Joy_axis[3]+1)*50) Right_Vertical=self.screenscreen.ids.Right_vertical Right_Vertical.value=ann except: print("Right_y Failed") pass try: print(joy_button[6]) if(joy_button[6]==0): LT=self.screenscreen.ids.LT_1 LT.md_bg_color = 0.3,1,0.3,0.2 else: LT=self.screenscreen.ids.LT_1 LT.md_bg_color = 1,0.5,0.5,1 except: print(" Failed LT") pass try: print(joy_button[4]) if(joy_button[4]==0): LB=self.screenscreen.ids.LB_1 LB.md_bg_color = 0.3,1,0.3,0.2 else: LB=self.screenscreen.ids.LB_1 LB.md_bg_color = 1,0.5,0.5,1 except: print(" Failed LB") pass try: print(joy_button[5]) if(joy_button[5]==0): RB=self.screenscreen.ids.RB_1 RB.md_bg_color = 0.3,1,0.3,0.2 else: RB=self.screenscreen.ids.RB_1 RB.md_bg_color = 1,0.5,0.5,1 except: print(" Failed RB") pass try: print(joy_button[7]) if(joy_button[7]==0): RT=self.screenscreen.ids.RT_1 RT.md_bg_color = 0.3,1,0.3,0.2 else: RT=self.screenscreen.ids.RT_1 RT.md_bg_color = 1,0.5,0.5,1 except: print(" Failed RT") pass try: print(joy_button[8]) if(joy_button[8]==0): Back_1=self.screenscreen.ids.back_1 Back_1.md_bg_color = 0.7,0.8,0.3,1 else: Back_1=self.screenscreen.ids.back_1 Back_1.md_bg_color = 1,0.2,0.2,1 except: print(" Failed back ") pass try: print(joy_button[9]) if(joy_button[9]==0): Start_1=self.screenscreen.ids.start_1 Start_1.md_bg_color = 0.7,0.8,0.3,1 else: Start_1=self.screenscreen.ids.start_1 Start_1.md_bg_color = 1,0.2,0.2,1 except: print(" Failed RT") pass try: print(joy_button[3]) if(joy_button[3]==0): y_1=self.screenscreen.ids.Y_1 y_1.md_bg_color = 0.7,0.8,0.3,1 else: y_1=self.screenscreen.ids.Y_1 y_1.md_bg_color = 1,0.2,0.2,1 except: print(" Failed Y_1 ") pass try: print(joy_button[1]) if(joy_button[1]==0): a_1=self.screenscreen.ids.A_1 a_1.md_bg_color = 0.7,0.8,0.3,1 else: a_1=self.screenscreen.ids.A_1 a_1.md_bg_color = 1,0.2,0.2,1 except: print(" Failed A") pass try: print(joy_button[0]) if(joy_button[0]==0): x_1=self.screenscreen.ids.X_1 x_1.md_bg_color = 0.7,0.8,0.3,1 else: x_1=self.screenscreen.ids.X_1 x_1.md_bg_color = 1,0.2,0.2,1 except: print(" Failed X_1") pass try: print(joy_button[2]) if(joy_button[2]==0): b_1=self.screenscreen.ids.B_1 b_1.md_bg_color = 0.7,0.8,0.3,1 else: b_1=self.screenscreen.ids.B_1 b_1.md_bg_color = 1,0.2,0.2,1 except: print(" Failed B_1") pass try: print(joy_button[10]) if(joy_button[10]==0): Button_stick_left=self.screenscreen.ids.button_stick_left Button_stick_left.md_bg_color = 0.3,0.2,0.8,1 else: Button_stick_left=self.screenscreen.ids.button_stick_left Button_stick_left.md_bg_color = 1,0.2,0.2,1 except: print(" Failed button_stick_left") pass try: print(joy_button[11]) if(joy_button[11]==0): Button_stick_right=self.screenscreen.ids.button_stick_right Button_stick_right.md_bg_color = 0.3,0.2,0.8,1 else: Button_stick_right=self.screenscreen.ids.button_stick_right Button_stick_right.md_bg_color = 1,0.2,0.2,1 except: print(" Failed Button_stick_right") pass try: if(Joy_axis[4]==-1 and Joy_axis[5]==0): arrow_Right=self.screenscreen.ids.Arrow_Right arrow_Right.md_bg_color = 0.3,0.2,0.8,1 elif(Joy_axis[4]==1 and Joy_axis[5]==0): arrow_Left=self.screenscreen.ids.Arrow_Left arrow_Left.md_bg_color = 0.3,0.2,0.8,1 elif(Joy_axis[4]==0 and Joy_axis[5]==-1): arrow_Down=self.screenscreen.ids.Arrow_Down arrow_Down.md_bg_color = 0.3,0.2,0.8,1 elif(Joy_axis[4]==0 and Joy_axis[5]==1): arrow_Up=self.screenscreen.ids.Arrow_Up arrow_Up.md_bg_color = 0.3,0.2,0.8,1 else: arrow_Right=self.screenscreen.ids.Arrow_Right arrow_Right.md_bg_color = 1,0.2,0.2,1 arrow_Left=self.screenscreen.ids.Arrow_Left arrow_Left.md_bg_color = 1,0.2,0.2,1 arrow_Down=self.screenscreen.ids.Arrow_Down arrow_Down.md_bg_color = 1,0.2,0.2,1 arrow_Up=self.screenscreen.ids.Arrow_Up arrow_Up.md_bg_color = 1,0.2,0.2,1 except: print(" Failed Left Front Buttons") pass def build(self): return self.screenscreen if __name__=="__main__": RobotApp().run()