Open xander-2077 opened 1 year ago
Hi,
I never tried the ZMQ client of coppeliaSim but I will (you piqued my curiosity) and report back. The connection to the simulated robot should work the same as there is a dedicated [connection] thread. Make sure you first start the simulation (the equivalent of pressing play in the GUI), before trying to connect. In particular, the simulated robot should at least execute the init simRobomaster.create_{s1|ep}(...)
, else it won't start the connection thread.
@xander-2077 I tested connecting to a robomaster while running the simulation using a ZMQ client, like in your script.
The short version is that you need to run the simulation while connecting to the client. The following works:
client.setStepping(False)
sim.startSimulation()
ep_robot = robot.Robot()
ep_robot.initialize(conn_type="sta")
client.setStepping(True)
The longer version
The real | simulated robomaster uses a discovery mechanism to announce itself to clients, for which it publishes a discovery message every second.
When the client executes ep_robot.initialize()
, it waits to receive one of these messages: if none are received, it fails, like your log. Now, in simulation, the timer that sends the discovery messages (https://github.com/jeguzzi/robomaster_sim/blob/main/src/discovery.cpp#L46) is triggered (indirectly) by the simulation step (https://github.com/jeguzzi/robomaster_sim/blob/main/coppeliaSim_plugin/plugin.cpp#L614). Therefore, while the simulation is paused (like between calls of client.step()
if we set client.setStepping(True)
), the discovery message are not sent and the client does not connect. Instead, when the simulation is running (like above), they are sent and the client connects. Once connected, we can pause the simulation.
An alternative would be to run ep_robot.initialize()
and client.step()
concurrently (e.g. in different threads).
I cannot connect to the robot when turning on synchronize mode in CoppeliaSim. A small snippet of display code:
An error occurred:
Can I connect to robot in this mode? Thank you!