problems with loop time
This commit is contained in:
parent
26a64db6d6
commit
e0451ab4e3
@ -73,7 +73,7 @@ class ActiveRLService(Node):
|
|||||||
self.display_run = False
|
self.display_run = False
|
||||||
|
|
||||||
# Main loop timer object
|
# Main loop timer object
|
||||||
self.mainloop_timer_period = 0.05
|
self.mainloop_timer_period = 0.1
|
||||||
self.mainloop = self.create_timer(self.mainloop_timer_period,
|
self.mainloop = self.create_timer(self.mainloop_timer_period,
|
||||||
self.mainloop_callback,
|
self.mainloop_callback,
|
||||||
callback_group=mainloop_callback_group)
|
callback_group=mainloop_callback_group)
|
||||||
|
@ -74,6 +74,7 @@ class ActiveBOTopic(Node):
|
|||||||
self.rl_final_step = None
|
self.rl_final_step = None
|
||||||
self.rl_reward = 0.0
|
self.rl_reward = 0.0
|
||||||
self.user_asked = False
|
self.user_asked = False
|
||||||
|
self.last_user_reward = 0.0
|
||||||
|
|
||||||
# State Publisher
|
# State Publisher
|
||||||
self.state_pub = self.create_publisher(ActiveBOState, 'active_bo_state', 1)
|
self.state_pub = self.create_publisher(ActiveBOState, 'active_bo_state', 1)
|
||||||
@ -111,6 +112,8 @@ class ActiveBOTopic(Node):
|
|||||||
self.current_episode = 0
|
self.current_episode = 0
|
||||||
self.save_result = False
|
self.save_result = False
|
||||||
self.seed_array = None
|
self.seed_array = None
|
||||||
|
self.env = None
|
||||||
|
self.active_bo_pending = False
|
||||||
|
|
||||||
def active_bo_callback(self, msg):
|
def active_bo_callback(self, msg):
|
||||||
if not self.active_bo_pending:
|
if not self.active_bo_pending:
|
||||||
@ -164,6 +167,10 @@ class ActiveBOTopic(Node):
|
|||||||
self.init_step = 0
|
self.init_step = 0
|
||||||
self.init_pending = False
|
self.init_pending = False
|
||||||
|
|
||||||
|
if self.user_asked:
|
||||||
|
self.last_user_reward = self.rl_reward
|
||||||
|
self.user_asked = False
|
||||||
|
|
||||||
self.rl_pending = False
|
self.rl_pending = False
|
||||||
self.reset_rl_response()
|
self.reset_rl_response()
|
||||||
|
|
||||||
@ -171,16 +178,17 @@ class ActiveBOTopic(Node):
|
|||||||
if self.active_bo_pending:
|
if self.active_bo_pending:
|
||||||
|
|
||||||
# set rl environment
|
# set rl environment
|
||||||
if self.bo_env == "Mountain Car":
|
if self.env is None:
|
||||||
self.env = Continuous_MountainCarEnv()
|
if self.bo_env == "Mountain Car":
|
||||||
elif self.bo_env == "Cartpole":
|
self.env = Continuous_MountainCarEnv()
|
||||||
self.env = CartPoleEnv()
|
elif self.bo_env == "Cartpole":
|
||||||
elif self.bo_env == "Acrobot":
|
self.env = CartPoleEnv()
|
||||||
self.env = AcrobotEnv()
|
elif self.bo_env == "Acrobot":
|
||||||
elif self.bo_env == "Pendulum":
|
self.env = AcrobotEnv()
|
||||||
self.env = PendulumEnv()
|
elif self.bo_env == "Pendulum":
|
||||||
else:
|
self.env = PendulumEnv()
|
||||||
raise NotImplementedError
|
else:
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
if self.BO is None:
|
if self.BO is None:
|
||||||
self.BO = BayesianOptimization(self.env,
|
self.BO = BayesianOptimization(self.env,
|
||||||
@ -194,7 +202,7 @@ class ActiveBOTopic(Node):
|
|||||||
# self.BO.initialize()
|
# self.BO.initialize()
|
||||||
self.init_pending = True
|
self.init_pending = True
|
||||||
self.get_logger().info('BO Initialization is starting!')
|
self.get_logger().info('BO Initialization is starting!')
|
||||||
self.get_logger().info(f'{self.rl_pending}')
|
# self.get_logger().info(f'{self.rl_pending}')
|
||||||
|
|
||||||
if self.init_pending and not self.rl_pending:
|
if self.init_pending and not self.rl_pending:
|
||||||
|
|
||||||
@ -283,8 +291,6 @@ class ActiveBOTopic(Node):
|
|||||||
self.get_logger().info('Responding: Active BO')
|
self.get_logger().info('Responding: Active BO')
|
||||||
self.active_bo_pub.publish(bo_response)
|
self.active_bo_pub.publish(bo_response)
|
||||||
self.reset_bo_request()
|
self.reset_bo_request()
|
||||||
self.active_bo_pending = False
|
|
||||||
self.BO = None
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if self.rl_pending or self.init_pending:
|
if self.rl_pending or self.init_pending:
|
||||||
@ -388,9 +394,7 @@ class ActiveBOTopic(Node):
|
|||||||
state_msg.current_episode = self.current_episode + 1 \
|
state_msg.current_episode = self.current_episode + 1 \
|
||||||
if self.current_episode < self.bo_episodes else self.bo_episodes
|
if self.current_episode < self.bo_episodes else self.bo_episodes
|
||||||
state_msg.best_reward = float(self.best_reward)
|
state_msg.best_reward = float(self.best_reward)
|
||||||
if self.user_asked:
|
state_msg.last_user_reward = self.last_user_reward
|
||||||
state_msg.last_user_reward = float(self.rl_reward)
|
|
||||||
self.user_asked = False
|
|
||||||
self.state_pub.publish(state_msg)
|
self.state_pub.publish(state_msg)
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,14 +16,14 @@ def generate_launch_description():
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
rl_launch = IncludeLaunchDescription(
|
# rl_launch = IncludeLaunchDescription(
|
||||||
PythonLaunchDescriptionSource(
|
# PythonLaunchDescriptionSource(
|
||||||
os.path.join(
|
# os.path.join(
|
||||||
get_package_share_directory('active_bo_ros'),
|
# get_package_share_directory('active_bo_ros'),
|
||||||
'rl_service.launch.py'
|
# 'rl_service.launch.py'
|
||||||
)
|
# )
|
||||||
)
|
# )
|
||||||
)
|
# )
|
||||||
|
|
||||||
bo_launch = IncludeLaunchDescription(
|
bo_launch = IncludeLaunchDescription(
|
||||||
PythonLaunchDescriptionSource(
|
PythonLaunchDescriptionSource(
|
||||||
@ -36,6 +36,6 @@ def generate_launch_description():
|
|||||||
|
|
||||||
return LaunchDescription([
|
return LaunchDescription([
|
||||||
websocket_launch,
|
websocket_launch,
|
||||||
rl_launch,
|
# rl_launch,
|
||||||
bo_launch
|
bo_launch
|
||||||
])
|
])
|
||||||
|
Loading…
Reference in New Issue
Block a user