I'm trying to measure distance between two dynamic objects. Attaching a screenshot showcasing what I'm doing.
The robot is moving along the teal line, and cuboid on the bottom is moving along the blue line.
I couldn't find an API like simGetDistance(robot_handle, cuboid_handle) to return dynamic distance between those two objects, so I have to try something else. Below is what I've tried so far.
1. I tried simGetObjectPosition of those two object respectively, then I apply Euclidean distance to calculate their distance, However, here comes the problematic part to me. Because of the objects are moving, I have to calculate the distance with time goes forward. What I come up with is to use simWait() with a high frequency. But no matter how frequent I adjust the parameter in simWait(), the returned distance is always ~0.37 (which I expect to be more diverse in [0.2, 1.0] ). Attaching my code below:
Code: Select all
robot_position = simGetObjectPosition(robot_handle, -1) cuboid_position = simGetObjectPosition(cuboid_handle, -1) r_dist = math.sqrt(math.pow((robot_position-cuboid_position),2) + math.pow((robot_position-cuboid_position),2)) while furthest_dis < r_dist do furthest_dis = r_dist simWait(0.001, true) r_dist = math.sqrt(math.pow((robot_position-cuboid_position),2) + math.pow((robot_position-cuboid_position),2)) end
Since the graph could get the right data, I believe there's some way the program could measure the distance in a timely fashion, it's just me didn't discover it yet. Could you please help?
Thanks in advance.