Could somebody help me with a lab I'm doing for school on CoppeliaSim Edu? I can't really figure out the issue I'm having
So I'm doing a lab that just involves tying a python script to a cuboid to make it move around, but for the life of me I can't get it to move. The code my professor gave us in the lab is as follows:
Python
# lab1_part1.py
import sim
import time
import math
print('Program started')
# Close any existing connections
sim.simxFinish(-1)
# Connect to CoppeliaSim
clientID = sim.simxStart('127.0.0.1', 19997, True, True, 5000, 5)
if clientID != -1:
print('Connected to remote API server')
# Get the handle for the 'Cuboid' object
errorCode, objectHandle = sim.simxGetObjectHandle(clientID, 'Cuboid', sim.simx_opmode_blocking)
if errorCode == sim.simx_return_ok:
print('Got object handle for Cuboid')
# 1. --- Change Position ---
# Define the new position [X, Y, Z]
new_position = [0.5, 0.2, 0.3]
# Set the object's position
sim.simxSetObjectPosition(clientID, objectHandle, -1, new_position, sim.simx_opmode_oneshot)
print(f"Moved Cuboid to position: {new_position}")
time.sleep(2) # Pause for 2 seconds to observe the change
# 2. --- Change Orientation ---
# Define the new orientation using Euler angles [alpha, beta, gamma] in radians
# For example, 90 degrees around the Z-axis and 45 degrees around the Y-axis
new_orientation_rad = [0, math.radians(45), math.radians(90)]
# Set the object's orientation
sim.simxSetObjectOrientation(clientID, objectHandle, -1, new_orientation_rad, sim.simx_opmode_oneshot)
print(f"Changed Cuboid orientation to (radians): {new_orientation_rad}")
else:
print(f"Could not get object handle. Error code: {errorCode}")
# Close the connection to CoppeliaSim
sim.simxFinish(clientID)
print('Connection closed')
else:
print('Failed connecting to remote API server')
print('Program finished')
So I put that into Visual Studio 2019 and I get an error message saying that there is no module in the file name "sim" (there is) and when I tie this to the cuboid it doesn't move or anything.
And on top of that, I can't even tie the script to the cuboid the way the instructions tell me to! The way it's written it says, "Select the Cuboid in the Scene Hierarchy. Click Add > Associated child script > Non-threaded. This script will run along with the simulation. We don't need to edit it for this part, but it's good practice to have it."
The way my CoppeliaSim Edu is working, the option tree for the cuboid goes add>script>simulation or customization script, there's no option for Associated child script.
So yeah I'm not sure what's happening and my professor hasn't emailed me back, I have until 5pm EST to get this turned in. Can you guys help me figure out what's going on? If you need more info I can give it to you.
Posted Sep 7, 2025, 10:35 PM UTC