Skip to content

Commit 6625744

Browse files
Update on Friday Week 4
1 parent 4edf55b commit 6625744

File tree

9 files changed

+3215
-729
lines changed

9 files changed

+3215
-729
lines changed

Box_wall_test.unity

Lines changed: 201 additions & 682 deletions
Large diffs are not rendered by default.

Camera_Manus_Rig.prefab

Lines changed: 2770 additions & 0 deletions
Large diffs are not rendered by default.

Camera_Manus_Rig.prefab.meta

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

Manus Interfacing/Manus_interpreter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
///////////////////////////////////////////////////////////////////////////////
22
//
3-
// Original System: Manus_interpreter.h.cpp
3+
// Original System: Manus_interpreter.cs
44
// Subsystem: Human-Robot Interaction
55
// Workfile: Manus_interpreter.cs
66
// Revision: 1.1 - 6/11/2018
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
//
3+
// Original System: Camera_controls.cs
4+
// Subsystem: Human-Robot Interaction
5+
// Workfile: Manus_Open_VR V2
6+
// Revision: 1.0 - 6/22/2018
7+
// Author: Esteban Segarra
8+
//
9+
// Description
10+
// ===========
11+
// Camera control wrapper for object in control.
12+
//
13+
///////////////////////////////////////////////////////////////////////////////
14+
//Some Code inherited from https://forum.unity.com/threads/moving-main-camera-with-mouse.119525/
15+
using UnityEngine;
16+
17+
public class Camera_controls : MonoBehaviour {
18+
//Limits for camera
19+
private float x_cam_rot_up = 90;
20+
private float y_cam_rot_up = 90;
21+
private float z_cam_rot_up = 90;
22+
private float x_cam_rot_down = -90;
23+
private float y_cam_rot_down = -90;
24+
private float z_cam_rot_down = -90;
25+
26+
//Speed Limits
27+
public float horizontal_speed = 40;
28+
public float vertical_speed = 40;
29+
public float foward_speed = 40;
30+
public float back_speed = 40;
31+
32+
// Update is called once per frame
33+
void Update () {
34+
Vector3 shift;
35+
while (Input.GetMouseButtonDown(1))
36+
{
37+
float hor = horizontal_speed * Input.GetAxis("Mouse Y");
38+
float ver = vertical_speed * Input.GetAxis("Mouse X");
39+
transform.Translate(ver, hor, 0);
40+
}
41+
42+
if( Input.GetKeyDown("Foward"))
43+
{
44+
shift = new Vector3(foward_speed, 0, 0);
45+
Debug.Log("FOWARD YO");
46+
this.transform.Translate(shift);
47+
}
48+
49+
if (Input.GetKeyDown("Back"))
50+
{
51+
shift = new Vector3(back_speed, 0, 0);
52+
this.transform.Translate(shift);
53+
}
54+
55+
if (Input.GetKeyDown("Left"))
56+
{
57+
shift = new Vector3(0, horizontal_speed, 0);
58+
this.transform.Translate( shift);
59+
}
60+
61+
if (Input.GetKeyDown("Right"))
62+
{
63+
shift = new Vector3(0, -horizontal_speed, 0);
64+
this.transform.Translate(shift);
65+
}
66+
67+
}
68+
}

