예제 #1
0
    def init_sim(self):
        '''Initialize the simulation interface'''

        mode_helpers.set_mode('teleop', False)
        hal_data['control']['ds_attached'] = True
        hal_in_data['control']['ds_attached'] = True

        # send it the initial seed data
        msg = {'out': hal_data, 'in': hal_in_data}

        self.write_message(json.dumps(msg, allow_nan=False), False)
        self.sim_initialized = True
예제 #2
0
 def on_step(self, tm):
     '''
         Called when a driver station packet would be delivered
     '''
     
     if tm < 5:
         mode_helpers.set_mode('auto', False)
     
     elif tm < 5 + self.autonomous_period:
         mode_helpers.set_mode('auto', True)
         
     elif tm < 5 + self.autonomous_period + 1:
         mode_helpers.set_mode('teleop', False)
     
     elif tm < 5 + self.autonomous_period + 1 + self.operator_period:
         mode_helpers.set_mode('teleop', True)
         
     else:
         return False
     
     if self._on_step is not None:
         retval = self._on_step(tm)
         if retval is not None:
             return retval
     
     return True
예제 #3
0
 def on_step(self, tm):
     '''
         Called when a driver station packet would be delivered
     '''
     
     if tm < 5:
         mode_helpers.set_mode('auto', False)
     
     elif tm < 5 + self.autonomous_period:
         mode_helpers.set_mode('auto', True)
         
     elif tm < 5 + self.autonomous_period + 1:
         mode_helpers.set_mode('teleop', False)
     
     elif tm < 5 + self.autonomous_period + 1 + self.operator_period:
         mode_helpers.set_mode('teleop', True)
         
     else:
         return False
     
     if self._on_step is not None:
         retval = self._on_step(tm)
         if retval is not None:
             return retval
     
     return True
예제 #4
0
    def on_message(self, message):
        '''Called on incoming messages from the simulation. Incoming messages
        are JSON encoded, with a 'msgtype' field. The rest of the JSON depends
        on what 'msgtype' is.
        
        Current values for msgtype:
        
        * input: Then 'data' is filled with data to be updated in HAL
        * mode: then 'mode' and 'enabled' are set
        
        '''
        msg = json.loads(message)

        msgtype = msg['msgtype']

        if msgtype == 'input':
            update_hal_data(msg['data'])
        elif msgtype == 'mode':
            mode_helpers.set_mode(msg['mode'], msg['enabled'])
예제 #5
0
    def init_sim(self):
        '''Initialize the simulation interface'''
        
        mode_helpers.set_mode('teleop', False)
        hal_data['control']['ds_attached'] = True
        hal_in_data['control']['ds_attached'] = True

        config = {}
        user_config = {}
        try: 
            with open(join(self.sim_path, 'config.json'), 'r') as fp:
                try:
                    config = json.loads(fp.read())
                except:
                    logger.error("Error reading config.json")
        except:
            pass
        
        try:
            with open(join(self.sim_path, 'user-config.json'), 'r') as fp:
                try:
                    user_config = json.loads(fp.read())
                except:
                    logger.error("Error reading user-config.json")
        except:
            pass

        
        # send it the initial seed data
        msg = {
            'out': hal_data,
            'in':  hal_in_data,
            'total_time': fake_time.get(),
            'mode_time': fake_time.get() - fake_time.mode_start_tm,
            'paused': fake_time.paused,
            'config': config,
            'user_config': user_config
        }
        
        self.write_message(json.dumps(msg, allow_nan=False, cls=SetEncoder), False)
        self.sim_initialized = True
