ZMQapiRequest issues
-
- Posts: 7
- Joined: 24 Oct 2023, 12:40
ZMQapiRequest issues
Hey everyone,
I have put my 'defaultPython' to the interpreter I am wishing to use . I am
trying to excute a python script which requires 'sim' module.
here is how it is showing error :
[CoppeliaSim:warning] Detected non-default settings (time steps and/or dyn.
engine global settings).
[/Motor_C@childScript:error]
...es/CoppeliaRobotics/CoppeliaSimEdu/lua/pythonWrapper.lua:311: Traceback
(most recent call last):
File "C:/Program
Files/CoppeliaRobotics/CoppeliaSimEdu/python/pythonLauncher.py", line 18,
in <module>
script, line 2, in <module>
ModuleNotFoundError: No module named 'sim'
stack traceback:
[C]: in function 'error'
...es/CoppeliaRobotics/CoppeliaSimEdu/lua/pythonWrapper.lua:311: in
function 'initPython'
...es/CoppeliaRobotics/CoppeliaSimEdu/lua/pythonWrapper.lua:225: in
function 'sysCall_init'
[sandboxScript:info] Simulation suspended.
please help me to resolve the issue.
I have put my 'defaultPython' to the interpreter I am wishing to use . I am
trying to excute a python script which requires 'sim' module.
here is how it is showing error :
[CoppeliaSim:warning] Detected non-default settings (time steps and/or dyn.
engine global settings).
[/Motor_C@childScript:error]
...es/CoppeliaRobotics/CoppeliaSimEdu/lua/pythonWrapper.lua:311: Traceback
(most recent call last):
File "C:/Program
Files/CoppeliaRobotics/CoppeliaSimEdu/python/pythonLauncher.py", line 18,
in <module>
script, line 2, in <module>
ModuleNotFoundError: No module named 'sim'
stack traceback:
[C]: in function 'error'
...es/CoppeliaRobotics/CoppeliaSimEdu/lua/pythonWrapper.lua:311: in
function 'initPython'
...es/CoppeliaRobotics/CoppeliaSimEdu/lua/pythonWrapper.lua:225: in
function 'sysCall_init'
[sandboxScript:info] Simulation suspended.
please help me to resolve the issue.
Re: ZMQapiRequest issues
Hello,
please download CoppeliaSim V4.6 and try again. By default CoppeliaSim V4.6 will use another wrapper: pythonWrapperV2.lua, which performs much better than previous one.
Cheers
please download CoppeliaSim V4.6 and try again. By default CoppeliaSim V4.6 will use another wrapper: pythonWrapperV2.lua, which performs much better than previous one.
Cheers
-
- Posts: 7
- Joined: 24 Oct 2023, 12:40
Re: ZMQapiRequest issues
Now I am facing the following issue after downloading 4.6.0v.
Here is the code I ran:=================================================================
#python
import numpy as np
import sim
# Define global variables
base = 0.05
motor = 0.15
arm = 0.10
pendulum = 0.30
U = None
# LQR control gains
Q = np.diag([1, 1, 1, 1]) # State cost weight matrix
R = np.array([[1]]) # Input cost weight matrix
# LQR control function to calculate control inputs
def lqr_control(A, B, Q, R):
P = np.matrix(np.linalg.solve(A.T @ P @ A - A.T @ P @ B @ np.linalg.solve(R + B.T @ P @ B, B.T @ P @ A), np.eye(4)))
K = np.linalg.solve(R + B.T @ P @ B, B.T @ P @ A)
return K
# System initialization
def sysCall_init():
global base, motor, arm, pendulum, U
# Get handles for objects
base = sim.getObjectHandle("Base")
motor = sim.getObjectHandle("Motor")
arm = sim.getObjectHandle("Arm")
pendulum = sim.getObjectHandle("Pendulum")
# Set the initial state and time step
sim.simxSetObjectPosition(motor, base, [0, 0, 0])
sim.simxSetObjectOrientation(motor, base, [0, 0, 0])
U = 0.0
# Actuation step
def sysCall_actuation():
global U
# Get the state and error
_, position = sim.simxGetObjectPosition(motor, base, -1)
_, orientation = sim.simxGetObjectOrientation(motor, base, -1)
x, x_dot, theta, theta_dot = position[1], position[2], orientation[2], sim.simxGetJointPosition(arm, -1)[1] # Corrected this line
# Define the state-space model matrices A and B
A = np.array([[0, 1, 0, 0],
[0, 0, 9.81 * np.cos(theta), 0],
[0, 0, 0, 1],
[0, 0, 9.81 * np.sin(theta), 0]])
B = np.array([[0],
[-1],
[0],
[-np.cos(theta)]])
# Calculate control input using LQR
K = lqr_control(A, B, Q, R)
state = np.array([x, x_dot, theta, theta_dot])
U = float(-K @ state)
# Apply control input to the motor
sim.simxSetJointTargetVelocity(motor, U, sim.simx_opmode_oneshot)
# Sensing step (not used in LQR control)
def sysCall_sensing():
pass
# Clean-up step
def sysCall_cleanup():
# Stop the motor after simulation ends
sim.simxSetJointTargetVelocity(motor, 0, sim.simx_opmode_oneshot)
# Initialize the CoppeliaSim remote API
sim.simxFinish(-1) # Close all open connections
clientID = sim.simxStart("127.0.0.1", 19999, True, True, 5000, 5)
if clientID != -1:
sim.simxAddStatusbarMessage(clientID, "Python controller connected to CoppeliaSim", sim.simx_opmode_oneshot)
sim.simxSynchronous(clientID, True)
sim.simxStartSimulation(clientID, sim.simx_opmode_oneshot_wait)
sysCall_init()
while True:
sysCall_actuation()
sim.simxSynchronousTrigger(clientID)
sysCall_cleanup()
sim.simxStopSimulation(clientID, sim.simx_opmode_oneshot_wait)
sim.simxFinish(clientID)
else:
print("Failed to connect to CoppeliaSim")
ERROR:==========================================================================
[CoppeliaSim:warning] Detected non-default settings (time steps and/or dyn. engine global settings).
[/Motor_C@childScript:error] Traceback (most recent call last):
script, line 3, in <module>
ModuleNotFoundError: No module named 'sim'
[/Motor_A@childScript:warning] using the compatibility python wrapper ('pythonWrapper.lua')
[/Motor_A@childScript:error] ...es/CoppeliaRobotics/CoppeliaSimEdu/lua/pythonWrapper.lua:234: attempt to concatenate a nil value (global 'pythonProg')
stack traceback:
...es/CoppeliaRobotics/CoppeliaSimEdu/lua/pythonWrapper.lua:234: in function 'sysCall_init'
[/Pivot_B@childScript:warning] using the compatibility python wrapper ('pythonWrapper.lua')
[/Pivot_B@childScript:error] ...es/CoppeliaRobotics/CoppeliaSimEdu/lua/pythonWrapper.lua:234: attempt to concatenate a nil value (global 'pythonProg')
stack traceback:
...es/CoppeliaRobotics/CoppeliaSimEdu/lua/pythonWrapper.lua:234: in function 'sysCall_init'
[sandboxScript:info] Simulation suspended.
===============================================================================
please help me out here.
Here is the code I ran:=================================================================
#python
import numpy as np
import sim
# Define global variables
base = 0.05
motor = 0.15
arm = 0.10
pendulum = 0.30
U = None
# LQR control gains
Q = np.diag([1, 1, 1, 1]) # State cost weight matrix
R = np.array([[1]]) # Input cost weight matrix
# LQR control function to calculate control inputs
def lqr_control(A, B, Q, R):
P = np.matrix(np.linalg.solve(A.T @ P @ A - A.T @ P @ B @ np.linalg.solve(R + B.T @ P @ B, B.T @ P @ A), np.eye(4)))
K = np.linalg.solve(R + B.T @ P @ B, B.T @ P @ A)
return K
# System initialization
def sysCall_init():
global base, motor, arm, pendulum, U
# Get handles for objects
base = sim.getObjectHandle("Base")
motor = sim.getObjectHandle("Motor")
arm = sim.getObjectHandle("Arm")
pendulum = sim.getObjectHandle("Pendulum")
# Set the initial state and time step
sim.simxSetObjectPosition(motor, base, [0, 0, 0])
sim.simxSetObjectOrientation(motor, base, [0, 0, 0])
U = 0.0
# Actuation step
def sysCall_actuation():
global U
# Get the state and error
_, position = sim.simxGetObjectPosition(motor, base, -1)
_, orientation = sim.simxGetObjectOrientation(motor, base, -1)
x, x_dot, theta, theta_dot = position[1], position[2], orientation[2], sim.simxGetJointPosition(arm, -1)[1] # Corrected this line
# Define the state-space model matrices A and B
A = np.array([[0, 1, 0, 0],
[0, 0, 9.81 * np.cos(theta), 0],
[0, 0, 0, 1],
[0, 0, 9.81 * np.sin(theta), 0]])
B = np.array([[0],
[-1],
[0],
[-np.cos(theta)]])
# Calculate control input using LQR
K = lqr_control(A, B, Q, R)
state = np.array([x, x_dot, theta, theta_dot])
U = float(-K @ state)
# Apply control input to the motor
sim.simxSetJointTargetVelocity(motor, U, sim.simx_opmode_oneshot)
# Sensing step (not used in LQR control)
def sysCall_sensing():
pass
# Clean-up step
def sysCall_cleanup():
# Stop the motor after simulation ends
sim.simxSetJointTargetVelocity(motor, 0, sim.simx_opmode_oneshot)
# Initialize the CoppeliaSim remote API
sim.simxFinish(-1) # Close all open connections
clientID = sim.simxStart("127.0.0.1", 19999, True, True, 5000, 5)
if clientID != -1:
sim.simxAddStatusbarMessage(clientID, "Python controller connected to CoppeliaSim", sim.simx_opmode_oneshot)
sim.simxSynchronous(clientID, True)
sim.simxStartSimulation(clientID, sim.simx_opmode_oneshot_wait)
sysCall_init()
while True:
sysCall_actuation()
sim.simxSynchronousTrigger(clientID)
sysCall_cleanup()
sim.simxStopSimulation(clientID, sim.simx_opmode_oneshot_wait)
sim.simxFinish(clientID)
else:
print("Failed to connect to CoppeliaSim")
ERROR:==========================================================================
[CoppeliaSim:warning] Detected non-default settings (time steps and/or dyn. engine global settings).
[/Motor_C@childScript:error] Traceback (most recent call last):
script, line 3, in <module>
ModuleNotFoundError: No module named 'sim'
[/Motor_A@childScript:warning] using the compatibility python wrapper ('pythonWrapper.lua')
[/Motor_A@childScript:error] ...es/CoppeliaRobotics/CoppeliaSimEdu/lua/pythonWrapper.lua:234: attempt to concatenate a nil value (global 'pythonProg')
stack traceback:
...es/CoppeliaRobotics/CoppeliaSimEdu/lua/pythonWrapper.lua:234: in function 'sysCall_init'
[/Pivot_B@childScript:warning] using the compatibility python wrapper ('pythonWrapper.lua')
[/Pivot_B@childScript:error] ...es/CoppeliaRobotics/CoppeliaSimEdu/lua/pythonWrapper.lua:234: attempt to concatenate a nil value (global 'pythonProg')
stack traceback:
...es/CoppeliaRobotics/CoppeliaSimEdu/lua/pythonWrapper.lua:234: in function 'sysCall_init'
[sandboxScript:info] Simulation suspended.
===============================================================================
please help me out here.
Re: ZMQapiRequest issues
You are using the compatibility wrapper. If you want to use the new, improved version, remove the first few lines in your script that say:
then, in your init phase, immediately load the sim namespace, e.g.:
Cheers
Code: Select all
#luaExec wrapper='pythonWrapper' -- using the old wrapper for backw. compat.
# To switch to the new wrapper, simply remove above line, and add sim=require('sim')
# as the first instruction in sysCall_init() or sysCall_thread()
Code: Select all
def sysCall_init():
sim = require('sim')
...
-
- Posts: 7
- Joined: 24 Oct 2023, 12:40
Re: ZMQapiRequest issues
Can you help me out with the following after running previously given python script:
================================================================================
[/Motor_C@childScript:error] Traceback (most recent call last):
script, line 3, in <module>
ModuleNotFoundError: No module named 'sim'
================================================================================
[/Motor_C@childScript:error] Traceback (most recent call last):
script, line 3, in <module>
ModuleNotFoundError: No module named 'sim'
Re: ZMQapiRequest issues
post the scene please
Cheers
Cheers
-
- Posts: 7
- Joined: 24 Oct 2023, 12:40
Re: ZMQapiRequest issues
Here is the image of the scene.
[img]
file:///C:/Users/Madhava/Pictures/Screenshots/Screenshot%202023-10-26%20010135.png
[/img]
[img]
file:///C:/Users/Madhava/Pictures/Screenshots/Screenshot%202023-10-26%20010135.png
[/img]
Re: ZMQapiRequest issues
you posted a link to a local file...
-
- Posts: 7
- Joined: 24 Oct 2023, 12:40
Re: ZMQapiRequest issues
I am sorry...
Here is the image of the scene...
https://drive.google.com/file/d/1vH4fYi ... p=drivesdk
please respond quickly, It's urgent.
Thank You.
Here is the image of the scene...
https://drive.google.com/file/d/1vH4fYi ... p=drivesdk
please respond quickly, It's urgent.
Thank You.
Re: ZMQapiRequest issues
We can't do anything with the picture... post the scene file!