Skip to content

Commit 4f11f0b

Browse files
committed
Added Lab3 files
1 parent aa5fb15 commit 4f11f0b

File tree

11 files changed

+538
-551
lines changed

11 files changed

+538
-551
lines changed

data/prm_graph.pickle

-37.2 KB
Binary file not shown.

data/prm_node.pickle

-10.4 KB
Binary file not shown.

data/urdfinfo.npz

0 Bytes
Binary file not shown.

external/dynamixel-workbench/dynamixel_workbench_controllers/src/position_control.cpp

Lines changed: 411 additions & 463 deletions
Large diffs are not rendered by default.

launch/camera_calibration.launch

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<launch>
22
<include file="position_control.launch"/>
3-
<include file="$(find realsense2_camera)/launch/rs_camera.launch"/>
3+
<include file="$(find realsense2_camera)/launch/rs_camera.launch">
4+
<arg name="enable_pointcloud" value="true"/>
5+
</include>
46
<include file="$(find ar_track_alvar)/launch/locobot_indiv_image.launch"/>
7+
<node type="rviz" name="rviz" pkg="rviz">
8+
</node>
59
</launch>

launch/load_urdf.launch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
<param
1111
name="use_gui"
1212
value="$(arg gui)" />
13-
<node
13+
<!--node
1414
name="joint_state_publisher"
1515
pkg="joint_state_publisher"
16-
type="joint_state_publisher" />
16+
type="joint_state_publisher" /-->
1717
<node
1818
name="robot_state_publisher"
1919
pkg="robot_state_publisher"

scripts/PRM.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import numpy as np
2-
import forward_kinematics as fk
2+
import forward_kinematics_extrinsics as fk
33
import collision_checking as cc
44
from collections import defaultdict
55
import time
@@ -60,12 +60,12 @@ def __init__(self, obstacles_cuboids):
6060
self.constraint = np.tile(np.array([-179,180])[:,np.newaxis],(1,DOF))
6161

6262
self.obstacles_cuboids = obstacles_cuboids
63-
ground_plane = np.array([[[-0.0896, 0.0004, 0.114],[0, 0, 0],[2.0, 2.0, 0.01]]])
63+
ground_plane = np.array([[[0.0, 0.000, -0.10],[0, 0, 0],[2.0, 2.0, 0.01]]])
6464
self.obstacles_cuboids = np.append(self.obstacles_cuboids, ground_plane, axis=0)
6565

6666
self.map = Graph()
67-
self.forward_kinematics = fk.forwardKinematics()
68-
self.anim = plotter.Plot()
67+
self.forward_kinematics = fk.forwardKinematics( base_link='bottom_plate', end_link='gripper_link')
68+
# self.anim = plotter.Plot()
6969

7070
# Set constraint on the joint angles
7171
def setConstraint(self,constraint_low, constraint_high):
@@ -91,7 +91,7 @@ def checkConstraint(self, state):
9191

9292
# sample a node and add in the graph if its in Cfree
9393
def sampleNode(self):
94-
#self.anim.clearPlot()
94+
# self.anim.clearPlot()
9595
samples = np.zeros((1,DOF))
9696

9797
# Generate Sample within Constraints
@@ -127,16 +127,17 @@ def findKNearestNeighbours(self, new_node, K):
127127
# Check if the sample is in collision with obstacles
128128
def checkPointCollision(self, sample):
129129
deg_to_rad = np.pi/180.
130-
130+
131+
np.insert(sample, 0, 0, axis=1)
131132
# Find arm cuboids properties in the current state
132133
arm_cuboids = self.forward_kinematics.getRotatedCuboid(deg_to_rad*sample)
133-
#self.Animation(arm_cuboids)
134+
# self.Animation(arm_cuboids)
134135

135136

136137
for i in range(arm_cuboids.shape[0]):
137138
for j in range(self.obstacles_cuboids.shape[0]):
138139
collision = cc.collisionChecking(arm_cuboids[i,:,:], self.obstacles_cuboids[j,:,:])
139-
#print('arm', i, 'obstacle', j, collision)
140+
# print('arm', i, 'obstacle', j, collision)
140141

