def main(): global agent try: agent = Optimalagent(Parameters1) kim = Communication() kim.run() kim.runner1() kim.runner2() time.sleep(3) print(kim.state) state_set = [kim.state] action_1 = -2.1 action_2 = -2.1 while True: t1 = time.time() kim.translate() agent.state = kim.state print(agent.state) msg1 = {"force_x": action_1, "force_y": 0, "force_z": 0} msg2 = {"force_x": action_2, "force_y": 0, "force_z": 0} #msg1 = {"force_x": 0, "force_y": 0, "force_z": 0} #msg2 = {"force_x": 0, "force_y": 0, "force_z": 0} msg1_json = json.dumps(msg1) msg2_json = json.dumps(msg2) # pallavi kim.send(msg1_json) kim.my_sender(msg2_json) # pallavi t2 = time.time() agent.data_append(kim.state, action_1, action_2, t2) if t2 - t1 - Parameters1.T < 0: time.sleep(Parameters1.T - t2 + t1) except KeyboardInterrupt: np.savetxt("rot_sysid.csv", agent.state_set, delimiter=",")
log_string("\tPort: " + port) log_string("\tBaud rate: " + str(baud)) # Try all ranges in port i = 0 ser = serial.Serial() for i in range(0, 10): try: ser = serial.Serial(port + str(i), baud, timeout=0) break except serial.serialutil.SerialException as e: pass if i == 9: rospy.logerr("No serial port found: " + port) exit(0) attempt = 0 rate = rospy.Rate(1) while not rospy.is_shutdown(): try: comm = Communication(ser) comm.run() break except serial.serialutil.SerialException as e: ser.close() log_string("Serial exception. " + e.strerror + " Retrying...(attempt {0})".format(attempt)) attempt = attempt + 1 rate.sleep()
#!/usr/bin/env python3 __author__ = "Rafał Prusak" __doc__ = "skrypt uruchamiający symylację dostawcy energi" from communication import Communication from wheather import WheatherGenerator from config import Configuration from model import Model from logs import Logger import time import json if __name__ == "__main__": Logger.init() with open('data.txt') as data_file: WheatherGenerator.data = json.load(data_file) # print(WheatherGenerator.data.keys()) Configuration.init() provider_model = Model() communicator = Communication(provider_model) while 1: # time.sleep(2) communicator.run()