From f5852f5e38b4ff1e488d0b91ca9694fe5d10aded Mon Sep 17 00:00:00 2001 From: cmuslima Date: Thu, 31 Aug 2023 11:42:20 -0600 Subject: [PATCH] making changes to get learning from demo working --- App/trial.py | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/App/trial.py b/App/trial.py index be80433..32a06d3 100644 --- a/App/trial.py +++ b/App/trial.py @@ -43,7 +43,7 @@ def __init__(self): self.show_demo = None self.total_reward = 0 self.demo_idx = 1 - self.action = 'noop' + self.action = 0 self.modality = self.config.get('modality') self.framerate = self.config.get('startingFrameRate', 30) self.frameId = 0 @@ -250,17 +250,15 @@ async def handle_command(self, message): print('Pass this?') if command == 'start': self.play = True - if self.action == 'increase': - self.demo_idx+=1 - elif self.action == 'decrease': - self.demo_idx-=1 - - print('using demo', self.demo_idx) - - # if self.modality == 'pref': - # self.show_demo = True - # #await self.render_all_frames() - # #await self.render_policy() + + if self.modality == 'pref': + if self.action == 'increase': + self.demo_idx+=1 + elif self.action == 'decrease': + self.demo_idx-=1 + + print('using demo', self.demo_idx) + elif command == 'stop': self.end() elif command == 'reset': @@ -273,6 +271,9 @@ async def handle_command(self, message): self.handle_feedback(command) self.handle_pref(command) + elif command == 'left' or 'right' or 'up' or 'bad': + self.handle_action(command) + async def render_all_frames(self): @@ -290,6 +291,7 @@ def handle_action(self, action:str): Translates action to int and resets action buffer if action !=0 ''' #action = action.strip().lower() + print('inside handle action') print(action) if self.modality == 'pref': if action == 'ArrowRight': @@ -303,11 +305,7 @@ def handle_action(self, action:str): elif self.modality == 'demo': self.action = 0 - if action == 'KEYDOWN': - #print('USER: GOOD') - self.action = '0' - - elif action == 'ArrowRight': + if action == 'ArrowRight': #print('USER: GOOD') self.action = 2 elif action == 'ArrowLeft': @@ -401,8 +399,8 @@ async def take_step(self): done = self.agent.step(self.humanfeedback) elif self.modality == 'demo': - print('self.humanAction', self.humanAction) - done = self.agent.step(self.humanAction) + print('self.humanAction', self.action) + done = self.agent.step(self.action)