Skip to content

Commit

Permalink
hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
armi3 committed Nov 22, 2019
1 parent 8e07d35 commit 857bc80
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 15 deletions.
18 changes: 16 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,25 @@ services:
context: ./gui/
ports:
- 8080:8080

# depends_on:
# - redis
lex:
image: love-my-robot/lex
build:
context: ./lex/
ports:
- 5000:5000

# depends_on:
# - redis

# from your apps you can reach Redis IP with its fqdn "redis"
# redis:
# image: redis:alpine
# restart: always
# volumes:
# - redis_data:/data
# ports:
# - 6379:6379

#volumes:
# redis_data: {}
36 changes: 23 additions & 13 deletions lex/lex.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# from redis import Redis


importlib.invalidate_caches()
app = Flask(__name__)
app.static_folder = 'static'
app.template_folder = 'templates'
Expand All @@ -21,6 +21,7 @@ def __init__(self):
self.ts_file = 'lmr_lex_2019_11_3-11_18'
self.ts_display = ''
self.procedure = []
self.procedure_display = ''


# redis = Redis(host='redis', port=6379)
Expand Down Expand Up @@ -56,12 +57,14 @@ def preprocess(request_body):

def preprocess_ts(request_body):
request_timestamp = request_body['request_timestamp']
year= request_timestamp[-4:]
request_timestamp=request_timestamp[:-4]
year = request_timestamp[-4:]
request_timestamp = request_timestamp[:-4]
state.ts_display = request_timestamp
print('preprocess_ts\n' + state.ts_display)
request_timestamp = "lmr_lex" + request_timestamp + ".py"
request_timestamp=request_timestamp.replace("Sun"," "+year).replace("Mon"," "+year).replace("Tue"," "+year).replace("Wed"," "+year).replace("Thu"," "+year).replace("Fri"," "+year).replace("Sat"," "+year)
request_timestamp = request_timestamp.replace("Sun", " " + year).replace("Mon", " " + year).replace("Tue",
" " + year).replace(
"Wed", " " + year).replace("Thu", " " + year).replace("Fri", " " + year).replace("Sat", " " + year)
request_timestamp = request_timestamp.replace("CST", "").replace(":", "-").replace(" ", '_')
request_timestamp = request_timestamp.replace('Jan', '1').replace("Feb", "2").replace("Mar", "3").replace("Apr",
"4").replace(
Expand All @@ -71,6 +74,7 @@ def preprocess_ts(request_body):
state.ts_file = request_timestamp
print(state.ts_file)


def preprocess_procedure(request_body):
array = []
for command in request_body['lmr']:
Expand Down Expand Up @@ -224,6 +228,7 @@ def transpile(procedure_array):


def export(text):
state.procedure_display = text
filepath = os.path.join('transpiled', state.ts_file)
if not os.path.exists('transpiled'):
os.makedirs('transpiled')
Expand All @@ -233,25 +238,32 @@ def export(text):


def execute():
transpiled_module = importlib.import_module('.' + state.ts_file, package='transpiled')
cozmo.run_program(transpiled_module.program())
try:
importlib.invalidate_caches()
transpiled_module = importlib.import_module('.' + state.ts_file, package='transpiled')
importlib.invalidate_caches()
# transpiled_module = importlib.import_module(os.path.abspath('transpiled/' + state.ts_file + '.py'))
cozmo.run_program(transpiled_module.program())
except ValueError:
print("Oops! That was no valid number. Try again...")


# print(transpile([['DRIVE_OFF'], ['WHEELIE'], ['ANIMATION', 'DizzyShakeStop']]))
print(transpile([['DRIVE_OFF'], ['WHEELIE'], ['ANIMATION', 'DizzyShakeStop']]))
# preprocess(json_dummy)
# process()
# execute()

# with open ("state.ts_file", "r") as myfile:
# data=myfile.readlines()

timestamp=str(state.ts_display)

# timestamp=str(state.ts_display)


@app.route("/")
def root():
# redis.incr('hits')
# return 'This Compose/Flask demo has been viewed %s time(s).' % redis.get('hits')
return render_template('index.html',data=data,time=timestamp)
return render_template('index.html', data=state.procedure_display, time=state.ts_display)


@app.route("/lex", methods=['POST'])
Expand All @@ -272,5 +284,3 @@ def lex():
if __name__ == "__main__":
# subscriber.subscribe('request-timestamp')
app.run(host="0.0.0.0", debug=True)


34 changes: 34 additions & 0 deletions lex/transpiled/lmr_lex_2019_11__3_01-42-41__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import time
from cozmo.objects import LightCube1Id, LightCube2Id, LightCube3Id
from cozmo.util import distance_mm, speed_mmps
import cozmo


def program(robot: cozmo.robot.Robot):
robot.say_text('HI').wait_for_completed()
robot.drive_straight(distance_mm(50), speed_mmps(100)).wait_for_completed()
robot.say_text('POO').wait_for_completed()
cube1 = robot.world.get_light_cube(LightCube1Id) # looks like a paperclip
cube2 = robot.world.get_light_cube(LightCube2Id) # looks like a lamp / heart
cube3 = robot.world.get_light_cube(LightCube3Id) # looks like the letters 'ab' over 'T'

if cube1 is not None:
cube1.set_lights(cozmo.lights.red_light)
else:
cozmo.logger.warning('Cozmo is not connected to a LightCube1Id cube - check the battery.')

if cube2 is not None:
cube2.set_lights(cozmo.lights.green_light)
else:
cozmo.logger.warning('Cozmo is not connected to a LightCube2Id cube - check the battery.')

if cube3 is not None:
cube3.set_lights(cozmo.lights.blue_light)
else:
cozmo.logger.warning('Cozmo is not connected to a LightCube3Id cube - check the battery.')

# Keep the lights on for 10 seconds until the program exits
time.sleep(10)


cozmo.run_program(program)

0 comments on commit 857bc80

Please sign in to comment.