Files
2019-Virtual-Field/FRC 2019 Virtual Camera/Assets/Scripts/robotControl.cs
T

52 lines
1.7 KiB
C#
Raw Normal View History

2019-01-18 19:54:55 -07:00
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
public class robotControl : MonoBehaviour
{
2019-01-28 16:16:40 -07:00
public float initialRot, yRot, yAng;
public float avgEncoder, lastEncoder, leftEncoder, rightEncoder;
public Vector3 pos, rot;
public int button;
2019-01-18 19:54:55 -07:00
robotCommunication roboCom;
2019-01-28 16:16:40 -07:00
bool start = false;
2019-01-18 19:54:55 -07:00
// Start is called before the first frame update
void Start()
{
GameObject Robot = GameObject.Find("Robot");
roboCom = Robot.GetComponent<robotCommunication>();
2019-01-28 16:16:40 -07:00
pos = new Vector3(0, 10, -257.5f);
2019-01-18 19:54:55 -07:00
rot = new Vector3(0.0f, 0.0f, 0.0f);
}
// Update is called once per frame
void Update()
{
2019-01-28 16:16:40 -07:00
roboCom.robotValues.TryGetValue("Yaw Angle Deg", out yRot);
roboCom.robotValues.TryGetValue("Left Pos Inches", out leftEncoder);
roboCom.robotValues.TryGetValue("Right Pos Inches", out rightEncoder);
2019-02-15 16:46:19 -07:00
/*if (!start && roboCom.isData)
2019-01-28 16:16:40 -07:00
{
avgEncoder = (leftEncoder + rightEncoder) / 2;
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.position = pos;
lastEncoder = avgEncoder;
2019-02-15 16:46:19 -07:00
}*/
2019-01-18 19:54:55 -07:00
}
}