Exemple #1
0
 def __init__(self, id, initialPosition):
     self.id = id
     self.initialPosition = initialPosition
     self.currentPosition = initialPosition
     self.bot = create2api.Create2()
     self.bot.start()
     self.bot.safe()
     cameraThread = CameraThread(self.bot)
     cameraThread.start()
Exemple #2
0
def main():

	bot = create2api.Create2()

	#Start the Create2
	bot.start()

	#Put the Create2 into 'safe' mode so we can drive it
	bot.safe()

	

	soya = Roomba_runrun()

	soya.roomba_go(3,1,0)
Exemple #3
0
	def __init__(self):

		# ROSのノードを宣言
		# ROSシステムの中で唯一の名前にしなけばならない
		rospy.init_node('roomber', anonymous=True)
		# Publisherのインスタンス
		
		self.msg = Twist()
		self.sasaki_mode = 0
		self.my_state = 0
		self.bot = create2api.Create2()
		#Start the Create2
		self.bot.start()
		#Put the Create2 into 'safe' mode so we can drive it
		self.bot.full()

		# ルンバディスプレイへの文字表示
		self.bot.digit_led_ascii('O_O ')
Exemple #4
0
    def __init__(self):
        # Runner
        rospy.init_node('Runner', anonymous=True)

        # instance of publisher
        self.pub = rospy.Publisher('Roomba_State', Rstate, queue_size=100)
        # instance of subscriber
        self.sub = None

        # create2api
        self.bot = create2api.Create2()
        self.bot.start()
        self.bot.safe()

        # sensor
        self.bump = 0
        self.uss = 0

        # state machine
        self.state = myState.myState()

        # Goal checker
        self.goal = False
Exemple #5
0
def Roomba_bumper():
    rospy.init_node('Roomba_bumper_node', anonymous=True)
    # nodeの宣言 : publisherのインスタンスを作る
    # Roomba_bumperというtopicにInt8型のmessageを送るPublisherをつくった
    pub = rospy.Publisher('Roomba_bumper', State, queue_size=100)

    # 1秒間にpublishする数の設定
    r = rospy.Rate(2)

    #Create a Create2. This will automatically try to connect to your
    #   robot over serial
    bot = create2api.Create2()

    #Start the Create2
    bot.start()

    #Put the Create2 into 'safe' mode so we can drive it
    bot.safe()

    msg = State()
    msg.state = 0

    #バンパの状態を延々と得る
    while not rospy.is_shutdown():
        bot.get_packet(7)
        Right = bot.sensor_state['wheel drop and bumps']['bump right']
        Left = bot.sensor_state['wheel drop and bumps']['bump left']

        if Right or Left == True:
            msg.state = 1
            pub.publish(msg)

        else:
            msg.state = 0
            pub.publish(msg)

        r.sleep(1)
Exemple #6
0
	def __init__(self):

		# ROSのノードを宣言
		# ROSシステムの中で唯一の名前にしなけばならない
		rospy.init_node('Roomba_runrun_node', anonymous=True)

		# Publisherのインスタンス
		self.roomba_bumper_pub = rospy.Publisher('roomba_bumper', myState, queue_size=100)
		# Subscriberのインスタンス
		self.roomba_drive_sub = rospy.Subscriber('operation_state', myState, self.drive_callback)

		# bamperのステートを送るためのメッセージ
		self.bumper_msg = myState()

		if DEBUG == False:
			# roombaを動かすために初期化処理
			# 初期化のために作った"bot"はクラスの中で共有
			# Create a Create2. This will automatically try to connect to your
			# robot over serial
			self.bot = create2api.Create2()
			#Start the Create2
			self.bot.start()
			#Put the Create2 into 'safe' mode so we can drive it
			self.bot.safe()
Exemple #7
0
def right():
    bot = create2api.Create2()
    bot.turn_clockwise(11)
    sleep(0.5)
    bot.drive_straight(0)
Exemple #8
0
def stop():
    bot = create2api.Create2()
    bot.drive_straight(0)
