forked from limxdynamics/tron2_rl_deploy_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
47 lines (38 loc) · 1.91 KB
/
Copy pathmain.py
File metadata and controls
47 lines (38 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
import sys
import limxsdk.robot.Robot as Robot
import limxsdk.robot.RobotType as RobotType
import controllers as controllers
if __name__ == '__main__':
# Get the robot type from the environment variable
robot_type = os.getenv("ROBOT_TYPE")
# Check if the ROBOT_TYPE environment variable is set, otherwise exit with an error
if not robot_type:
print("\033[31mError: Please set the ROBOT_TYPE using 'export ROBOT_TYPE=<robot_type>'.\033[0m")
sys.exit(1)
# Create a Robot instance of the specified type
robot = Robot(RobotType.Tron2)
# Default IP address for the robot
robot_ip = "127.0.0.1"
# Check if command-line argument is provided for robot IP
if len(sys.argv) > 1:
robot_ip = sys.argv[1]
# Initialize the robot with the provided IP address
if not robot.init(robot_ip):
sys.exit()
# Physical gamepad via pygame; off by default so the robot-joystick GUI
# (SDK SensorJoy topic) is used. Beware: pygame can grab non-gamepad HID
# devices (e.g. keyboard dongles), which silently blocks the SDK topic.
use_pygame_joystick = os.getenv("USE_PYGAME_JOYSTICK", "0") == "1"
# Determine if the simulation is running
start_controller = False
# Create and run the controller
if robot_type == "SF_TRON2A":
controller = controllers.SolefootController(f'{os.path.dirname(os.path.abspath(__file__))}/controllers/model', robot, robot_type, start_controller, use_pygame_joystick=use_pygame_joystick)
controller.run()
elif robot_type == "WF_TRON2A":
controller = controllers.WheelfootController(f'{os.path.dirname(os.path.abspath(__file__))}/controllers/model', robot, robot_type, start_controller, use_pygame_joystick=use_pygame_joystick)
controller.run()
else:
print(f"\033[31mError: unsupported ROBOT_TYPE='{robot_type}', expected SF_TRON2A or WF_TRON2A\033[0m")
sys.exit(1)