I’m having trouble reading values from Prototwin Connect. I can write (.set) values to the model no problem! however if I include any “.get” commands in my python program, the program will seemingly timeout and quit after 5 seconds. Here is the simple program being tested:
import prototwin
import asyncio
simulation_time_address = 0
motor_pos_set = 2
async def main():
client = await prototwin.attach()
while True:
t = client.get(simulation_time_address) # (I comment out in to make program run)
client.set(motor_pos_set, 2) # Works great!
await client.step() # Step the simulation forward in time
asyncio.run(main()) # Run the simulation loop
Hi Antoineft,
I think that I was able to create a simple test case the reproduced the issue you described. When using the python client by itself (i.e. not through the gymnasium environment), the signals are only read at particular points. The client is waiting indefinitely for a response from the call to client.get() because it hasn’t yet received the signals from ProtoTwin.
The call to client.get() doesn’t actually request the signals from ProtoTwin. It only retrieves the last value that was received from ProtoTwin for a particular signal. To fix this, you just need to initialize the simulation before running the simulation loop:
import prototwin
import asyncio
import os
simulation_time_address = 0
motor_pos_set = 2
async def main():
path = os.path.join(os.path.dirname(__file__), "example.ptm")
client = await prototwin.start()
await client.load(path)
await client.initialize() # Initialize before reading!
while True:
t = client.get(simulation_time_address )
client.set(motor_pos_set, 2)
await client.step()
asyncio.run(main())
The call to client.initialize() will initialize the simulation and request the signals from ProtoTwin. After this, the signal values can be read using client.get().
Let me know if you have any questions.
Thanks,
Kareem
That was it, thank you very much Kareem! Very cool piece of software, looking forward to diving more into it!