Ejemplo n.º 1
0
    	def loadWorld(self, filename):
		## SETUP WORLD
		print "-------------------- Creating World --------------------"
		self.world = robotsim.WorldModel()
		res = self.world.readFile(filename)
		if not res:
		    print "Unable to read file", filename
		    exit(0)
		print "-------------------- World Successfully Created --------------------"
		self.robot = self.world.robot(0)
		self.space = robotplanning.makeSpace(world=self.world, robot=self.robot,
		                                edgeCheckResolution=1e-3,
		                                movingSubset='all')
Ejemplo n.º 2
0
    def visualize(self):
        world = robotsim.WorldModel()
        vis.add("world", world)
        vis.add("coordinates", coordinates.manager())
        vis.setWindowTitle("PointCloud World")
        vp = vis.getViewport()
        vp.w, vp.h = 800, 800
        vis.setViewport(vp)
        # vis.autoFitCamera()
        vis.show()

        vis.lock()
        vis.unlock()

        while vis.shown():
            time.sleep(0.01)
        vis.kill()
WAIT_TIME = 2

# Read hardcoded configurations from json file
PATH_DICTIONARY = {}
try:
    file = open(JSON_FILE, 'rw')
    PATH_DICTIONARY = json.load(file)
    file.close()
    MOVING_LIMB = PATH_DICTIONARY[JSON_PATHNAME][JSON_LIMB]
except:
    raise Exception('Path Dictionary failed to load')
# print PATH_DICTIONARY['CONFIG_1'][2][1][0]

## SETUP WORLD
print "-------------------- Creating World --------------------"
WORLD = robotsim.WorldModel()
# fn = MODEL_DIR+KLAMPT_MODEL
fn = RESOURCE_DIR + WORLD_MODEL
res = WORLD.readFile(fn)
if not res:
    print "Unable to read file", fn
    exit(0)
print "-------------------- World Successfully Created --------------------"
ROBOT = WORLD.robot(0)
SPACE = robotplanning.makeSpace(world=WORLD,
                                robot=ROBOT,
                                edgeCheckResolution=1e-3,
                                movingSubset='all')
"""
Merge two Dictionaries
"""
Ejemplo n.º 4
0
    def load_pcloud(self, save_file):
        """
        Converts a geometry to another type, if a conversion is available. The
        interpretation of param depends on the type of conversion, with 0
        being a reasonable default.
            Available conversions are:
                PointCloud -> TriangleMesh, if the point cloud is structured. param is the threshold
                                for splitting triangles by depth discontinuity, by default infinity.
        """

        long_np_cloud = np.fromfile(save_file)
        print(long_np_cloud.shape, ": shape of long numpy cloud")

        num_points = long_np_cloud.shape[0] / 3
        np_cloud = np.zeros(shape=(num_points, 3))
        pcloud = klampt.PointCloud()
        scaling_factor = 0.1
        points = []
        xs = []
        ys = []
        zs = []

        for x in range(num_points):
            i = x * 3
            x_val = long_np_cloud[i] * scaling_factor
            y_val = long_np_cloud[i + 1] * scaling_factor
            z_val = long_np_cloud[i + 2] * scaling_factor
            np_cloud[x][0] = x_val
            np_cloud[x][1] = y_val
            np_cloud[x][2] = z_val
            xs.append(x_val)
            ys.append(y_val)
            zs.append(z_val)
            points.append(np_cloud[x])

        points.sort(key=lambda tup: tup[2])

        x_sorted = sorted(xs)  # sorted
        y_sorted = sorted(ys)  # sorted
        z_sorted = sorted(zs)  # sorted

        xfit = stats.norm.pdf(x_sorted, np.mean(x_sorted), np.std(x_sorted))
        yfit = stats.norm.pdf(y_sorted, np.mean(y_sorted), np.std(y_sorted))
        zfit = stats.norm.pdf(z_sorted, np.mean(z_sorted), np.std(z_sorted))

        # plot with various axes scales
        plt.figure(1)

        # linear
        plt.subplot(221)
        plt.plot(x_sorted, xfit)
        plt.hist(x_sorted, normed=True)
        plt.title("X values")
        plt.grid(True)

        plt.subplot(222)
        plt.plot(y_sorted, yfit)
        plt.hist(y_sorted, normed=True)
        plt.title("Y values")
        plt.grid(True)

        plt.subplot(223)
        plt.plot(z_sorted, zfit)
        plt.hist(z_sorted, normed=True)
        plt.title("Z values")
        plt.grid(True)

        # Format the minor tick labels of the y-axis into empty strings with
        # `NullFormatter`, to avoid cumbering the axis with too many labels.
        plt.gca().yaxis.set_minor_formatter(NullFormatter())
        # Adjust the subplot layout, because the logit one may take more space
        # than usual, due to y-tick labels like "1 - 10^{-3}"
        plt.subplots_adjust(top=0.92,
                            bottom=0.08,
                            left=0.10,
                            right=0.95,
                            hspace=0.25,
                            wspace=0.35)

        # plt.show()

        median_z = np.median(zs)
        threshold = 0.25 * scaling_factor
        for point in points:
            if np.fabs(point[2] - median_z) < threshold:
                pcloud.addPoint(point)

        print(pcloud.numPoints(), ": num points")

        # Visualize
        pcloud.setSetting("width", "3")
        pcloud.setSetting("height", str(len(points) / 3))
        g3d_pcloud = Geometry3D(pcloud)
        mesh = g3d_pcloud.convert("TriangleMesh", 0)

        world = robotsim.WorldModel()
        vis.add("world", world)
        vis.add("coordinates", coordinates.manager())
        vis.setWindowTitle("PointCloud World")
        vp = vis.getViewport()
        vp.w, vp.h = 800, 800
        vis.setViewport(vp)
        vis.autoFitCamera()
        vis.show()

        vis.lock()
        vis.add("mesh", mesh)
        vis.unlock()

        while vis.shown():
            time.sleep(0.01)
        vis.kill()

        print("done")