コード例 #1
0
 def pub_gp_result_callback(self):
     if self.isSetController is None:
         return
     x_sampling_points = np.linspace(self.controller.bounds[0][0],
                                     self.controller.bounds[0][1],
                                     500)  # Number of sampling points
     x_sampling_points = x_sampling_points[:,
                                           None]  # Reshape For GPy input shape
     msg = GP()
     mean, var = self.controller.model.predict(x_sampling_points)
     train_x = self.controller.X
     train_y = self.controller.Y
     msg.x_sampling_points = encode_array(x_sampling_points,
                                          msg.x_sampling_points)
     msg.mean = encode_array(mean, msg.mean)
     msg.var = encode_array(var, msg.var)
     msg.train_x = encode_array(train_x, msg.train_x)
     msg.train_y = encode_array(train_y, msg.train_y)
     msg.iter_num = self.iter_num
     self.pub_gp_result.publish(msg)
コード例 #2
0
    def update(self):
        self.get_logger().info('on update')

        x_star = self.controller.calc_next_point()  # Loop 1) 2) 3)

        # Wait for response
        response = self.request_service_sync(
            self.cli_target_object,
            encode_array(array=x_star.x, comm_data=self.req))

        # Do something about response

        y_star = decode_array(response)

        self.controller.add_x_y_to_T(x_star.x, y_star)  # Loop 5)
コード例 #3
0
 def obtain_y_at_x(self, x):
     self.req = encode_array(array=x, comm_data=self.req)
     self.future = self.cli_target_object.call_async(self.req)
     while True:
         if not self.isSetController:
             rclpy.spin_once(self)
         if self.future.done():
             try:
                 response = self.future.result()
             except Exception as e:
                 self.get_logger().info('Service call failed %r' % (e, ))
             else:
                 self.get_logger().info('Success!')
                 break
     y = decode_array(response)
     return y
コード例 #4
0
    def update(self):
        self.get_logger().info('on update')

        # 1) 2) 3) in Loop
        x_star = self.controller.calc_next_point()

        # 4) in Loop # Wait for response
        response = self.request_service_sync(
            self.cli_target_object,
            encode_array(array=x_star.x, comm_data=self.req))

        # 5) in Loop
        y_star = decode_array(response)
        self.controller.add_x_y_to_T(x_star.x, y_star)

        self.iter_num += 1
コード例 #5
0
 def surface_shape_callback(self, request, response):
     x = decode_array(request)
     surface_array = self.target_object.surface_shape(x)
     # surface_shape's type is np.array, so it should be transform to list (not nest)
     response = encode_array(surface_array, response)
     return response