def __init__(self): try: from soar.serial import Serial except ImportError: print( "You are missing some serial support libraries. Probably you are on windows and you need to get pywin32. Check out http://sourceforge.net/projects/pywin32/ for details." ) raise CancelGUIAction self.portName = settings.SERIAL_PORT_NAME self.sonarsChanged = [0, 0, 0, 0, 0, 0, 0, 0] self.connectionState = STATE_NO_SYNC self.port = None self.lastxpos, self.lastypos = 0, 0 self.storedsonars = SharedVar([0, 0, 0, 0, 0, 0, 0, 0]) self.temperature = SharedVar(0) self.ldr = SharedVar([0, 0]) self.trans, self.rot = SharedVar(0), SharedVar(0) self.odpose = SharedVar((0, 0, 0)) self.stalled = SharedVar(False) self.analogInputs = SharedVar([0, 0, 0, 0]) self.analogOut = SharedVar(0) self.asynchronous = True self.setters = { "motorOutput": self.motorOutput, "discreteMotorOutput": self.discreteMotorOutput, "say": self.cmdSay, "analogOutput": self.analogOutput, "setMaxEffectiveSonarDistance": self.setMaxEffectiveSonarDistance, "enableAccelerationCap": self.enableAccelerationCap, "setMaxVelocities": self.setMaxVelocities } self.getters = { "pose": self.odpose.get, "sonarDistances": self.storedsonars.get, "stalled": self.stalled.get, "analogInputs": self.analogInputs.get } debug("Pioneer variables set up", 2) self.serialready = False try: self.open(Serial) debug("Serial Connection started", 2) except: debug("Could not open the serial port", 0) raise CancelGUIAction("Error opening serial port") self.cmdEnable(1) debug("Robot cmdEnabled", 2) app.soar.addFlowTriplet( (self.startmoving, self.update, self.stopmoving)) self.currentthread = None self.acceptMotorCmds = False self.startSerialThread()
def initGlobals(self, reset=False): self.storedsonars = SharedVar() self.oldsonars = SharedVar() self.reallyoldsonars = SharedVar() self.v = SharedVar(0.0) self.w = SharedVar(0.0) self.abspose = SharedVar( (self.world.init[0], self.world.init[1], self.world.init[2])) self.odpose = SharedVar((0.0, 0.0, 0.0)) self.analogInputs = SharedVar((0.0, 0.0, 0.0, 0.0)) if not reset: self.obstacles = [] if self.world.width > self.world.height: self.simheight = MAX_SIM_WIDTH * self.world.height / self.world.width self.simwidth = MAX_SIM_WIDTH else: self.simwidth = MAX_SIM_HEIGHT * self.world.width / self.world.height self.simheight = MAX_SIM_HEIGHT self.pxmax = float(self.world.width) self.pxmin = 0.0 self.pymax = float(self.world.height) self.pymin = 0.0 self.cxmax = float(self.simwidth - 5) self.cxmin = 5.0 self.cymax = 5.0 self.cymin = float(self.simheight - 5) self.pxtocx = (self.cxmax - self.cxmin) / (self.pxmax - self.pxmin) self.pytocy = (self.cymax - self.cymin) / (self.pymax - self.pymin) self.cxtopx = (self.pxmax - self.pxmin) / (self.cxmax - self.cxmin) self.cytopy = (self.pymax - self.pymin) / (self.cymax - self.cymin) self.pxcxconstant = self.cxmin - self.pxmin * self.pxtocx self.pycyoffset = self.cymin - self.pymin * self.pytocy self.cxpxoffset = self.pxmin - self.cxmin * self.cxtopx self.cypyoffset = self.pymin - self.cymin * self.cytopy else: self.drawRobot() self.updateSonars() self.inrobot = False self.stalled = SharedVar(False)
def __init__(self): try: from soar.serial import Serial except ImportError: print "You are missing some serial support libraries. Probably you are on windows and you need to get pywin32. Check out http://sourceforge.net/projects/pywin32/ for details." raise CancelGUIAction self.sonarValues = [0, 0, 0, 0, 0, 0] self.all_Values = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] self.port = None self.serialReady = False self.ldrvalue = [0, 0] self.p_value = [0, 0] self.acc_values = [0, 0, 0, 0, 0, 0] self.pos_values = [0, 0, 0] self.EKF = Locator_EKF([0., 0.], 0.) self.offset_counter = 0 self.thread_flag = 0 self.heading = 0. self.offset_counter_iteration = 200 self.Ultrasonic_rear_right = 0 self.Ultrasonic_right = 0 self.Ultrasonic_front = 0 self.Ultrasonic_left = 0 self.Ultrasonic_rear_left = 0 self.Ultrasonic_back = 0 self.portName = -1 self.sonarsChanged = [0, 0, 0, 0, 0, 0, 0, 0] #Change to 6 after self.from_update = 0 self.connectionState = STATE_NO_SYNC self.port = None self.lastxpos, self.lastypos = 0, 0 self.storedsonars = SharedVar([0, 0, 0, 0, 0, 0, 0, 0]) #Change to 6 after self.trans, self.rot = SharedVar(0), SharedVar(0) self.odpose = SharedVar((0, 0, 0)) self.stalled = SharedVar(False) self.analogInputs = SharedVar([0, 0, 0, 0]) self.analogOut = SharedVar(0) self.asynchronous = True self.zero_recv_cnt = 0 # Added -> Not in pioneer self.setters = { "motorOutput": self.motorOutput, "discreteMotorOutput": self.discreteMotorOutput, "say": self.cmdSay, "analogOutput": self.analogOutput, "setMaxEffectiveSonarDistance": self.setMaxEffectiveSonarDistance, "enableAccelerationCap": self.enableAccelerationCap, "setMaxVelocities": self.setMaxVelocities } self.getters = { "pose": self.odpose.get, "sonarDistances": self.storedsonars.get, "stalled": self.stalled.get, "analogInputs": self.analogInputs.get } debug("eBot variables set up", 2) self.serialReady = False self.prev_sonar = [0, 0, 0, 0, 0, 0] try: self.connect(Serial) self.open() debug("Serial Connection started", 2) print "eBot connection successful" except: sys.stderr.write("Couldn't connect to eBot.\n") sys.stderr.write( "- Check if eBot is on, paired and connected. If not, power up and try again. \n" ) #sys.stderr.write("- Check to see if COM port below is eBot. If not, remove device and try again. \n") debug("Could not open the serial port", 0) print 5 raise CancelGUIAction("Error opening serial port") app.soar.addFlowTriplet( (self.startmoving, self.update, self.stopmoving)) self.currentthread = None self.acceptMotorCmds = False self.startSerialThread() sleep(7)