<commit_before>#!/usr/bin/python

from hal import RobotHardware
import time

r=RobotHardware()
state='init'

def bump():
	ts=r.read_touches()
	return (ts['front_left_touch'],ts['front_right_touch'])

try:
	while True:
		print state
		time.sleep(0.01)
		if state=='init':
			#r.command_actuators({'ramp_conveyer':1,'back_conveyer':1,'hopper':0,'left_wheel':0,'right_wheel':0})
			state='wander'
			bumps=0
		elif state=='wander':
			r.command_actuators({'left_wheel':.4,'right_wheel':.4})
			b=bump()
			if b==(1,0):
				state='hit_left'
			elif b==(0,1):
				state='hit_right'
			elif b==(1,1):
				state='hit_both'
			elif bumps>10:
				spintime=time.time()+5
				state='spin'
		elif state=='hit_left':
			r.command_actuators({'left_wheel':-.3,'right_wheel':-.4})
			b=bump()
			if b==(0,0):
				bumps+=1
				state='wander'
			elif b==(0,1):
				state='hit_right'
			elif b==(1,1):
				state='hit_both'
		elif state=='hit_right':
			r.command_actuators({'left_wheel':-.4,'right_wheel':-.3})
			b=bump()
			if b==(0,0):
				bumps+=1
				state='wander'
			elif b==(1,0):
				state='hit_right'
			elif b==(1,1):
				state='hit_both'
		elif state=='hit_both':
			r.command_actuators({'left_wheel':-.3,'right_wheel':-.3})
			b=bump()
			if b==(1,0):
				state='hit_left'
			elif b==(0,1):
				state='hit_right'
			elif b==(0,0):
				bumps+=1
				state='wander'
		elif state=='spin':
			r.command_actuators({'left_wheel':.3,'right_wheel':-.3})
			b=bump()
			bumps=0
			if b==(1,0):
				state='hit_left'
			elif b==(0,1):
				state='hit_right'
			elif b==(1,1):
				state='hit_both'
			elif time.time()>spintime:
				state='wander'

except KeyboardInterrupt:
	print "Got keyboard interrupt"
r.command_actuators({'ramp_conveyer':0,'back_conveyer':0,'hopper':0,'left_wheel':0,'right_wheel':0})<commit_msg>added dispense state<commit_after>#!/usr/bin/python

from hal import RobotHardware
import time

r=RobotHardware()
state='init'

def bump():
	ts=r.read_touches()
	return (ts['front_left_touch'],ts['front_right_touch'])

def enter_dispense():
	timer=1
	state='dispense1'

try:
	while True:
		print state
		time.sleep(0.01)
		if state=='init':
			#r.command_actuators({'ramp_conveyer':1,'back_conveyer':1,'hopper':0,'left_wheel':0,'right_wheel':0})
			state='wander'
			bumps=0
			gametimer=time.time()+60
		elif state=='wander':
			r.command_actuators({'left_wheel':.5,'right_wheel':.5})
			b=bump()
			if b==(1,0):
				state='hit_left'
			elif b==(0,1):
				state='hit_right'
			elif b==(1,1):
				state='hit_both'
			elif bumps>10:
				timer=time.time()+5
				state='spin'
			elif time.timer()>gametimer:
				enter_dispense()
		elif state=='hit_left':
			r.command_actuators({'left_wheel':-.3,'right_wheel':-.4})
			b=bump()
			if b==(0,0):
				bumps+=1
				state='wander'
			elif b==(0,1):
				state='hit_right'
			elif b==(1,1):
				state='hit_both'
		elif state=='hit_right':
			r.command_actuators({'left_wheel':-.4,'right_wheel':-.3})
			b=bump()
			if b==(0,0):
				bumps+=1
				state='wander'
			elif b==(1,0):
				state='hit_right'
			elif b==(1,1):
				state='hit_both'
		elif state=='hit_both':
			r.command_actuators({'left_wheel':-.3,'right_wheel':-.3})
			b=bump()
			if b==(1,0):
				state='hit_left'
			elif b==(0,1):
				state='hit_right'
			elif b==(0,0):
				bumps+=1
				state='wander'
		elif state=='spin':
			r.command_actuators({'left_wheel':.3,'right_wheel':-.3})
			b=bump()
			bumps=0
			if b==(1,0):
				state='hit_left'
			elif b==(0,1):
				state='hit_right'
			elif b==(1,1):
				state='hit_both'
			elif time.time()>timer:
				state='wander'
		elif state=='dispense1':
			r.command_actuators({'ramp_conveyer':0,'back_conveyer':0,'hopper':0,'left_wheel':0,'right_wheel':0})
			if time.time()>timer:
				timer=1
				state='dispense2'
		elif state=='dispense2':
			r.command_actuators({'hopper':1})
			if time.time()>timer:
				timer=5
				state='dispense3'
		elif state=='dispense3':
			r.command_actuators({'left_wheel':.3,'right_wheel':.3})
			if time.time()>timer:
				state='done'
		elif state=='done':
			r.command_actuators({'hopper':0,'left_wheel':0,'right_wheel':0})

except KeyboardInterrupt:
	print "Got keyboard interrupt"
r.command_actuators({'ramp_conveyer':0,'back_conveyer':0,'hopper':0,'left_wheel':0,'right_wheel':0})
{'fraction_non_alphanumeric': 0.2063380281690141, 'fraction_numerical': 0.03380281690140845, 'mean_word_length': 4.400506970849176, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2933510', 'n_tokens_mistral': 2125, 'n_tokens_neox': 1790, 'n_words': 248}