141142
# If even one of the cuboids is in collsion, return true
142143
if collision is True:
@@ -157,7 +158,7 @@ def Animation(self, arm_cuboids):
157158
box = cc.Cuboid(self.obstacles_cuboids[i])
158159
self.anim.plotCuboid(box.getCorners(), i)
159160

160-
self.anim.showPlot(0.1)
161+
self.anim.showPlot(10)
161162

162163
# Check if there are obstacles between new_node and its nearest neighbour
163164
def checkLineCollision(self, new_node, nearest_node):
@@ -173,6 +174,8 @@ def checkLineCollision(self, new_node, nearest_node):
173174
diff = self.map.nodes[nearest_node[i,0]] - new_node.state
174175
# Find out the max angle difference and calculate the number of steps to move
175176
steps = math.ceil(abs(diff).max()/discrete_factor)
177+
if steps == 0.0:
178+
continue
176179

177180
for j in range(int(steps)+1):
178181
# Find the angles for the jth step
@@ -197,7 +200,7 @@ def makeGraph(self, sim_time):
197200
K = 5
198201

199202
constraint = np.ones((2,5))
200-
prm.setConstraint(-90*constraint[0,:],90*constraint[1,:])
203+
self.setConstraint(-90*constraint[0,:],90*constraint[1,:])
201204

202205
start_time = time.time()
203206

@@ -209,7 +212,7 @@ def makeGraph(self, sim_time):
209212
self.checkLineCollision(new_node, nearest_node)
210213

211214
print(len(self.map.nodes))
212-
print(self.map.adj_list)
215+
#print(self.map.adj_list)
213216
print('Graph Successfully Built')
214217

215218
# Save graph for future use
@@ -328,8 +331,9 @@ def loadGraph(self):
328331
print('Inside PRM Class')
329332

330333
#obstacles_cuboids = np.load('../data/obstacle_cuboid.npy')
331-
obstacles_cuboids = np.array([[[0.0604, 0.1854, 0.214], [0, 0, 0], [0.1, 0.125, 0.225]], \
332-
[[0.0604, 0.1854, 0.349], [0, 0, 0], [0.125, 0.225, 0.1]]])
334+
obstacles_cuboids = np.array([[[-0.12, 0, 0.1025], [0, 0, 0], [0.08, 0.19, 0.205]],
335+
[[-0.11, 0, 0.305], [0, 0, 0], [0.07, 0.19, 0.20]],
336+
[[-0.06, 0.0, 0.455], [0, 0, 0], [0.1, 0.15, 0.1]]])
333337
prm = ProbabilisticRoadMap(obstacles_cuboids)
334338
# prm.makeGraph(120.0)
335339

scripts/collision_checking.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import numpy as np
22
from sklearn.preprocessing import normalize
3-
import forward_kinematics as fk
3+
import forward_kinematics_extrinsics as fk
44

55
# Cuboid Class for creating cuboids from Origin, Orientation and Dimension
66
class Cuboid:

scripts/forward_kinematics_extrinsics.py

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ def __init__(self, base_link='bottom_plate', end_link='ar_tag', \
1111

1212
self.axis = None
1313
self.position = None
14-
# arm_cuboid_properties = np.load('../data/arm_cuboid_properties.npz')
15-
# self.arm_cuboid_origin = arm_cuboid_properties[arm_cuboid_properties.files[0]]
16-
# self.dimension = arm_cuboid_properties[arm_cuboid_properties.files[1]]
14+
arm_cuboid_properties = np.load('../data/arm_cuboid_properties.npz')
15+
self.arm_cuboid_origin = arm_cuboid_properties[arm_cuboid_properties.files[0]]
16+
self.dimension = arm_cuboid_properties[arm_cuboid_properties.files[1]]
17+
print(self.dimension)
1718
robot = URDF.from_xml_file(path)
1819
self.urdfParser(robot, base_link, end_link)
1920
self.loadURDFinfo()
@@ -54,32 +55,32 @@ def getJointForwardKinematics(self, joint_angles):
5455
return H
5556

5657
# Returns the Origin, Orientation and Dimension of the collision cuboids around the robot arm links
57-
# def getRotatedCuboid(self, joint_angles):
58-
# H = self.getJointForwardKinematics(joint_angles)
59-
# cuboid = np.zeros((7,3,3))
58+
def getRotatedCuboid(self, joint_angles):
59+
H = self.getJointForwardKinematics(joint_angles)
60+
cuboid = np.zeros((7,3,3))
6061

61-
# # Cuboid information for links 1 to 5 which are connected to revolute joints
62-
# for i in range(H.shape[0]):
63-
# # Origin of the cuboid (x,y,z)
64-
# cuboid[i,0,:] = np.matmul(H[i,:,:],self.arm_cuboid_origin[i,:].T)[0:3]
62+
# Cuboid information for links 1 to 5 which are connected to revolute joints
63+
for i in range(H.shape[0]-1):
64+
# Origin of the cuboid (x,y,z)
65+
cuboid[i,0,:] = np.matmul(H[i+1,:,:],self.arm_cuboid_origin[i,:].T)[0:3]
6566

66-
# # Rotation angles of the cuboid (roll, pitch, yaw)
67-
# cuboid[i,1,:] = self.getEulerAngles(H[i,0:3,0:3])
67+
# Rotation angles of the cuboid (roll, pitch, yaw)
68+
cuboid[i,1,:] = self.getEulerAngles(H[i+1,0:3,0:3])
6869

69-
# # Dimension of the cuboid along (x,y,z)
70-
# cuboid[i,2,:] = self.dimension[i,:]
70+
# Dimension of the cuboid along (x,y,z)
71+
cuboid[i,2,:] = self.dimension[i,:]
7172

72-
# # Cuboid information for the first finger
73-
# cuboid[5,0,:] = np.matmul(H[4,:,:],self.arm_cuboid_origin[5,:].T)[0:3]
74-
# cuboid[5,1,:] = self.getEulerAngles(H[4,0:3,0:3])
75-
# cuboid[5,2,:] = self.dimension[5,:]
73+
# Cuboid information for the first finger
74+
cuboid[i+1,0,:] = np.matmul(H[i+1,:,:],self.arm_cuboid_origin[i+1,:].T)[0:3]
75+
cuboid[i+1,1,:] = self.getEulerAngles(H[i+1,0:3,0:3])
76+
cuboid[i+1,2,:] = self.dimension[i+1,:]
7677

77-
# # Cuboid information for the second finger
78-
# cuboid[6,0,:] = np.matmul(H[4,:,:],self.arm_cuboid_origin[6,:].T)[0:3]
79-
# cuboid[6,1,:] = self.getEulerAngles(H[4,0:3,0:3])
80-
# cuboid[6,2,:] = self.dimension[6,:]
78+
# Cuboid information for the second finger
79+
cuboid[i+2,0,:] = np.matmul(H[i+1,:,:],self.arm_cuboid_origin[i+2,:].T)[0:3]
80+
cuboid[i+2,1,:] = self.getEulerAngles(H[i+1,0:3,0:3])
81+
cuboid[i+2,2,:] = self.dimension[i+2,:]
8182

82-
# return(cuboid)
83+
return(cuboid)
8384

8485
# Checks if a matrix is a valid rotation matrix.
8586
@staticmethod
@@ -143,8 +144,10 @@ def loadURDFinfo(self):
143144
# joint_angles = calibration_info[calibration_info.files[3]][0].reshape((1,5))
144145
# fk = forwardKinematics()
145146
# M = fk.getJointForwardKinematics(joint_angles)
146-
X = np.array([[0., 90., 0., -90., 90., 0., 0.]])
147-
fk = forwardKinematics()
147+
X = np.array([[0., 0., 60., 0., 0., 0.]])
148+
fk = forwardKinematics(base_link='bottom_plate', end_link='gripper_link')
148149
M = fk.getJointForwardKinematics(X*np.pi/180)
149-
for i in range(M.shape[0]):
150-
print(np.matmul(np.linalg.inv(M[0,:,:]),M[i,:,:]))
150+
print(M)
151+
# for i in range(M.shape[0]):
152+
# print(np.matmul(np.linalg.inv(M[0,:,:]),M[i,:,:]))
153+
print(fk.getRotatedCuboid(X))

0 commit comments

Comments
 (0)