Skip to content

Commit 2096483

Browse files
Hand_UR5 Update
Continued development into virtual simulation of UR5 control. Added Manus hand to the UR5 Model. Leaving some reduncancy fallback scripts for later use.
1 parent ddc7bf1 commit 2096483

File tree

10 files changed

+3985
-405
lines changed

10 files changed

+3985
-405
lines changed

Box_wall_test.unity

Lines changed: 3621 additions & 323 deletions
Large diffs are not rendered by default.

Manus Interfacing/Manus_interpreter.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ private Vector3 process_vector(vector_t vect)
319319
vec_out.x = (float)vect.x;
320320
vec_out.y = (float)vect.y;
321321
vec_out.z = (float)vect.z;
322+
if (vec_out.x == float.NaN)
323+
{
324+
vec_out = Vector3.zero;
325+
}
322326
return vec_out;
323327
}
324328

@@ -330,6 +334,13 @@ private Quaternion process_quat(quat_t quat)
330334
quat_out.y = (float)quat.y;
331335
quat_out.z = (float)quat.z;
332336
quat_out.w = (float)quat.w;
337+
if (quat_out.x == float.NaN)
338+
{
339+
quat_out.x = 0;
340+
quat_out.y = 0;
341+
quat_out.z = 0;
342+
quat_out.w = 0;
343+
}
333344
return quat_out;
334345
}
335346

Shadow_hand_manus.unity