Utillity Scripts/Camera_controls.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/Modify_my_slider.cs

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -37,52 +37,6 @@ void Update () {
3737
z4 = (float)hand_compression_ratios[0]; //Pinky
3838
z5 = (float)hand_compression_ratios[8]; //Thumb
3939

40-
{
41-
/*a
42-
if (z1 > 1)
43-
{
44-
z1 = 1;
45-
}
46-
if (z2 > 1)
47-
{
48-
z2 = 1;
49-
}
50-
if (z3 > 1)
51-
{
52-
z3 = 1;
53-
}
54-
if (z4 > 1)
55-
{
56-
z4 = 1;
57-
}
58-
if (z5 > 1)
59-
{
60-
z5 = 1;
61-
}
62-
if (z1 < 0)
63-
{
64-
z1 = 0;
65-
}
66-
if (z2 < 0)
67-
{
68-
z2 = 0;
69-
}
70-
if (z3 < 0)
71-
{
72-
z3 = 0;
73-
}
74-
if (z4 < 0)
75-
{
76-
z4 = 0;
77-
}
78-
if (z5 < 0)
79-
{
80-
z5 = 0;
81-
}
82-
*/
83-
}
84-
85-
8640
//Slider Overrides
8741
sliders_on_gameObj[0].value = z5 * 111F - 85.0F; //Rotate the base
8842
sliders_on_gameObj[1].value = z1 * 350.0F - 175.0F; //Move the second arm

Utillity Scripts/TouchControl.cs

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/////////////////////////////////////////////////////////////////////////////
2+
//
3+
// Original System: TouchControl.cs
4+
// Subsystem: Human-Robot Interaction
5+
// Workfile: Manus_interpreter.cs
6+
// Revision: 1.1 - 6/21/2018
7+
// Author: Shelly Bagachi/ Edits made: Esteban Segarra
8+
//
9+
// Description
10+
// ===========
11+
// Touchscreen and mouse controls for UR5 robot control.
12+
//
13+
///////////////////////////////////////////////////////////////////////////////
14+
using System.Collections;
15+
using System.Collections.Generic;
16+
using UnityEngine;
17+
18+
//From http://answers.unity3d.com/questions/610440/on-touch-event-on-game-object-on-android-2d.html
19+
20+
public class TouchControl : MonoBehaviour {
21+
//private GameObject thisObj;
22+
private RuntimePlatform platform = Application.platform;
23+
public float speed_touch = 0.01f;
24+
public float speed_mouse = 10f;
25+
26+
Ray cursorRay;
27+
RaycastHit hit;
28+
29+
//public bool did_get_hit;
30+
public bool did_feel_hit;
31+
bool was_prev_clicked = false;
32+
bool first_click = true;
33+
public bool newHit = false;
34+
public Vector2 touchPosition = Vector2.zero;
35+
public Vector2 touchDeltaPosition = Vector2.zero;
36+
public Vector2 currentMousePosition = Vector2.zero;
37+
public Vector2 lastMousePosition = Vector2.zero;
38+
public Vector2 mouseDeltaPosition = Vector2.zero;
39+
40+
// Use this for initialization
41+
void Start () {
42+
cursorRay = Camera.main.ScreenPointToRay(Vector3.zero);
43+
}
44+
45+
// Update is called once per frame
46+
void Update () {
47+
if (platform == RuntimePlatform.Android || platform == RuntimePlatform.IPhonePlayer)
48+
{
49+
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved)
50+
{
51+
touchPosition = Input.GetTouch(0).position;
52+
cursorRay = Camera.main.ScreenPointToRay(touchPosition);
53+
touchDeltaPosition = Input.GetTouch(0).deltaPosition;
54+
}
55+
}
56+
else if (platform == RuntimePlatform.WindowsEditor)
57+
{
58+
newHit = false;
59+
if (!Input.GetMouseButton(0) && was_prev_clicked)
60+
{
61+
currentMousePosition = Input.mousePosition;
62+
was_prev_clicked = false;
63+
first_click = true;
64+
mouseDeltaPosition = currentMousePosition - lastMousePosition;
65+
Vector3 pos_cam = new Vector3(currentMousePosition.x, currentMousePosition.y, 0);
66+
cursorRay = Camera.main.ScreenPointToRay(pos_cam);
67+
newHit = true;
68+
}
69+
70+
if (Input.GetMouseButton(0) && first_click)
71+
{
72+
lastMousePosition = Input.mousePosition;
73+
was_prev_clicked = true;
74+
first_click = false;
75+
currentMousePosition = new Vector3();
76+
}
77+
78+
else if (Input.GetMouseButton(0))
79+
{
80+
was_prev_clicked = true;
81+
}
82+
83+
84+
}
85+
86+
Debug.DrawLine(currentMousePosition, lastMousePosition);
87+
if (Physics.Raycast(cursorRay, out hit, 1000.0f))
88+
{
89+
//Debug.DrawLine(cursorRay.origin, hit.point);
90+
if (hit.collider.gameObject.name == this.name)
91+
{
92+
{
93+
if (newHit)
94+
Debug.Log("Hit detected on object " + hit.collider.gameObject.name + " at point " + hit.point);
95+
var pos = gameObject.transform.position;
96+
97+
Debug.Log(gameObject.transform.position.ToString());
98+
99+
if (platform == RuntimePlatform.Android || platform == RuntimePlatform.IPhonePlayer)
100+
{
101+
//float d = Mathf.Sqrt(touchDeltaPosition.x*touchDeltaPosition.x + touchDeltaPosition.y*touchDeltaPosition.y);
102+
//Debug.Log(d);
103+
//pos.z += touchDeltaPosition.magnitude * Mathf.Sign(touchDeltaPosition.x) * speed_touch;
104+
pos.x += touchDeltaPosition.x * speed_touch;
105+
pos.y += touchDeltaPosition.y * speed_touch;
106+
107+
}
108+
else if (platform == RuntimePlatform.WindowsEditor)
109+
{
110+
//currentRotation.z += Input.GetAxis("Mouse X") * speed_mouse * 40.0f; //got x40 factor from SE...??
111+
//pos.z += mouseDeltaPosition.magnitude * Mathf.Sign(mouseDeltaPosition.x) * speed_mouse;
112+
pos.x += mouseDeltaPosition.x * speed_mouse;
113+
pos.y += mouseDeltaPosition.y * speed_mouse;
114+
}
115+
Debug.Log(pos.ToString());
116+
gameObject.transform.position = pos;
117+
}
118+
}
119+
}
120+
}
121+
122+
123+
//Check where my camera is
124+
void checkTouch(Vector2 pos)
125+
{
126+
Vector3 wp = Camera.main.ScreenToWorldPoint(pos);
127+
Vector2 touchPos = new Vector2(wp.x, wp.y);
128+
Collider2D hit = Physics2D.OverlapPoint(touchPos);
129+
//did_get_hit = hit;
130+
if (hit)
131+
{
132+
if (hit.transform.gameObject.name == name)
133+
{
134+
Debug.Log(name);
135+
hit.transform.gameObject.SendMessage("Clicked", 0, SendMessageOptions.DontRequireReceiver);
136+
}
137+
}
138+
}
139+
}

Utillity Scripts/TouchControl.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.

0 commit comments

Comments
 (0)