Initial Commit

This commit is contained in:
Keenan D. Buckley
2019-01-18 19:54:55 -07:00
parent f37167f725
commit 2b26a07105
38 changed files with 1259726 additions and 0 deletions
@@ -0,0 +1,52 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Net;
using System.Net.Sockets;
using System.Text;
using UnityEngine;
public class robotCommunication : MonoBehaviour
{
public static int portNumber = 4388;
public int bytesAvailable;
public SortedList<string, float> robotValues =
new SortedList<string, float>
{
{ "encoder", 0.0f },
{ "navX", 0.0f },
};
public string input;
IPEndPoint serverAddress = new IPEndPoint(IPAddress.Parse("127.0.0.1"), portNumber);
Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
short currentIndex;
float currentValue;
// Start is called before the first frame update
void Start()
{
Console.WriteLine("Connecting...");
clientSocket.Connect(serverAddress);
Console.WriteLine("Connected");
}
// Update is called once per frame
void Update()
{
bytesAvailable = clientSocket.Available;
if (bytesAvailable == 12)
{
byte[] byteInput = new byte[100];
clientSocket.Receive(byteInput);
input = Encoding.UTF8.GetString(byteInput);
string[] values = input.Split('|');
robotValues["encoder"] = float.Parse(values[0], CultureInfo.InvariantCulture.NumberFormat);
robotValues["navX"] = float.Parse(values[1], CultureInfo.InvariantCulture.NumberFormat);
clientSocket.Send(new byte[] { 100 });
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b452003d27a1fcc418ff00dcf3d33fef
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,42 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
public class robotControl : MonoBehaviour
{
public float yRot, yAng;
public float avgEncoder, lastEncoder;
public Vector3 pos;
public Vector3 rot;
robotCommunication roboCom;
// Start is called before the first frame update
void Start()
{
GameObject Robot = GameObject.Find("Robot");
roboCom = Robot.GetComponent<robotCommunication>();
pos = new Vector3(0, 10, -260);
rot = new Vector3(0.0f, 0.0f, 0.0f);
gameObject.transform.position = pos;
roboCom.robotValues.TryGetValue("encoder", out avgEncoder);
lastEncoder = avgEncoder;
}
// Update is called once per frame
void Update()
{
roboCom.robotValues.TryGetValue("encoder", out yRot);
roboCom.robotValues.TryGetValue("encoder", out avgEncoder);
yAng = (yRot + 90) * Mathf.Deg2Rad;
pos.x += ((avgEncoder - lastEncoder) * Mathf.Cos(yAng));
pos.z += ((avgEncoder - lastEncoder) * Mathf.Sin(yAng));
///TODO: Adjust yRot to fall within -180 to 180
rot.y = yRot;
transform.rotation = Quaternion.Euler(rot);
transform.position = pos;
lastEncoder = avgEncoder;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3ad2403fd7bea294a9b282ec3181df43
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: