示例#1
0
def main():
    rospy.init_node(name='grasping', anonymous=True)
    pnp = BaxterAPI(args.limb, args.hover_distance,
                    args.reach_distance)  # pick and place
    pnp.move_to_start(initial_pose)
    image_tools = ImageTools(img_id=args.img_id)

    while not rospy.is_shutdown():
        utils.listener(args.topic_name, image_tools.callback)
def main():
    rospy.init_node(name='grasping', anonymous=True)
    pnp = BaxterAPI(args.limb, args.hover_distance,
                    args.reach_distance)  # pick and place
    pnp.move_to_start(initial_pose)
    image_tools = ImageTools(img_id=args.img_id)

    images_t = tf.placeholder(dtype=tf.float32, shape=[None, 224, 224, 3])
    images_t = images_t - [123.68, 116.779, 103.939]
    with slim.arg_scope(model_arg_scope()):
        net, end_points = model(inputs=images_t,
                                num_classes=num_classes,
                                is_training=False,
                                dropout_keep_prob=1.0,
                                scope='target_only')
        # with slim.arg_scope(model_arg_scope()):
        #     net, end_points = model(inputs=images_t,
        #                             num_classes=num_classes,
        #                             is_training=False,
        #                             dropout_keep_prob=1.0,
        #                             reuse=None,
        #                             scope='domain_adapt',
        #                             adapt_scope='target_adapt_layer',
        #                             adapt_dims=128)
        angle_index_t = tf.argmin(net, axis=1)

        saver = tf.train.Saver()
        session_config = tf.ConfigProto(allow_soft_placement=True,
                                        log_device_placement=False)
        session_config.gpu_options.allow_growth = True
        sess = tf.Session(config=session_config)
        saver.restore(sess, tf.train.latest_checkpoint(args.checkpoint_dir))
        print 'Successfully loading model.'

    while not rospy.is_shutdown():
        flag = 0
        while flag != 1:
            c_x, c_y = utils.get_center_coordinate_from_kinect(
                args.center_coor, args.limb)
            d_x = float(c_x) / 1000.0
            d_y = float(c_y) / 1000.0
            x = origin[0] + d_x
            y = origin[1] + d_y
            z = origin[2]
            flag = pnp.approach(
                Pose(position=Point(x, y, z), orientation=initial_orientation))
        rospy.sleep(0.7)
        utils.listener(args.topic_name, image_tools)
        coors, images = image_tools.sampling_image(args.patch_size,
                                                   args.num_patches)
        scores = sess.run(net, feed_dict={images_t: images})
        patch, coor, new_coors = image_tools.resampling_image(
            scores, coors, args.patch_size)
        angle_index, scores = sess.run([angle_index_t, net],
                                       feed_dict={images_t: patch})
        angle_index = angle_index[0]
        print angle_index
        print scores
        grasp_angle = (angle_index * 10 - 90) * 1.0 / 180 * pi
        x -= float(coor[0] - 160) * 0.6 / 1000
        y -= float(coor[1] - 320) * 0.5 / 1000
        z = z
        pose = Pose(position=Point(x, y, z), orientation=initial_orientation)
        success = pnp.pick(pose, image_tools, args.output_path, new_coors,
                           coor, args.patch_size, grasp_angle)
        pnp.move_to_start(initial_pose)