Exemple #9
0
def dock():
    bot = create2api.Create2()
    bot.start()
    bot.seek_dock()
    bot.stop()
Exemple #10
0
def spot():
    bot = create2api.Create2()
    bot.start()
    bot.spot()
    bot.stop()
Exemple #11
0
def RetrieveCreateTelemetrySensors(dashboard):

    create_data = """
                  {"OFF" : 0,
                   "PASSIVE" : 1,
                   "SAFE" : 2,
                   "FULL" : 3,
                   "NOT CHARGING" : 0,
                   "RECONDITIONING" : 1,
                   "FULL CHARGING" : 2,
                   "TRICKLE CHARGING" : 3,
                   "WAITING" : 4,
                   "CHARGE FAULT" : 5
                   }
                   """
                   
    create_dict = json.loads(create_data)

    # a timer for issuing a button command to prevent Create2 from sleeping in Passive mode    
    BtnTimer = datetime.datetime.now() + datetime.timedelta(seconds=30)
    battcharging = False
    docked = False
    connection_attempt = 0
        
    global CLNpin, BRCpin
    CLNpin = 17                      # GPIO 17 to control CLEAN button
    BRCpin = 18                      # GPIO 18 to negative pulse BRC pin on miniDIN port
    GPIO.setmode(GPIO.BCM)           # as opposed to GPIO.BOARD # Uses 'import RPi.GPIO as GPIO'
    GPIO.setup(CLNpin, GPIO.OUT)     # GPIO pin 17 drives high to switch on BC337 transistor and CLEAN button 'ON'
    GPIO.setup(BRCpin, GPIO.OUT)     # GPIO pin 18 drives low on Create2 BRC pin
    GPIO.output(CLNpin, GPIO.LOW)    # initial state
    GPIO.output(BRCpin, GPIO.HIGH)   # initial state
    time.sleep(1)
    GPIO.output(BRCpin, GPIO.LOW)    # pulse BRC pin LOW to wake up irobot if in Off mode and listen at 115200 baud
    time.sleep(1)
    GPIO.output(BRCpin, GPIO.HIGH)   # rest state

    while True and not dashboard.exitflag: # outer loop to handle data link retry connect attempts
        
        if dashboard.dataconn.get() == True:

            print "Attempting data link connection"
            dashboard.comms_check(-1)
            dashboard.master.update()
            
            bot = create2api.Create2()
            bot.digit_led_ascii('    ') # clear DSEG before Passive mode
            print "Issuing a Start()"
            bot.start()                 # issue passive mode command
            #bot.safe()
            dist = 0                    # reset odometer
            connection_attempt += 1

            while True and not dashboard.exitflag:
                        
                try:
                    # check if serial is communicating
                    time.sleep(.3)
                    if timelimit(3, bot.get_packet, (100, ), {}) == False:  # run bot.get_packet(35) with a timeout

                        print "Data link down"
                        dashboard.comms_check(0)
                        bot.destroy()
                        if connection_attempt > 5:
                            connection_attempt = 0
                            print "Attempted 6 communication connections... sleeping for 6 mins..."
                            time.sleep(360)
                        print "Simulating a Clean button press"
                        GPIO.output(CLNpin, GPIO.HIGH) # Single press of Clean button enters Passive mode
                        time.sleep(.2)
                        GPIO.output(CLNpin, GPIO.LOW)  # Clean button activates on button 'release'
                        dashboard.dataconn.set(True)
                        break

                    else:
                        
                        # DATA LINK
                        connection_attempt = 0
                        if dashboard.dataconn.get() == True:
                            print "Data link up"
                            dashboard.dataconn.set(False)

                        if dashboard.dataretry.get() == True:   # retry an unstable (green) connection
                            print "Data link reconnect"
                            dashboard.dataretry.set(False)
                            dashboard.dataconn.set(True)
                            dashboard.comms_check(0)
                            bot.destroy()
                            break

                        if dashboard.rbcomms.cget('state') == "normal":  # flash radio button
                            dashboard.comms_check(-1)
                        else:
                            dashboard.comms_check(1)
                   
                        # SLEEP PREVENTION
                        # set BRC pin HIGH
                        GPIO.output(BRCpin, GPIO.HIGH)
                        
                        # command a 'Dock' button press (while docked) every 30 secs to prevent Create2 sleep 
                        # pulse BRC pin LOW every 30 secs to prevent Create2 sleep when undocked
                        # (BRC pin pulse to prevent sleep not working for me)
                        if datetime.datetime.now() > BtnTimer:
                            GPIO.output(BRCpin, GPIO.LOW)
                            print 'BRC pin pulse'
                            BtnTimer = datetime.datetime.now() + datetime.timedelta(seconds=30)
                            if docked:
                                print 'Dock'
                                bot.buttons(4) # 1=Clean 2=Spot 4=Dock 8=Minute 16=Hour 32=Day 64=Schedule 128=Clock
                            # switch to safe mode if undocked and detects OI mode is Passive
                            # (no longer required with Clean button press simulation)
                            elif bot.sensor_state['oi mode'] == create_dict["PASSIVE"] and \
                                 dashboard.chgmode.get() != 'Seek Dock':
                                dashboard.chgmode.set('Safe') 
                                bot.safe()
                                                 
                        if bot.sensor_state['oi mode'] == create_dict["OFF"]:
                            dashboard.mode.set("Off")
                        elif bot.sensor_state['oi mode'] == create_dict["PASSIVE"]:
                            dashboard.mode.set("Passive")
                        elif bot.sensor_state['oi mode'] == create_dict["SAFE"]:
                            dashboard.mode.set("Safe")
                        elif bot.sensor_state['oi mode'] == create_dict["FULL"]:
                            dashboard.mode.set("Full")
                        else:
                            dashboard.mode.set("")

                        if dashboard.modeflag.get() == True:
                            if dashboard.chgmode.get() == 'Off':
                                bot.digit_led_ascii('    ')  # clear DSEG before Off mode
                                bot.stop()
                            elif dashboard.chgmode.get() == 'Passive':
                                bot.digit_led_ascii('    ')  # clear DSEG before Passive mode
                                bot.start()
                            elif dashboard.chgmode.get() == 'Safe':
                                bot.safe()
                            elif dashboard.chgmode.get() == 'Full':
                                bot.full()
                            elif dashboard.chgmode.get() == 'Seek Dock':
                                bot.digit_led_ascii('DOCK')  # clear DSEG before Passive mode
                                bot.start()
                                bot.seek_dock()
                            dashboard.modeflag.set(False)

                        if bot.sensor_state['charging sources available']['home base']:
                            docked = True
                        else:
                            docked = False

                        # DRIVE
                        if dashboard.driven.get() == 'Button\ndriven':
                            if dashboard.driveforward == True:
                                bot.drive(int(dashboard.speed.get()), 32767)
                            elif dashboard.drivebackward == True:
                                bot.drive(int(dashboard.speed.get()) * -1, 32767)
                            elif dashboard.driveleft == True:
                                bot.drive(int(dashboard.speed.get()), 1)
                            elif dashboard.driveright == True:
                                bot.drive(int(dashboard.speed.get()), -1)
                            else:
                                bot.drive(0, 32767)
                        else:
                            if dashboard.leftbuttonclick.get() == True:
                                bot.drive(dashboard.commandvelocity, dashboard.commandradius)
                            else:
                                bot.drive(0, 32767)

                        # 7 SEGMENT DISPLAY
                        #bot.digit_led_ascii("abcd")
                        bot.digit_led_ascii(dashboard.mode.get()[:4].rjust(4))  # rjustify and pad to 4 chars
                                
                        dashboard.master.update() # inner loop to update dashboard telemetry

                except Exception: #, e:
                    print "Aborting telemetry loop"
                    #print sys.stderr, "Exception: %s" % str(e)
                    traceback.print_exc(file=sys.stdout)
                    break
                    
        dashboard.master.update()
        time.sleep(1)   # outer loop to handle data link retry connect attempts
        
    # a Power() command will stop serial communication and the OI will enter into Passive mode.
    # a Stop() command will stop serial communication and the OI will enter into Off mode.
    # iRobot beeps once to acknowledge it is starting from Off mode when undocked
    if bot.SCI.ser.isOpen(): bot.power()
    GPIO.cleanup()
    dashboard.master.destroy()  # exitflag = True
