-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
175 lines (161 loc) · 6.53 KB
/
main.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import mecademicpy.robot as MecademicRobot
import mecademicpy.robot_classes
from Components.LongPart import Component
import sys
from time import sleep
from lib.OutputStyle import Foreground, Style
from Components.VacuumSwitch import VacuumSwitch
#debugging
import traceback
#use python -m main
#################################
# NOTE: INITIALIZATION FOR NEEDED OJBECTS
#################################
switch = VacuumSwitch()
robot = MecademicRobot.Robot()
# def test_callback(self):
# for i in range(5):
# sleep(1)
# print(f"test check #{i}")
#
# callbacks: mecademicpy.robot.RobotCallbacks = mecademicpy.robot.RobotCallbacks()
# callbacks.on_checkpoint_reached = test_callback
# robot.RegisterCallbacks(callbacks=callbacks, run_callbacks_in_separate_thread=True)
try:
# print(robot.IsConnected())
robot.Connect(address="192.168.0.100", enable_synchronous_mode=True, disconnect_on_exception=False)
except mecademicpy.robot_classes.CommunicationError:
print(Foreground.red, Style.bold, "Error Communicating with the robot. Exiting Now.")
sys.exit()
except TimeoutError:
print(Foreground.red, Style.bold, "Error Communicating with the robot. Exiting Now.")
sys.exit()
except Exception:
print(Foreground.red, Style.bold, "Unknown Error: ", Style.reset)
traceback.print_exc()
switch.cleanup()
sys.exit()
###################################
# ARGS HANDLING
##################################
# USAGE: python main.py [LOOPS] [INDEX]
try:
loops = int(sys.argv[1]) if len(sys.argv) > 1 else 1 #default amount of loops is 1, else it is the first argument
except ValueError:
print(Foreground.orange, Style.bold, "Wrong type entered, only an integer is accepted. Using default value of 1.", Style.reset)
loops = 1
except Exception as e:
traceback.print_exc()
loops = 1
try:
index = int(sys.argv[2]) if len(sys.argv) > 2 else None #default amount of loops is 1, else it is the first argument
except ValueError:
print(Foreground.orange, Style.bold, "Wrong type entered, only an integer is accepted. Using default value of 1.", Style.reset)
index = 1
except Exception as e:
traceback.print_exc()
index = 1
##################################
# COMPONENT INITIALIZATION
##################################
if index != None:
component = Component(robot, switch, debug=False, index=index - 1)
else:
component = Component(robot, switch, debug=False)
robot.ActivateAndHome()
##################################
# MAIN ACTIONS
##################################
try:
print("Starting process..")
# print(robot.GetJoints(), end="\r")
for i in range(loops): #You know what to do >:] (try 500 at a time) doing 100 + 108+53
print(f"\rStarting Loop {i+1}")
##########################################################################################
# Start of all blocks of code that will execute [loop] times.
##########################################################################################
component.pressButton()
component.grabComp()
# #component.preheat() #one day
component.flux()
component.solder()
component.flux()
component.solder()
component.drop()
##########################################################################################
# End of block
##########################################################################################
except KeyboardInterrupt:
robot.PauseMotion() #experimental, said to completely interrupt the robot.
robot.ClearMotion()
try:
print(Style.bold, Style.underline, Foreground.red, "CTRL+C for return", Foreground.orange, " or ENTER to lift")
input(f":{Style.reset}")
robot.MoveLinRelWrf(0, 0, 100, 0, 0, 0)
except KeyboardInterrupt:
print(Style.bold, "Exited", Style.reset)
except Exception:
print(Foreground.pink, "danny was dumb. EXITING NOW", Style.reset)
print(Style.bold, "\nManually Exited With CTRL+C", Style.reset)
except AssertionError:
# stop right there buster!!
robot.PauseMotion() #works btw
robot.ClearMotion()
# beep and wait for hooman
switch.start_alarm()
try:
print(Style.bold, Foreground.orange, "Robot missing part.", Foreground.red, Style.underline, "CTRL+C to return", Foreground.orange, "or ENTER to lift", end="")
input(f":{Style.reset}")
robot.MoveLinRelWrf(0, 0, 100, 0, 0, 0)
except KeyboardInterrupt:
print(Style.bold, "Exited", Style.reset)
except mecademicpy.robot_classes.InterruptException:
robot.ResetError()
robot.ResumeMotion()
try:
robot.MoveLinRelWrf(0, 0, 10, 0, 0, 0)
except Exception:
pass
switch.stop_alarm()
print("exited, returning to normal position. ")
except mecademicpy.robot_classes.InterruptException as e:
robot.ResetError()
robot.ClearMotion()
robot.ResumeMotion()
print(Foreground.red, Style.bold, f"Robot Exception \"{e}\" happened, exiting.")
except Exception as e:
print(Foreground.red, Style.bold, f"Unknown Exception \"{e}\" happened, exiting.")
print(Style.reset, Foreground.red, "######## START TRACEBACK ########", Style.reset)
traceback.print_exc()
print(Foreground.red, "######## END TRACEBACK ########", Style.reset)
robot.PauseMotion() #works btw
robot.ClearMotion()
try:
print(Style.bold, Style.underline, Foreground.red, "CTRL+C for return", Foreground.orange, " or ENTER to lift")
input(f":{Style.reset}")
robot.MoveLinRelWrf(0, 0, 100, 0, 0, 0)
except KeyboardInterrupt:
print(Style.bold, "Exited", Style.reset)
except Exception:
print(Foreground.pink, "danny was dumb. EXITING NOW", Style.reset)
else:
print(Foreground.green, "Successfully Exited.", Style.reset)
####################################
# PROGRAM END
####################################
print(Style.bold, "Program finished.")
try:
robot.ResumeMotion()
#################################################
# ROBOT RESET
#################################################
robot.MoveJoints(90,0,0,0,0,0)
robot.SetValveState(0, 0)
robot.SetValveState(0)
except Exception:
traceback.print_exc()
print(Foreground.red, "robot interrupted during deactivation.")
# robot.DeactivateRobot()
#should ALWAYS execute on exit
robot.Disconnect()
switch.cleanup()