@@ -57,6 +57,15 @@ def __init__(self, dog, name, description, file):
5757 async def act (self , params ):
5858 pass
5959
60+ async def call_robot (self , api_id , params = None ):
61+ args = {'api_id' : api_id }
62+ if params :
63+ args ['parameter' ] = params
64+ await self .dog .maybe_reconnect ()
65+ await self .dog .robot .datachannel .pub_sub .publish_request_new (
66+ RTC_TOPIC ["SPORT_MOD" ], args
67+ )
68+
6069 def tool (self ):
6170 return Tool (
6271 name = self .name ,
@@ -72,76 +81,55 @@ def __init__(self, dog):
7281 super ().__init__ (dog , "stand_up" , "Make the dog stand up" , "tools/empty.json" )
7382
7483 async def act (self , params ):
75- await self .dog .maybe_reconnect ()
76- await self .dog .robot .datachannel .pub_sub .publish_request_new (
77- RTC_TOPIC ["SPORT_MOD" ], {"api_id" : SPORT_CMD ["StandUp" ]}
78- )
84+ await self .call_robot (SPORT_CMD ["StandUp" ])
7985 return "Doggo is now standing up"
8086
8187class Damp (Trick ):
8288 def __init__ (self , dog ):
8389 super ().__init__ (dog , "lie_down" , "Make the dog lie down" , "tools/empty.json" )
8490
8591 async def act (self , params ):
86- await self .dog .maybe_reconnect ()
87- await self .dog .robot .datachannel .pub_sub .publish_request_new (
88- RTC_TOPIC ["SPORT_MOD" ], {"api_id" : SPORT_CMD ["Damp" ]}
89- )
92+ await self .call_robot (SPORT_CMD ["Damp" ])
9093 return "Doggo is now damping"
9194
9295class Hello (Trick ):
9396 def __init__ (self , dog ):
9497 super ().__init__ (dog , "hello" , "Make the dog say hello" , "tools/empty.json" )
9598
9699 async def act (self , params ):
97- await self .dog .maybe_reconnect ()
98- await self .dog .robot .datachannel .pub_sub .publish_request_new (
99- RTC_TOPIC ["SPORT_MOD" ], {"api_id" : SPORT_CMD ["Hello" ]}
100- )
100+ await self .call_robot (SPORT_CMD ["Hello" ])
101101 return "Doggo is now saying hello"
102102
103103class Move (Trick ):
104104 def __init__ (self , dog ):
105105 super ().__init__ (dog , "move" , "Make the dog move" , "tools/move.json" )
106106
107107 async def act (self , params ):
108- await self .dog .maybe_reconnect ()
109- await self .dog .robot .datachannel .pub_sub .publish_request_new (
110- RTC_TOPIC ["SPORT_MOD" ], {"api_id" : SPORT_CMD ["Move" ], "parameter" : params }
111- )
108+ await self .call_robot (SPORT_CMD ["Move" ], params )
112109 return "Doggo is now moving"
113110
114111class Stop (Trick ):
115112 def __init__ (self , dog ):
116113 super ().__init__ (dog , "stop" , "Make the dog stop" , "tools/empty.json" )
117114
118115 async def act (self , params ):
119- await self .dog .maybe_reconnect ()
120- await self .dog .robot .datachannel .pub_sub .publish_request_new (
121- RTC_TOPIC ["SPORT_MOD" ], {"api_id" : SPORT_CMD ["Stop" ]}
122- )
116+ await self .call_robot (SPORT_CMD ["Stop" ])
123117 return "Doggo is now stopping"
124118
125119class Dance (Trick ):
126120 def __init__ (self , dog ):
127121 super ().__init__ (dog , "dance" , "Make the dog dance" , "tools/empty.json" )
128122
129123 async def act (self , params ):
130- await self .dog .maybe_reconnect ()
131- await self .dog .robot .datachannel .pub_sub .publish_request_new (
132- RTC_TOPIC ["SPORT_MOD" ], {"api_id" : SPORT_CMD ["Dance1" ]}
133- )
124+ await self .call_robot (SPORT_CMD ["Dance1" ])
134125 return "Doggo is now dancing"
135126
136127class Jump (Trick ):
137128 def __init__ (self , dog ):
138129 super ().__init__ (dog , "jump" , "Make the dog jump" , "tools/empty.json" )
139130
140131 async def act (self , params ):
141- await self .dog .maybe_reconnect ()
142- await self .dog .robot .datachannel .pub_sub .publish_request_new (
143- RTC_TOPIC ["SPORT_MOD" ], {"api_id" : SPORT_CMD ["FrontJump" ]}
144- )
132+ await self .call_robot (SPORT_CMD ["FrontJump" ])
145133 return "Doggo is now jumping"
146134
147135def trick_tools (dog ):
0 commit comments