mirror of
https://github.com/Team4388/2019-Virtual-Field.git
synced 2026-06-09 00:28:01 -06:00
Compatability with Robopipe v2.0.0
This commit is contained in:
@@ -0,0 +1,33 @@
|
|||||||
|
# ===========================
|
||||||
|
# Default Collab Ignore Rules
|
||||||
|
# ===========================
|
||||||
|
|
||||||
|
# OS Generated
|
||||||
|
# ============
|
||||||
|
.DS_Store
|
||||||
|
._*
|
||||||
|
.Spotlight-V100
|
||||||
|
.Trashes
|
||||||
|
Icon?
|
||||||
|
ehthumbs.db
|
||||||
|
[Tt]humbs.db
|
||||||
|
[Dd]esktop.ini
|
||||||
|
|
||||||
|
# Visual Studio / MonoDevelop generated
|
||||||
|
# =====================================
|
||||||
|
[Ee]xported[Oo]bj/
|
||||||
|
*.userprefs
|
||||||
|
*.csproj
|
||||||
|
*.pidb
|
||||||
|
*.suo
|
||||||
|
*.sln
|
||||||
|
*.user
|
||||||
|
*.unityproj
|
||||||
|
*.booproj
|
||||||
|
|
||||||
|
# Unity generated
|
||||||
|
# ===============
|
||||||
|
[Oo]bj/
|
||||||
|
[Bb]uild
|
||||||
|
sysinfo.txt
|
||||||
|
*.stackdump
|
||||||
@@ -9,8 +9,8 @@ Material:
|
|||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_Name: Detail
|
m_Name: Detail
|
||||||
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
|
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
|
||||||
m_ShaderKeywords: _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
|
m_ShaderKeywords: _EMISSION _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
|
||||||
m_LightmapFlags: 4
|
m_LightmapFlags: 1
|
||||||
m_EnableInstancingVariants: 0
|
m_EnableInstancingVariants: 0
|
||||||
m_DoubleSidedGI: 0
|
m_DoubleSidedGI: 0
|
||||||
m_CustomRenderQueue: -1
|
m_CustomRenderQueue: -1
|
||||||
@@ -73,5 +73,5 @@ Material:
|
|||||||
- _UVSec: 0
|
- _UVSec: 0
|
||||||
- _ZWrite: 1
|
- _ZWrite: 1
|
||||||
m_Colors:
|
m_Colors:
|
||||||
- _Color: {r: 0.7924528, g: 0.7887148, b: 0.7887148, a: 1}
|
- _Color: {r: 0, g: 0.8480973, b: 1, a: 1}
|
||||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
- _EmissionColor: {r: 0, g: 0.19711433, b: 0.2264151, a: 1}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 4e0e207295f654e429a11bbe0880a490
|
guid: 75a4bc78aeb04c747bfb4dbc677abb87
|
||||||
ModelImporter:
|
ModelImporter:
|
||||||
serializedVersion: 23
|
serializedVersion: 23
|
||||||
fileIDToRecycleName:
|
fileIDToRecycleName:
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -9,16 +9,22 @@ using UnityEngine;
|
|||||||
|
|
||||||
public class robotCommunication : MonoBehaviour
|
public class robotCommunication : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
public bool isData = false;
|
||||||
public static int portNumber = 4388;
|
public static int portNumber = 4388;
|
||||||
public int bytesAvailable;
|
public int bytesAvailable;
|
||||||
|
List<string> keys = new List<string>();
|
||||||
public SortedList<string, float> robotValues =
|
public SortedList<string, float> robotValues =
|
||||||
new SortedList<string, float>
|
new SortedList<string, float>
|
||||||
{
|
{
|
||||||
{ "encoder", 0.0f },
|
{ "Left Pos Inches", 0.0f },
|
||||||
{ "navX", 0.0f },
|
{ "Yaw Angle Deg", 0.0f },
|
||||||
|
{ "Right Pos Inches", 0.0f },
|
||||||
|
{ "Elevator Pos Ticks", 0.0f },
|
||||||
};
|
};
|
||||||
|
|
||||||
public string input;
|
public float encoder, navX;
|
||||||
|
|
||||||
|
public string input, request = "";
|
||||||
|
|
||||||
IPEndPoint serverAddress = new IPEndPoint(IPAddress.Parse("127.0.0.1"), portNumber);
|
IPEndPoint serverAddress = new IPEndPoint(IPAddress.Parse("127.0.0.1"), portNumber);
|
||||||
Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||||
@@ -29,24 +35,36 @@ public class robotCommunication : MonoBehaviour
|
|||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
Console.WriteLine("Connecting...");
|
|
||||||
clientSocket.Connect(serverAddress);
|
clientSocket.Connect(serverAddress);
|
||||||
Console.WriteLine("Connected");
|
foreach (var valuePair in robotValues)
|
||||||
|
{
|
||||||
|
request += valuePair.Key;
|
||||||
|
keys.Add(valuePair.Key);
|
||||||
|
request += ",";
|
||||||
|
}
|
||||||
|
request = request.Substring(0,request.Length-1);
|
||||||
|
byte[] byteRequest = Encoding.UTF8.GetBytes(request);
|
||||||
|
clientSocket.Send(byteRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
bytesAvailable = clientSocket.Available;
|
bytesAvailable = clientSocket.Available;
|
||||||
if (bytesAvailable == 12)
|
if (bytesAvailable > 10)
|
||||||
{
|
{
|
||||||
byte[] byteInput = new byte[100];
|
byte[] byteInput = new byte[100];
|
||||||
clientSocket.Receive(byteInput);
|
clientSocket.Receive(byteInput);
|
||||||
input = Encoding.UTF8.GetString(byteInput);
|
input = Encoding.UTF8.GetString(byteInput);
|
||||||
string[] values = input.Split('|');
|
string[] values = input.Split('|');
|
||||||
robotValues["encoder"] = float.Parse(values[0], CultureInfo.InvariantCulture.NumberFormat);
|
int i = 0;
|
||||||
robotValues["navX"] = float.Parse(values[1], CultureInfo.InvariantCulture.NumberFormat);
|
foreach (string key in keys)
|
||||||
|
{
|
||||||
|
robotValues[keys[i]] = float.Parse(values[i], CultureInfo.InvariantCulture.NumberFormat);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
clientSocket.Send(new byte[] { 100 });
|
clientSocket.Send(new byte[] { 100 });
|
||||||
|
isData = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,37 +6,46 @@ using UnityEngine;
|
|||||||
|
|
||||||
public class robotControl : MonoBehaviour
|
public class robotControl : MonoBehaviour
|
||||||
{
|
{
|
||||||
public float yRot, yAng;
|
public float initialRot, yRot, yAng;
|
||||||
public float avgEncoder, lastEncoder;
|
public float avgEncoder, lastEncoder, leftEncoder, rightEncoder;
|
||||||
public Vector3 pos;
|
public Vector3 pos, rot;
|
||||||
public Vector3 rot;
|
public int button;
|
||||||
robotCommunication roboCom;
|
robotCommunication roboCom;
|
||||||
|
bool start = false;
|
||||||
|
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
GameObject Robot = GameObject.Find("Robot");
|
GameObject Robot = GameObject.Find("Robot");
|
||||||
roboCom = Robot.GetComponent<robotCommunication>();
|
roboCom = Robot.GetComponent<robotCommunication>();
|
||||||
pos = new Vector3(0, 10, -260);
|
pos = new Vector3(0, 10, -257.5f);
|
||||||
rot = new Vector3(0.0f, 0.0f, 0.0f);
|
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
|
// Update is called once per frame
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
roboCom.robotValues.TryGetValue("encoder", out yRot);
|
roboCom.robotValues.TryGetValue("Yaw Angle Deg", out yRot);
|
||||||
roboCom.robotValues.TryGetValue("encoder", out avgEncoder);
|
roboCom.robotValues.TryGetValue("Left Pos Inches", out leftEncoder);
|
||||||
yAng = (yRot + 90) * Mathf.Deg2Rad;
|
roboCom.robotValues.TryGetValue("Right Pos Inches", out rightEncoder);
|
||||||
pos.x += ((avgEncoder - lastEncoder) * Mathf.Cos(yAng));
|
if (!start && roboCom.isData)
|
||||||
pos.z += ((avgEncoder - lastEncoder) * Mathf.Sin(yAng));
|
{
|
||||||
///TODO: Adjust yRot to fall within -180 to 180
|
avgEncoder = (leftEncoder + rightEncoder) / 2;
|
||||||
rot.y = yRot;
|
lastEncoder = avgEncoder;
|
||||||
|
initialRot = yRot;
|
||||||
|
transform.position = pos;
|
||||||
|
start = true;
|
||||||
|
} else if (roboCom.isData) {
|
||||||
|
avgEncoder = (leftEncoder + rightEncoder) / 2;
|
||||||
|
yAng = (yRot - initialRot) * Mathf.Deg2Rad;
|
||||||
|
float _yAng = yAng;
|
||||||
|
pos.x -= (avgEncoder - lastEncoder) * Mathf.Cos(yAng);
|
||||||
|
_yAng = yAng;
|
||||||
|
pos.z += (avgEncoder - lastEncoder) * Mathf.Sin(yAng);
|
||||||
|
rot.y = yAng * Mathf.Rad2Deg;
|
||||||
transform.rotation = Quaternion.Euler(rot);
|
transform.rotation = Quaternion.Euler(rot);
|
||||||
transform.position = pos;
|
transform.position = pos;
|
||||||
lastEncoder = avgEncoder;
|
lastEncoder = avgEncoder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user