The python script can't interact with CoppeliaSim in headless mode normally.
Posted: 04 Apr 2022, 08:38
Hi~ when I try to use the following code to control YouBot to move forward and keep recording the position of the robot, the code works fine under the GUI mode. However, if I launch CoppeliaSim in headless mode with parameter "-h -gREMOTEAPISERVERSERVICE_19998_False_True" and run the code, the car doesn't seem to be moving as the output keeps the same. I have no idea why there is such a difference in the two different modes. The problem exists in CoppeliaSim V4.0/4.1/4.2 and the system I used is Ubuntu 18.04/macOS Monterey 12.1.
Code: Select all
import sim
sim.simxFinish(-1)
clientID = sim.simxStart('127.0.0.1',19998,True,True,5000,5)
_, youBot_handle = sim.simxGetObjectHandle(clientID, 'youBot', sim.simx_opmode_blocking)
wheel_joints_handle = [-1,-1,-1,-1];
_, wheel_joints_handle[0] = sim.simxGetObjectHandle(clientID, 'rollingJoint_fl', sim.simx_opmode_blocking)
_, wheel_joints_handle[1] = sim.simxGetObjectHandle(clientID, 'rollingJoint_fr', sim.simx_opmode_blocking)
_, wheel_joints_handle[2] = sim.simxGetObjectHandle(clientID, 'rollingJoint_rr', sim.simx_opmode_blocking)
_, wheel_joints_handle[3] = sim.simxGetObjectHandle(clientID, 'rollingJoint_rl', sim.simx_opmode_blocking)
[forward_back_vel, left_right_vel, rotation_vel] = [0.5, 0, 0]
while True:
sim.simxSetJointTargetVelocity(clientID, wheel_joints_handle[0], -forward_back_vel + left_right_vel - rotation_vel, sim.simx_opmode_blocking)
sim.simxSetJointTargetVelocity(clientID, wheel_joints_handle[1], -forward_back_vel - left_right_vel + rotation_vel, sim.simx_opmode_blocking)
sim.simxSetJointTargetVelocity(clientID, wheel_joints_handle[2], -forward_back_vel + left_right_vel + rotation_vel, sim.simx_opmode_blocking)
sim.simxSetJointTargetVelocity(clientID, wheel_joints_handle[3], -forward_back_vel - left_right_vel - rotation_vel, sim.simx_opmode_blocking)
_, youBot_position = sim.simxGetObjectPosition(clientID, youBot_handle, -1, sim.simx_opmode_blocking)
print(youBot_position)