Exemple #12
0
import create2api
import time


bot = create2api.Create2('/dev/ttyUSB0')
bot.start()
bot.safe()

while True:
	cmd = input()
	if (cmd == 'f'):
		bot.drive_straight(20)
	elif (cmd == 'b'):
		bot.drive_straight(-20)
	elif (cmd == 'r'):
		bot.turn_clockwise(20)
	elif (cmd == 'l'):
		bot.turn_counter_clockwise(300)
		time.sleep(10)
		bot.drive_straight(0)
		bot.drive_straight(0)
	elif (cmd == 's'):
		bot.drive_straight(0)
	else:
		print("bad command")

Exemple #13
0
def close():
    bot = create2api.Create2()
    bot.stop()
Exemple #14
0
    prevTime = time.time()

    # thread data sharing
    currentProgram = constants.ProgramInfo()
    currMap = map.Map()

    # slam thread
    slamThread = threading.Thread(
        target=rpslam.slam, args=(currentProgram,))
    slamThread.daemon = True
    slamThread.start()

    # robot initialization
    while (not currentProgram.roombaPort):
        pass
    bot = create2api.Create2(currentProgram.roombaPort)
    bot.start()
    bot.safe()
    bot.full()

    # move robot thread
    moveThread = threading.Thread(
    target=move.run, args=(currentProgram, bot))
    moveThread.daemon = True
    moveThread.start()

    # obstacle thread
    obstacleThread = threading.Thread(
        target=sensors.monitor, args=(currentProgram, currMap, bot))
    obstacleThread.daemon = True
    obstacleThread.start()