Lines changed: 88 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ RenderSettings:
3838
m_ReflectionIntensity: 1
3939
m_CustomReflection: {fileID: 0}
4040
m_Sun: {fileID: 0}
41-
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
41+
m_IndirectSpecularColor: {r: 0.18028378, g: 0.22571412, b: 0.30692285, a: 1}
4242
--- !u!157 &3
4343
LightmapSettings:
4444
m_ObjectHideFlags: 0
@@ -113,86 +113,6 @@ NavMeshSettings:
113113
debug:
114114
m_Flags: 0
115115
m_NavMeshData: {fileID: 0}
116-
--- !u!1 &505459631
117-
GameObject:
118-
m_ObjectHideFlags: 0
119-
m_PrefabParentObject: {fileID: 0}
120-
m_PrefabInternal: {fileID: 0}
121-
serializedVersion: 5
122-
m_Component:
123-
- component: {fileID: 505459635}
124-
- component: {fileID: 505459634}
125-
- component: {fileID: 505459633}
126-
- component: {fileID: 505459632}
127-
m_Layer: 0
128-
m_Name: Main Camera
129-
m_TagString: MainCamera
130-
m_Icon: {fileID: 0}
131-
m_NavMeshLayer: 0
132-
m_StaticEditorFlags: 0
133-
m_IsActive: 1
134-
--- !u!81 &505459632
135-
AudioListener:
136-
m_ObjectHideFlags: 0
137-
m_PrefabParentObject: {fileID: 0}
138-
m_PrefabInternal: {fileID: 0}
139-
m_GameObject: {fileID: 505459631}
140-
m_Enabled: 1
141-
--- !u!124 &505459633
142-
Behaviour:
143-
m_ObjectHideFlags: 0
144-
m_PrefabParentObject: {fileID: 0}
145-
m_PrefabInternal: {fileID: 0}
146-
m_GameObject: {fileID: 505459631}
147-
m_Enabled: 1
148-
--- !u!20 &505459634
149-
Camera:
150-
m_ObjectHideFlags: 0
151-
m_PrefabParentObject: {fileID: 0}
152-
m_PrefabInternal: {fileID: 0}
153-
m_GameObject: {fileID: 505459631}
154-
m_Enabled: 1
155-
serializedVersion: 2
156-
m_ClearFlags: 1
157-
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
158-
m_NormalizedViewPortRect:
159-
serializedVersion: 2
160-
x: 0
161-
y: 0
162-
width: 1
163-
height: 1
164-
near clip plane: 0.3
165-
far clip plane: 1000
166-
field of view: 60
167-
orthographic: 0
168-
orthographic size: 5
169-
m_Depth: -1
170-
m_CullingMask:
171-
serializedVersion: 2
172-
m_Bits: 4294967295
173-
m_RenderingPath: -1
174-
m_TargetTexture: {fileID: 0}
175-
m_TargetDisplay: 0
176-
m_TargetEye: 3
177-
m_HDR: 1
178-
m_AllowMSAA: 1
179-
m_ForceIntoRT: 0
180-
m_OcclusionCulling: 1
181-
m_StereoConvergence: 10
182-
m_StereoSeparation: 0.022
183-
--- !u!4 &505459635
184-
Transform:
185-
m_ObjectHideFlags: 0
186-
m_PrefabParentObject: {fileID: 0}
187-
m_PrefabInternal: {fileID: 0}
188-
m_GameObject: {fileID: 505459631}
189-
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
190-
m_LocalPosition: {x: 0, y: 1, z: -10}
191-
m_LocalScale: {x: 1, y: 1, z: 1}
192-
m_Children: []
193-
m_Father: {fileID: 0}
194-
m_RootOrder: 0
195-
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
196116
--- !u!1 &958011566
197117
GameObject:
198118
m_ObjectHideFlags: 0
@@ -256,5 +176,91 @@ Transform:
256176
m_LocalScale: {x: 1, y: 1, z: 1}
257177
m_Children: []
258178
m_Father: {fileID: 0}
259-
m_RootOrder: 1
179+
m_RootOrder: 0
260180
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
181+
--- !u!1 &1498021665
182+
GameObject:
183+
m_ObjectHideFlags: 0
184+
m_PrefabParentObject: {fileID: 0}
185+
m_PrefabInternal: {fileID: 0}
186+
serializedVersion: 5
187+
m_Component:
188+
- component: {fileID: 1498021669}
189+
- component: {fileID: 1498021668}
190+
- component: {fileID: 1498021667}
191+
- component: {fileID: 1498021666}
192+
m_Layer: 0
193+
m_Name: Plane
194+
m_TagString: Untagged
195+
m_Icon: {fileID: 0}
196+
m_NavMeshLayer: 0
197+
m_StaticEditorFlags: 0
198+
m_IsActive: 1
199+
--- !u!23 &1498021666
200+
MeshRenderer:
201+
m_ObjectHideFlags: 0
202+
m_PrefabParentObject: {fileID: 0}
203+
m_PrefabInternal: {fileID: 0}
204+
m_GameObject: {fileID: 1498021665}
205+
m_Enabled: 1
206+
m_CastShadows: 1
207+
m_ReceiveShadows: 1
208+
m_DynamicOccludee: 1
209+
m_MotionVectors: 1
210+
m_LightProbeUsage: 1
211+
m_ReflectionProbeUsage: 1
212+
m_Materials:
213+
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
214+
m_StaticBatchInfo:
215+
firstSubMesh: 0
216+
subMeshCount: 0
217+
m_StaticBatchRoot: {fileID: 0}
218+
m_ProbeAnchor: {fileID: 0}
219+
m_LightProbeVolumeOverride: {fileID: 0}
220+
m_ScaleInLightmap: 1
221+
m_PreserveUVs: 1
222+
m_IgnoreNormalsForChartDetection: 0
223+
m_ImportantGI: 0
224+
m_StitchLightmapSeams: 0
225+
m_SelectedEditorRenderState: 3
226+
m_MinimumChartSize: 4
227+
m_AutoUVMaxDistance: 0.5
228+
m_AutoUVMaxAngle: 89
229+
m_LightmapParameters: {fileID: 0}
230+
m_SortingLayerID: 0
231+
m_SortingLayer: 0
232+
m_SortingOrder: 0
233+
--- !u!64 &1498021667
234+
MeshCollider:
235+
m_ObjectHideFlags: 0
236+
m_PrefabParentObject: {fileID: 0}
237+
m_PrefabInternal: {fileID: 0}
238+
m_GameObject: {fileID: 1498021665}
239+
m_Material: {fileID: 0}
240+
m_IsTrigger: 0
241+
m_Enabled: 1
242+
serializedVersion: 2
243+
m_Convex: 0
244+
m_InflateMesh: 0
245+
m_SkinWidth: 0.01
246+
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
247+
--- !u!33 &1498021668
248+
MeshFilter:
249+
m_ObjectHideFlags: 0
250+
m_PrefabParentObject: {fileID: 0}
251+
m_PrefabInternal: {fileID: 0}
252+
m_GameObject: {fileID: 1498021665}
253+
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
254+
--- !u!4 &1498021669
255+
Transform:
256+
m_ObjectHideFlags: 0
257+
m_PrefabParentObject: {fileID: 0}
258+
m_PrefabInternal: {fileID: 0}
259+
m_GameObject: {fileID: 1498021665}
260+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
261+
m_LocalPosition: {x: -7.5793, y: 3.3931599, z: -4.6269}
262+
m_LocalScale: {x: 1.9506115, y: 1, z: 2.3604095}
263+
m_Children: []
264+
m_Father: {fileID: 0}
265+
m_RootOrder: 1
266+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/*Code from https://forum.unity.com/threads/raycast-without-colliders.14378/
2+
*
3+
*
4+
*
5+
*
6+
*/
7+
8+
9+
10+
using System.Collections;
11+
using System.Collections.Generic;
12+
using UnityEngine;
13+
14+
public class Dynamic_Mesh_Collider : MonoBehaviour {
15+
class CVertexWeight
16+
{
17+
public int index;
18+
public Vector3 localPosition;
19+
public float weight;
20+
21+
public CVertexWeight(int i, Vector3 p, float w)
22+
{
23+
index = i;
24+
localPosition = p;
25+
weight = w;
26+
}
27+
}
28+
29+
class CWeightList
30+
{
31+
public Transform transform;
32+
public ArrayList weights;
33+
public CWeightList()
34+
{
35+
weights = new ArrayList();
36+
}
37+
}
38+
39+
public bool forceUpdate;
40+
public bool updateOncePerFrame = true;
41+
42+
private CWeightList[] nodeWeights; // one per node
43+
44+
private SkinnedMeshRenderer skinnedMeshRenderer;
45+
private MeshCollider meshCollider;
46+
47+
48+
/// <summary>
49+
/// This basically translates the information about the skinned mesh into
50+
/// data that we can internally use to quickly update the collision mesh.
51+
/// </summary>
52+
void Start()
53+
{
54+
skinnedMeshRenderer = GetComponent<SkinnedMeshRenderer>();
55+
meshCollider = GetComponent<MeshCollider>();
56+
57+
if (meshCollider != null && skinnedMeshRenderer != null)
58+
{
59+
// Cache used values rather than accessing straight from the mesh on the loop below
60+
Vector3[] cachedVertices = skinnedMeshRenderer.sharedMesh.vertices;
61+
Matrix4x4[] cachedBindposes = skinnedMeshRenderer.sharedMesh.bindposes;
62+
BoneWeight[] cachedBoneWeights = skinnedMeshRenderer.sharedMesh.boneWeights;
63+
64+
// Make a CWeightList for each bone in the skinned mesh
65+
nodeWeights = new CWeightList[skinnedMeshRenderer.bones.Length];
66+
for (int i = 0; i < skinnedMeshRenderer.bones.Length; i++)
67+
{
68+
nodeWeights[i] = new CWeightList();
69+
nodeWeights[i].transform = skinnedMeshRenderer.bones[i];
70+
}
71+
72+
// Create a bone weight list for each bone, ready for quick calculation during an update...
73+
for (int i = 0; i < cachedVertices.Length; i++)
74+
{
75+
BoneWeight bw = cachedBoneWeights[i];
76+
if (bw.weight0 != 0.0f)
77+
{
78+
Vector3 localPt = cachedBindposes[bw.boneIndex0].MultiplyPoint3x4(cachedVertices[i]);
79+
nodeWeights[bw.boneIndex0].weights.Add(new CVertexWeight(i, localPt, bw.weight0));
80+
}
81+
if (bw.weight1 != 0.0f)
82+
{
83+
Vector3 localPt = cachedBindposes[bw.boneIndex1].MultiplyPoint3x4(cachedVertices[i]);
84+
nodeWeights[bw.boneIndex1].weights.Add(new CVertexWeight(i, localPt, bw.weight1));
85+
}
86+
if (bw.weight2 != 0.0f)
87+
{
88+
Vector3 localPt = cachedBindposes[bw.boneIndex2].MultiplyPoint3x4(cachedVertices[i]);
89+
nodeWeights[bw.boneIndex2].weights.Add(new CVertexWeight(i, localPt, bw.weight2));
90+
}
91+
if (bw.weight3 != 0.0f)
92+
{
93+
Vector3 localPt = cachedBindposes[bw.boneIndex3].MultiplyPoint3x4(cachedVertices[i]);
94+
nodeWeights[bw.boneIndex3].weights.Add(new CVertexWeight(i, localPt, bw.weight3));
95+
}
96+
}
97+
98+
UpdateCollisionMesh();
99+
}
100+
else
101+
{
102+
Debug.LogError("[SkinnedCollisionHelper] " + gameObject.name + " is missing SkinnedMeshRenderer or MeshCollider!");
103+
}
104+
105+
}
106+
107+
/// <summary>
108+
/// Manually recalculates the collision mesh of the skinned mesh on this object.
109+
/// </summary>
110+
public void UpdateCollisionMesh()
111+
{
112+
Mesh mesh = new Mesh();
113+
114+
Vector3[] newVert = new Vector3[skinnedMeshRenderer.sharedMesh.vertices.Length];
115+
116+
// Now get the local positions of all weighted indices...
117+
foreach (CWeightList wList in nodeWeights)
118+
{
119+
foreach (CVertexWeight vw in wList.weights)
120+
{
121+
newVert[vw.index] += wList.transform.localToWorldMatrix.MultiplyPoint3x4(vw.localPosition) * vw.weight;
122+
}
123+
}
124+
125+
// Now convert each point into local coordinates of this object.
126+
for (int i = 0; i < newVert.Length; i++)
127+
{
128+
newVert[i] = transform.InverseTransformPoint(newVert[i]);
129+
}
130+
131+
// Update the mesh ( collider) with the updated vertices
132+
mesh.vertices = newVert;
133+
mesh.uv = skinnedMeshRenderer.sharedMesh.uv; // is this even needed here?
134+
mesh.triangles = skinnedMeshRenderer.sharedMesh.triangles;
135+
mesh.RecalculateBounds();
136+
mesh.MarkDynamic(); // says it should improve performance, but I couldn't see it happening
137+
meshCollider.sharedMesh = mesh;
138+
}
139+
140+
/// <summary>
141+
/// If the 'forceUpdate' flag is set, updates the collision mesh for the skinned mesh on this object
142+
/// </summary>
143+
void Update()
144+
{
145+
if (forceUpdate)
146+
{
147+
if (updateOncePerFrame) forceUpdate = false;
148+
UpdateCollisionMesh();
149+
}
150+
}
151+
}

Utillity Scripts/Dynamic_Mesh_Collider.cs.meta

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Utillity Scripts/Manus_hand_model_inputter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using manus_interface;
2020

2121

22+
2223
public class Manus_hand_model_inputter : MonoBehaviour
2324
{
2425
[SerializeField]

0 commit comments

Comments
 (0)