Not able to add objects to scene

**I am trying to add a box to the scene but nothing appears. Do we have to publish something as there is a scene topic as maybe that could be causing this? **

My code:

#!/usr/bin/env python

#All the imports
import sys
import copy
import rospy
import moveit_commander
import moveit_msgs.msg
import geometry_msgs.msg
import random
from std_msgs.msg import String

def add_objects(scene,robot):
print “adding”
rospy.sleep(10)
box_pose = geometry_msgs.msg.PoseStamped()
box_pose.header.frame_id = robot.get_planning_frame()
box_pose.pose.orientation.w = 1.0
box_pose.pose.position.z = 2
box_name = “box”
scene.add_box(box_name, box_pose, size=(1, 1, 1))
rospy.sleep(10)
print “added!”

def move_group_python_interface_tutorial():

moveit_commander.roscpp_initialize(sys.argv)
rospy.init_node('move_group_python_interface_tutorial',
                anonymous=True)
robot = moveit_commander.RobotCommander()

scene = moveit_commander.PlanningSceneInterface()

display_trajectory_publisher = rospy.Publisher(
    '/move_group/display_planned_path',
    moveit_msgs.msg.DisplayTrajectory)

group = moveit_commander.MoveGroupCommander("panda_arm")

add_objects(scene,robot)

rospy.spin()

if name == ‘main’:
try:
move_group_python_interface_tutorial()
except rospy.ROSInterruptException:
pass

Hi @psahay10001,

Could you please specify the course you are taking and the Exercise/Example you are trying to solve?


By the way, welcome to the Community!

Hi Bayodesegun, it worked for after doing a catkin_make. Thanks!

1 Like