Exemple #15
0
 def __init__(self):
     self.orientation = 90
     self.velocity = 0
     self.bot = create2api.Create2()
Exemple #16
0
def backward():
    bot = create2api.Create2()
    bot.drive_straight(-200)  #Normal speed of Roomba is -280
Exemple #17
0
def open():
    bot = create2api.Create2()
    bot.start()
    bot.safe()
Exemple #18
0
def forward():
    bot = create2api.Create2()
    bot.drive_straight(200)  #Normal speed of Roomba is 280
print('Socket created')

#Bind socket to local host and port
try:
    s.bind((HOST, PORT))
except socket.error as msg:
    print('Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1])
    sys.exit()

print('Socket bind complete')

#Start listening on socket, limit to one connection
s.listen(1)
print('Socket now listening')

roomba = create2api.Create2()
commandQueue = queue.Queue()
queueLock = threading.Lock()


#Function for handling connections. This will be used to create threads
def clientthread(conn, com_queue):
    #infinite loop so that function does not terminate and thread does not end.
    while True:
        #Receiving from client
        data = conn.recv(256)

        if not data:
            break

        try:
Exemple #20
0
def go_sleep():
    bot = create2api.Create2()
    bot.start()
    bot.power()
    bot.stop()
Exemple #21
0
import create2api
import time

STOP_VELOCITY = 0
STRAIGHT_RADIUS = 32767

ROTATION_VELOCITY = 100
UNIT_ROTATION_TIME = 6.60 / 360.0

bot = create2api.Create2()

bot.start()

bot.safe()


def rotate(angle):
    timeToRotate = abs(angle * UNIT_ROTATION_TIME)

    if angle >= 0:
        bot.drive(ROTATION_VELOCITY, -1)
    else:
        bot.drive(ROTATION_VELOCITY, 1)

    print timeToRotate

    time.sleep(timeToRotate)

    bot.drive(STOP_VELOCITY, STRAIGHT_RADIUS)

Exemple #22
0
def clean():
    bot = create2api.Create2()
    bot.start()
    bot.clean()
    bot.stop()