def onEvent(self, evt): ### ### TEAM CODE GOES HERE ### Handle events as you see fit, and return after # Ignore everything except keydown events if evt.type != KEYDOWN: return if evt.key == K_1: print("\nset corner 1") # x_pos has not been set if not self.corner_1: self.corner_1.append(self.arm[0].get_goal()) self.corner_1.append(self.arm[1].get_goal()) self.corner_1.append(self.arm[2].get_goal()) print("\n{},{},{}".format(self.corner_1[0], self.corner_1[1], self.corner_1[2])) return # already set, override self.corner_1[0] = self.arm[0].get_goal() self.corner_1[1] = self.arm[1].get_goal() self.corner_1[2] = self.arm[2].get_goal() print("\n{},{},{}".format(self.corner_1[0], self.corner_1[1], self.corner_1[2])) return if evt.key == K_2: print("\nset corner 2") # x_pos has not been set if not self.corner_2: self.corner_2.append(self.arm[0].get_goal()) self.corner_2.append(self.arm[1].get_goal()) self.corner_2.append(self.arm[2].get_goal()) print("\n{},{},{}".format(self.corner_2[0], self.corner_2[1], self.corner_2[2])) return # already set, override self.corner_2[0] = self.arm[0].get_goal() self.corner_2[1] = self.arm[1].get_goal() self.corner_2[2] = self.arm[2].get_goal() print("\n{},{},{}".format(self.corner_2[0], self.corner_2[1], self.corner_2[2])) return if evt.key == K_3: print("\nset corner 3") # x_pos has not been set if not self.corner_3: self.corner_3.append(self.arm[0].get_goal()) self.corner_3.append(self.arm[1].get_goal()) self.corner_3.append(self.arm[2].get_goal()) print("\n{},{},{}".format(self.corner_3[0], self.corner_3[1], self.corner_3[2])) return # already set, override self.corner_3[0] = self.arm[0].get_goal() self.corner_3[1] = self.arm[1].get_goal() self.corner_3[2] = self.arm[2].get_goal() print("\n{},{},{}".format(self.corner_3[0], self.corner_3[1], self.corner_3[2])) return if evt.key == K_4: print("\nset corner 4") # x_pos has not been set if not self.corner_4: self.corner_4.append(self.arm[0].get_goal()) self.corner_4.append(self.arm[1].get_goal()) self.corner_4.append(self.arm[2].get_goal()) print("\n{},{},{}".format(self.corner_4[0], self.corner_4[1], self.corner_4[2])) return # already set, override self.corner_4[0] = self.arm[0].get_goal() self.corner_4[1] = self.arm[1].get_goal() self.corner_4[2] = self.arm[2].get_goal() print("\n{},{},{}".format(self.corner_4[0], self.corner_4[1], self.corner_4[2])) return # move to programmed corners in plan if evt.key == K_SPACE: # self.movePlan.square = self.square self.movePlan.start() return # append points and begin drawing square if evt.key == K_5: self.append_points(4, 3, 3, 2.0) return return ArmAnimatorApp.onEvent(self, evt)
def onEvent(self, evt): ### ### TEAM CODE GOES HERE ### Handle events as you see fit, and return after return ArmAnimatorApp.onEvent(self, evt)
def onEvent(self, evt): ### ### TEAM CODE GOES HERE ### Handle events as you see fit, and return after #activate autonomous mode and move to a square corner by pressing 'w','e','r','t' if evt.type == KEYDOWN: progress('in keydown') p = "wert".find(evt.unicode) if p >= 0: if self.move.isRunning(): progress('Move running!') return self.move.pos = self.square_w[ p] #set square corner as goal position self.move.start() self.move.square = True #after each move, set the previous goal position as your new starting position self.move.currentPos = self.move.pos progress('Move plan started!') return #Press 'k' to move to grid point for calibration if evt.key == K_k: self.move.pos = self.calib_grid[ self.calib_idx] #set next grid point as goal position self.move.start() progress('Moving to calibration point') for i, motor in enumerate(self.arm): self.calib_ang[self.calib_idx, i] = motor.get_goal() * ( pi / 18000 ) #convert angles from centidegrees to radians #Manual adjustment before this step #Press 'o' to calculate error between where arm moved and where it was supposed to be if evt.key == K_o: #Calculate error progress('Calculate error') if self.calib_idx < len(self.calib_ang): real_ang = zeros(len(self.arm)) for i, motor in enumerate(self.arm): real_ang[i] = motor.get_goal() * (pi / 18000) self.calib_ang[self.calib_idx] = real_ang - self.calib_ang[ self.calib_idx] self.calib_idx += 1 self.move.calDone = True self.move.currentPos = self.move.pos progress('Error calculation complete') if self.calib_idx == len(self.calib_ang): progress('Calibration_complete!') self.move.calibrated = True save("calib_array.npy", self.calib_ang) #save calibration array return #manual movements # row of 'a' on QWERTY keyboard increments motors p = "asdf".find(evt.unicode) if p >= 0: progress('manual move') self.arm[p].set_pos(self.arm[p].get_goal() + 300) return # row of 'z' in QWERTY keyboard decrements motors p = "zxcv".find(evt.unicode) if p >= 0: progress('manual move') self.arm[p].set_pos(self.arm[p].get_goal() - 300) return return ArmAnimatorApp.onEvent(self, evt)