Exemple #1
0
 def __init__(self,
              robot_cls: type,
              task_cls: type,
              robot_kwargs: Dict = None,
              task_kwargs: Dict = None):
     if task_kwargs is None:
         task_kwargs = {}
     if robot_kwargs is None:
         robot_kwargs = {}
     ut_launch.set_network_env_vars()
     os.environ['RMW_IMPLEMENTATION'] = 'rmw_fastrtps_cpp'
     # Check if rclpy has been initialised before
     context = rclpy.get_default_context()
     if not context.ok():
         rclpy.init()
     sim_time_param = rclpy.parameter.Parameter('use_sim_time', value=True)
     self.node = rclpy.node.Node(robot_cls.__name__,
                                 parameter_overrides=[sim_time_param])
     # self.node.set_parameters([sim_time])
     self.__robot: LobotArmBase = robot_cls(self.node, **robot_kwargs)
     self.__task = task_cls(self.node, self.__robot, **task_kwargs)
     self.action_space = self.__robot.get_action_space()
     self.observation_space = self.__get_observation_space()
     # Set up ROS related variables
     self.__episode_num = 0
     self.__cumulated_episode_reward = 0
     self.__cumulated_reward_noise = 0
     self.__cumulated_norm_reward = 0
     self.__cumulated_unshaped_reward = 0
     self.__cumulated_exp_reward = 0
     self.__step_num = 0
     self.__last_done_info = None
     now = datetime.now()
     table_name = f'run_{now.strftime("%d_%m_%Y__%H_%M_%S")}'
     self.__logger = Logger(table_name)
Exemple #2
0
def test_init_with_domain_id():
    rclpy.init(domain_id=123)
    assert rclpy.get_default_context().get_domain_id() == 123
    rclpy.shutdown()
    context = rclpy.context.Context()
    rclpy.init(context=context, domain_id=123)
    assert context.get_domain_id() == 123
    rclpy.shutdown(context=context)
    def __init__(self):
        super().__init__('zumi_cmd_vel_publish')
        qos = QoSProfile(depth=10)

        # Initialise subscribers
        self.cmd_vel_sub = self.create_subscription(Twist, 'cmd_vel',
                                                    self.cmd_vel_callback, qos)
        """************************************************************
        ** Initialise timers
        ************************************************************"""
        self.update_timer = self.create_timer(
            0.010,  # unit: s
            self.update_callback)

        self.get_logger().info("Zumin on ")

        # Set the socket parameters
        HOST = ''
        PORT = 10000
        buf = 1024
        ADDR = (HOST, PORT)

        # Create socket and bind to address
        self.serverSocket = socket(AF_INET, SOCK_STREAM)
        self.serverSocket.bind(ADDR)
        print('bind')

        # 연결 수신 대기 상태
        self.serverSocket.listen(100)
        print('listen')

        # 연결 수락
        self.clientSocekt, addr_info = self.serverSocket.accept()
        print('accept')
        print('--client information--')
        print(self.clientSocekt, )

        rclpy.get_default_context().on_shutdown(self.fnShutDown)
        print('close')
Exemple #4
0
def set_preempt_handler(sc):
    """Sets a ROS pre-shutdown handler to preempt a given SMACH container when
    ROS receives a shutdown request.

    This can be attached to multiple containers, but only needs to be used on
    the top-level containers.

    @type sc: L{smach.Container}
    @param sc: Container to preempt on ROS shutdown.
    """

    ### Define handler
    def handler(sc):
        sc.request_preempt()

        while sc.is_running():
            rclpy.logging.get_logger(__name__).info(
                "Received shutdown request... sent preempt... waiting for state machine to terminate."
            )
            time.sleep(1.0)

    ### Add handler
    rclpy.get_default_context().on_shutdown(lambda: handler(sc))
 def __init__(self, robot_cls: type, task_cls: type, state_noise_mu: float = None, state_noise_sigma: float = None):
     ut_launch.set_network_env_vars()
     os.environ["RMW_IMPLEMENTATION"] = 'rmw_opensplice_cpp'
     context = rclpy.get_default_context()
     if not context.ok():
         rclpy.init()
     sim_time_param= rclpy.parameter.Parameter("use_sim_time", value=True)
     self.node = rclpy.node.Node(robot_cls.__name__, parameter_overrides=[sim_time_param])
     # self.node.set_parameters([sim_time])
     self.__robot: LobotArmBase = robot_cls(self.node)
     self.__robot.state_noise_mu = state_noise_mu
     self.__robot.state_noise_sigma = state_noise_sigma
     self.__task = task_cls(self.node, self.__robot)
     self.action_space = self.__robot.get_action_space()
     self.observation_space = self.__robot.get_observation_space()
     # Set up ROS related variables
     self.__episode_num = 0
     self.__cumulated_episode_reward = 0
     self.__step_num = 0
     self.reset()
 def __init__(self, robot_cls: type, task_cls: type, robot_kwargs: Dict = None, task_kwargs: Dict = None):
     if task_kwargs is None:
         task_kwargs = {}
     if robot_kwargs is None:
         robot_kwargs = {}
     ut_launch.set_network_env_vars()
     os.environ['RMW_IMPLEMENTATION'] = 'rmw_fastrtps_cpp'
     # Check if rclpy has been initialised before
     context = rclpy.get_default_context()
     if not context.ok():
         rclpy.init()
     sim_time_param = rclpy.parameter.Parameter('use_sim_time', value=True)
     self.node = rclpy.node.Node(robot_cls.__name__, parameter_overrides=[sim_time_param])
     # self.node.set_parameters([sim_time])
     self.__robot: LobotArmBase = robot_cls(self.node, robot_kwargs)
     self.__task = task_cls(self.node, self.__robot, task_kwargs)
     self.action_space = self.__robot.get_action_space()
     self.observation_space = self.__get_observation_space()
     # Set up ROS related variables
     self.__episode_num = 0
     self.__cumulated_episode_reward = 0
     self.__step_num = 0
     self.reset()
Exemple #7
0
 def on_shutdown(self, handler):
     rclpy.get_default_context().on_shutdown(handler)