예제 #6
0
 def on_message(self, message):
     '''Called on incoming messages from the simulation. Incoming messages
     are JSON encoded, with a 'msgtype' field. The rest of the JSON depends
     on what 'msgtype' is.
     
     Current values for msgtype:
     
     * input: Then 'data' is filled with data to be updated in HAL
     * mode: then 'mode' and 'enabled' are set
     
     '''
     msg = json.loads(message)
     
     msgtype = msg['msgtype']
     
     if msgtype == 'input':
         update_hal_data(msg['data'])
     elif msgtype == 'add_device_gyro_channel':
         self.add_device_gyro_channel(msg['angle_key'])
     elif msgtype == 'update_gyros':
         self.update_gyros(msg['da'])
     elif msgtype == 'mode':
         if self.is_mode_the_same(msg['mode'], msg['enabled']) is False:
             fake_time.mode_start_tm = fake_time.get()
             mode_helpers.set_mode(msg['mode'], msg['enabled'])
     elif msgtype == 'set_autonomous':
         if self.is_mode_the_same('auto', True) is False:
             fake_time.mode_start_tm = fake_time.get()
             mode_helpers.set_autonomous(True, msg['game_specific_message'])
     elif msgtype == 'pause_sim':
         fake_time.pause()
     elif msgtype == 'resume_sim':
         fake_time.resume()
     elif msgtype == 'step_time':
         try:
             tm = float(msg['time'])
             if tm > 0:
                 fake_time.resume(tm)
         except ValueError:
             logger.error("Invalid step time", "'%s' is not a valid number", msg['time'])
예제 #7
0
파일: controller.py 프로젝트: robotpy/pyfrc
 def set_test_mode(self, enabled=True):
     """Puts the robot in test mode (the robot mode, not related to unit testing)"""
     mode_helpers.set_mode("test", enabled)
예제 #8
0
파일: controller.py 프로젝트: robotpy/pyfrc
 def set_operator_control(self, enabled=True):
     """Puts the robot in operator control mode"""
     mode_helpers.set_mode("teleop", enabled)
예제 #9
0
파일: controller.py 프로젝트: robotpy/pyfrc
 def set_autonomous(self, enabled=True):
     """Puts the robot in autonomous mode"""
     mode_helpers.set_mode(
         "auto", enabled, game_specific_message=self.game_specific_message
     )
예제 #10
0
 def set_autonomous(self, enabled=True):
     '''Puts the robot in autonomous mode'''
     mode_helpers.set_mode('auto',
                           enabled,
                           game_specific_message=self.game_specific_message)
예제 #11
0
 def set_operator_control(self, enabled=True):
     '''Puts the robot in operator control mode'''
     mode_helpers.set_mode('teleop', enabled)
예제 #12
0
 def set_autonomous(self, enabled=True):
     '''Puts the robot in autonomous mode'''
     mode_helpers.set_mode('auto', enabled)
예제 #13
0
 def set_test_mode(self, enabled=True):
     """Puts the robot in test mode (the robot mode, not related to unit testing)"""
     mode_helpers.set_mode("test", enabled)
예제 #14
0
 def set_operator_control(self, enabled=True):
     """Puts the robot in operator control mode"""
     mode_helpers.set_mode("teleop", enabled)
예제 #15
0
 def set_autonomous(self, enabled=True):
     """Puts the robot in autonomous mode"""
     mode_helpers.set_mode("auto",
                           enabled,
                           game_specific_message=self.game_specific_message)
예제 #16
0
 def set_operator_control(self, enabled=True):
     '''Puts the robot in operator control mode'''
     mode_helpers.set_mode('teleop', enabled)
예제 #17
0
 def set_autonomous(self, enabled=True):
     '''Puts the robot in autonomous mode'''
     mode_helpers.set_mode('auto', enabled)
예제 #18
0
 def set_test_mode(self, enabled=True):
     '''Puts the robot in test mode (the robot mode, not related to unit testing)'''
     mode_helpers.set_mode('test', enabled)
예제 #19
0
 def set_test_mode(self, enabled=True):
     '''Puts the robot in test mode (the robot mode, not related to unit testing)'''
     mode_helpers.set_mode('test', enabled)
예제 #20
0
 def set_autonomous(self, enabled=True):
     """Puts the robot in autonomous mode"""
     mode_helpers.set_mode("auto", enabled)