Added some things

This commit is contained in:
Keenan D. Buckley
2019-02-15 16:46:19 -07:00
parent b68ece8fd3
commit 0b0347cdaa
117 changed files with 137930 additions and 7379 deletions
@@ -0,0 +1,31 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class cameraControl : MonoBehaviour
{
public bool nyah = false;
public bool negNyah = false;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKey("left"))
{
transform.Rotate(Vector3.up, -200 * Time.deltaTime);
nyah = true;
negNyah = false;
}
if (Input.GetKey("right"))
{
transform.Rotate(Vector3.up, 200 * Time.deltaTime);
negNyah = true;
nyah = false;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 65b6b77e8469e104abfc7201dd384683
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Net;
using System.Net.Sockets;
@@ -9,33 +10,34 @@ using UnityEngine;
public class robotCommunication : MonoBehaviour
{
public bool isData = false;
public static int portNumber = 4388;
public int bytesAvailable;
List<string> keys = new List<string>();
public SortedList<string, float> robotValues =
new SortedList<string, float>
{
{ "Left Pos Inches", 0.0f },
{ "Yaw Angle Deg", 0.0f },
{ "Right Pos Inches", 0.0f },
{ "Elevator Pos Ticks", 0.0f },
{ "Pitch", 0.0f },
{ "Roll", 0.0f },
{ "Yaw", 0.0f },
{ "Distance", 0.0f },
};
public static int portNumber = 4388;
public int bytesAvailable;
List<string> keys = new List<string>();
public float encoder, navX;
public string input, request = "";
IPEndPoint serverAddress = new IPEndPoint(IPAddress.Parse("127.0.0.1"), portNumber);
Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
Socket serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
Socket clientSocket;
short currentIndex;
float currentValue;
public float latency;
// Start is called before the first frame update
void Start()
{
clientSocket.Connect(serverAddress);
startRobopipe();
serverSocket.Bind(serverAddress);
serverSocket.Listen(10);
clientSocket = serverSocket.Accept();
foreach (var valuePair in robotValues)
{
request += valuePair.Key;
@@ -50,6 +52,7 @@ public class robotCommunication : MonoBehaviour
// Update is called once per frame
void Update()
{
latency = Time.deltaTime * 1000;
bytesAvailable = clientSocket.Available;
if (bytesAvailable > 10)
{
@@ -63,8 +66,20 @@ public class robotCommunication : MonoBehaviour
robotValues[keys[i]] = float.Parse(values[i], CultureInfo.InvariantCulture.NumberFormat);
i++;
}
clientSocket.Send(new byte[] { 100 });
isData = true;
clientSocket.Send(Encoding.UTF8.GetBytes("CONT"));
}
}
private void OnApplicationQuit()
{
clientSocket.Send(Encoding.UTF8.GetBytes("EXIT"));
}
private void startRobopipe()
{
Process foo = new Process();
foo.StartInfo.FileName = "Robopipe.jar";
foo.StartInfo.Arguments = "" + portNumber;
foo.Start();
}
}
@@ -28,7 +28,7 @@ public class robotControl : MonoBehaviour
roboCom.robotValues.TryGetValue("Yaw Angle Deg", out yRot);
roboCom.robotValues.TryGetValue("Left Pos Inches", out leftEncoder);
roboCom.robotValues.TryGetValue("Right Pos Inches", out rightEncoder);
if (!start && roboCom.isData)
/*if (!start && roboCom.isData)
{
avgEncoder = (leftEncoder + rightEncoder) / 2;
lastEncoder = avgEncoder;
@@ -46,6 +46,6 @@ public class robotControl : MonoBehaviour
transform.rotation = Quaternion.Euler(rot);
transform.position = pos;
lastEncoder = avgEncoder;
}
}*/
}
}
@@ -0,0 +1,42 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class robotNavXControl : MonoBehaviour
{
public float distance, lastDistance;
public Vector3 vel, acc, initRot, rot, otherRot;
public int button;
robotCommunication roboCom;
bool start = false;
// Start is called before the first frame update
void Start()
{
GameObject Robot = GameObject.Find("Robot");
roboCom = Robot.GetComponent<robotCommunication>();
vel = new Vector3(0, 0, 0);
rot = new Vector3(0.0f, 0.0f, 0.0f);
transform.position = new Vector3(0, 0, 0);
}
// Update is called once per frame
void Update()
{
float x = 0, y = 0, z = 0;
roboCom.robotValues.TryGetValue("Pitch", out rot.x);
roboCom.robotValues.TryGetValue("Yaw", out rot.y);
roboCom.robotValues.TryGetValue("Roll", out rot.z);
roboCom.robotValues.TryGetValue("Distance", out distance);
rot.x *= -1;
rot.z *= -1;
//Angle
//rot -= initRot;
Vector3 finalRot = new Vector3(0, 0, 0);
finalRot.y = rot.y - initRot.y;
transform.rotation = Quaternion.Euler(finalRot);
//Position
transform.position += transform.forward * (distance - lastDistance);
lastDistance = distance;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ea5e8b30d3f960040ae1e01d3dd699d2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -5,13 +5,13 @@ using UnityEngine.UI;
public class setPosition : MonoBehaviour
{
robotControl robotControl;
robotNavXControl robotControl;
// Start is called before the first frame update
public void Start()
{
GameObject Robot = GameObject.Find("Robot");
robotControl = Robot.GetComponent<robotControl>();
robotControl = Robot.GetComponent<robotNavXControl>();
}
// Update is called once per frame
@@ -23,17 +23,17 @@ public class setPosition : MonoBehaviour
{
if (dd.value == 1)
{
robotControl.pos = new Vector3(-50, 10, -260);
robotControl.transform.position = new Vector3(-50, 0, -256);
}
else if (dd.value == 2)
{
robotControl.pos = new Vector3(0, 10, -260);
robotControl.transform.position = new Vector3(0, 0, -256);
}
else if (dd.value == 3)
{
robotControl.pos = new Vector3(50, 10, -260);
robotControl.transform.position = new Vector3(50, 0, -256);
}
robotControl.initialRot = robotControl.yRot;
robotControl.initRot = robotControl.rot;
dd.value = 0;
}
}