|
| 1 | +import concore |
| 2 | +import concore2 |
| 3 | +import time |
| 4 | +from osparc_control import CommandManifest |
| 5 | +from osparc_control import CommandParameter |
| 6 | +from osparc_control import CommandType |
| 7 | +from osparc_control import PairedTransmitter |
| 8 | +# declare some commands to which a reply can be provided |
| 9 | +CONCORE_MANIFEST = CommandManifest( |
| 10 | + action="fun", |
| 11 | + description="function call", |
| 12 | + params=[ |
| 13 | + CommandParameter(name="u", description="control move"), |
| 14 | + ], |
| 15 | + command_type=CommandType.WITH_IMMEDIATE_REPLY, |
| 16 | +) |
| 17 | + |
| 18 | + |
| 19 | +print("funbody 0mq") |
| 20 | +# initialization of 0mq/osparc-control "paired_transmitter" |
| 21 | +paired_transmitter = PairedTransmitter( |
| 22 | + remote_host="localhost", |
| 23 | + exposed_commands=[CONCORE_MANIFEST], |
| 24 | + remote_port=2346, |
| 25 | + listen_port=2345,) |
| 26 | + |
| 27 | +paired_transmitter.start_background_sync() |
| 28 | + |
| 29 | +concore.delay = 0.07 |
| 30 | +concore2.delay = 0.07 |
| 31 | +concore2.inpath = concore.inpath |
| 32 | +concore2.outpath = concore.outpath |
| 33 | +concore2.simtime = 0 |
| 34 | +concore.default_maxtime(100) |
| 35 | +init_simtime_u = "[0.0, 0.0, 0.0]" |
| 36 | +init_simtime_ym = "[0.0, 0.0, 0.0]" |
| 37 | + |
| 38 | +u = concore.initval(init_simtime_u) |
| 39 | +ym = concore2.initval(init_simtime_ym) |
| 40 | +while(concore2.simtime<concore.maxtime): |
| 41 | + #while concore.unchanged(): |
| 42 | + # u = concore.read(concore.iport['U1'],"u",init_simtime_u) |
| 43 | + command_list = paired_transmitter.get_incoming_requests() |
| 44 | + while len(command_list)==0: |
| 45 | + time.sleep(.01) |
| 46 | + command_list = paired_transmitter.get_incoming_requests() |
| 47 | + if len(command_list)>1: |
| 48 | + print("too many commands at once!") |
| 49 | + command = command_list[0] |
| 50 | + if command.action == CONCORE_MANIFEST.action: |
| 51 | + u = command.params["u"] |
| 52 | + concore.simtime = u[0] |
| 53 | + u = u[1:] |
| 54 | + concore.write(concore.oport['U2'],"u",u) |
| 55 | + print(u) |
| 56 | + old2 = concore2.simtime |
| 57 | + while concore2.unchanged() or concore2.simtime <= old2: |
| 58 | + ym = concore2.read(concore.iport['Y2'],"ym",init_simtime_ym) |
| 59 | + ym = [concore2.simtime]+ym |
| 60 | + print(f"Replying to {command.action} with {ym}") |
| 61 | + paired_transmitter.reply_to_command( |
| 62 | + request_id=command.request_id, payload=ym) |
| 63 | + else: |
| 64 | + print("undefined action"+str(command.action)) |
| 65 | + quit() |
| 66 | + #concore2.write(concore.oport['Y1'],"ym",ym) |
| 67 | + print("funbody u="+str(u)+" ym="+str(ym)+" time="+str(concore2.simtime)) |
| 68 | +paired_transmitter.stop_background_sync() |
| 69 | +print("retry="+str(concore.retrycount)) |
0 commit comments