problem with getCameraImage and python 3.5.3

Post Reply
vasnakh
Posts: 1
Joined: Mon May 15, 2017 6:21 am

problem with getCameraImage and python 3.5.3

Post by vasnakh »

I am trying to use pybullet.getCameraImage in python 3.5.3 and I get the following error:

SystemError: null argument to internal routine

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:/Users/Vasna/Documents/PycharmProjects/RoboticsHw2/Hw4_P4_B - Copy.py", line 40, in <module>
test = p.getCameraImage(800,600)
SystemError: <built-in function getCameraImage> returned a result with an error set



Does anyone know why I get this error message? I tried to run the same code on 3 different computers and different OS (Windows, and Ubuntu) and it got the same error again. Even python 2.7 didn't work for me. I am attaching the code as well for further investigation if needed. I really appreciate any help.




code:

import pybullet as p
import time
import math
# import ffmpy as ffmpeg
import os
from datetime import datetime


p.connect(p.GUI)

path = 'C:/Users/Vasna/Documents/bullet3/data/'

# load table and plane and set gravity
p.loadURDF(path+"plane.urdf")
tableId = p.loadURDF(path + 'table/table.urdf', [0,0,0])
p.setGravity(0,0,-10)


# load robot on table
robot_initial_pos = [0,0,.6]
kukaId = p.loadURDF(path + 'kuka_lwr/kuka.urdf',robot_initial_pos,useFixedBase=True)
numJointsRobot = p.getNumJoints(kukaId)



# load grip and attach it to robot
gripperId = p.loadSDF(path+"gripper/wsg50_one_motor_gripper_new_free_base.sdf")[0]
p.createConstraint(kukaId,6,gripperId,0,p.JOINT_FIXED,[0,0,0],[0,0,0],[0,0,0])
GRIPPER_CLOSED = [ 0.000000, -0.011130, 0.206421, 0.205143, 0.05, 0.000000, 0.05, 0.000000 ]
GRIPPER_OPEN = [0.000000, -0.011130, -0.206421, 0.205143, -0.01, 0.000000, 0.01, 0.000000]
numJointsGripper = p.getNumJoints(gripperId)

# load ball and put it on table
ballId = p.loadURDF(path + 'sphere_small.urdf',[0.55,0,0.7])
ball_pos = list(p.getBasePositionAndOrientation(ballId)[0])
last_joint_pos = [ball_pos[0]-0.09, ball_pos[1], ball_pos[2]+0.2]


p.setRealTimeSimulation(1)
test = p.getCameraImage(800,600)
time.sleep(1)
# reset Robot position when gripper is attached.
for k in range(numJointsRobot):
p.setJointMotorControl2(bodyIndex=kukaId, jointIndex=k, controlMode=p.POSITION_CONTROL,
targetPosition=0, targetVelocity=0, force=500, positionGain=0.001)


# wait to make sure robot is at initial config
time.sleep(1)

# make sure orientation of grip is facing down all time to grab the ball correctly
gripper_orn = p.getQuaternionFromEuler([0,math.pi,0])

# go to top of the ball
for i in range (100000):
jointPoses = p.calculateInverseKinematics(kukaId, 6, last_joint_pos, gripper_orn)
for k in range(numJointsRobot):
# time.sleep(0.1)

# jointPoses = p.calculateInverseKinematics(kukaId, 6, ball_pos, [0, 0, 0, -1])
p.setJointMotorControl2(bodyIndex=kukaId, jointIndex=k, controlMode=p.POSITION_CONTROL,
targetPosition=jointPoses[k], targetVelocity=0, force=500, positionGain=0.01,
velocityGain=1)
current_pos = list(p.getLinkState(kukaId, 6)[0])
if (math.sqrt((last_joint_pos[2] - current_pos[2]) * (last_joint_pos[2] - current_pos[2]) + (last_joint_pos[1] - current_pos[1]) * (
last_joint_pos[1] - current_pos[1]) + (last_joint_pos[1] - current_pos[1]) * (last_joint_pos[1] - current_pos[1]))) <= 0.01:
break

for k in range(numJointsGripper):
p.setJointMotorControl2(bodyIndex=gripperId, jointIndex=k, controlMode=p.POSITION_CONTROL,
targetPosition=GRIPPER_OPEN[k], targetVelocity=0, force=500, positionGain=0.01,
velocityGain=1)

# approach ball from top
last_joint_pos = [last_joint_pos[0], last_joint_pos[1], last_joint_pos[2]-0.009]
for i in range (1000):
jointPoses = p.calculateInverseKinematics(kukaId, 6, last_joint_pos, gripper_orn)
for k in range(numJointsRobot):
# time.sleep(0.1)

# jointPoses = p.calculateInverseKinematics(kukaId, 6, ball_pos, [0, 0, 0, -1])
p.setJointMotorControl2(bodyIndex=kukaId, jointIndex=k, controlMode=p.POSITION_CONTROL,
targetPosition=jointPoses[k], targetVelocity=0, force=500, positionGain=0.01,
velocityGain=1)

current_pos = list(p.getLinkState(kukaId, 6)[0])
if (math.sqrt((last_joint_pos[2] - current_pos[2]) * (last_joint_pos[2] - current_pos[2]) + (
last_joint_pos[1] - current_pos[1]) * (
last_joint_pos[1] - current_pos[1]) + (last_joint_pos[1] - current_pos[1]) * (
last_joint_pos[1] - current_pos[1]))) <= 0.01:
break



# close the gripper to grab the ball
for k in range(numJointsGripper):
p.setJointMotorControl2(bodyIndex=gripperId, jointIndex=k, controlMode=p.POSITION_CONTROL,
targetPosition=GRIPPER_CLOSED[k], targetVelocity=0, force=500, positionGain=0.01,
velocityGain=1)
# wait for the grip to close properly
time.sleep(1)

# move the ball up
last_joint_pos = [last_joint_pos[0], last_joint_pos[1], last_joint_pos[2]+1]
for i in range (100000):
jointPoses = p.calculateInverseKinematics(kukaId, 6, last_joint_pos, gripper_orn)
for k in range(numJointsRobot):
p.setJointMotorControl2(bodyIndex=kukaId, jointIndex=k, controlMode=p.POSITION_CONTROL,
targetPosition=jointPoses[k], targetVelocity=0, force=500, positionGain=0.01,
velocityGain=1)



time.sleep(20)


User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: problem with getCameraImage and python 3.5.3

Post by Erwin Coumans »

Thanks for the report.

Try adding a few more arguments, at least view matrix and projection matrix. See examples/pybullet/examples/testrender.py for some examples.

Code: Select all


 pybullet.getCameraImage(pixelWidth, pixelHeight, viewMatrix,projectionMatrix, lightDirection,lightColor,renderer=pybullet.ER_TINY_RENDERER)
At the same time, I'll fix the issue when only 2 arguments are used (all the others should be optional).
Post Reply