Resetting simulation
trying to stop program, reset simulation and restart program. Program not responding.
#!/usr/bin/env python3
import rospy
from std_msgs.msg import Float64
import math
import random
from sensor_msgs.msg import JointState
import numpy as np
import time
import threading
from std_srvs.srv import Empty
import sys
start_time = time.time()
reset_simulation = rospy.ServiceProxy('/gazebo/reset_simulation', Empty)
class RobotControl:
def __init__(self):
rospy.init_node('robot_control_node', anonymous=True)
self.talker = rospy.Publisher('/rrbot/joint1_position_controller/command', Float64, queue_size=10)
rospy.Subscriber('/rrbot/joint_states', JointState, self.joint_callback)
self.force = None
self.joint = None
self.rate = rospy.Rate(10)
while not rospy.is_shutdown():
self.give_force()
self.rate.sleep()
def give_force(self):
self.force = random.choice([-3,3]) # Changes force every time, right before publishing
self.talker.publish(self.force)
def joint_callback(self, data):
self.joint = data.position[0]
reward = None
if self.observation_check() is True:
reward = (time.time() - start_time)
#sys.exit("restarting simulation")
'''
reset_simulation()
self.rate.sleep()
RobotControl()
'''
else:
pass
print(reward)
#return reward
def observation_check(self):
max_height = -3.2
if self.joint < max_height:
done = True
else:
done = False
return done
def robotcontrolloop():
if RobotControl() is not None:
reset_simulation()
robotcontrolloop()
if __name__ == "__main__":
# Instantiate the class
RobotControl()