Added serial link to SSC32
This commit is contained in:
1 parent
235a81c280
commit
9dcf9a6190
10 files changed
+128
-23
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -28,7 +28,7 @@ public class Foot : Component
|
|||||||
public Vector3 transformation = new Vector3(0, 0, 0);
|
public Vector3 transformation = new Vector3(0, 0, 0);
|
||||||
public Vector3 transformation2 = new Vector3(0, 0, 0);
|
public Vector3 transformation2 = new Vector3(0, 0, 0);
|
||||||
|
|
||||||
static float knie_offset = 2;
|
static float knie_offset = 3;
|
||||||
|
|
||||||
void RL3()
|
void RL3()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ public class Leg : MonoBehaviour {
|
|||||||
public GameObject pointShouldBe;
|
public GameObject pointShouldBe;
|
||||||
public Vector3 pos = new Vector3(0, 0, 0);
|
public Vector3 pos = new Vector3(0, 0, 0);
|
||||||
|
|
||||||
|
public int startServo = -1;
|
||||||
|
|
||||||
private Foot foot = new Foot();
|
private Foot foot = new Foot();
|
||||||
|
|
||||||
// Use this for initialization
|
// Use this for initialization
|
||||||
@@ -71,10 +73,34 @@ public class Leg : MonoBehaviour {
|
|||||||
a3 = foot.O3 - 90;
|
a3 = foot.O3 - 90;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!invert && startServo != -1)
|
||||||
|
{
|
||||||
|
Serial.Instance.send(startServo,
|
||||||
|
(int)Remap((float)a1, -90, 90, 2500, 500),
|
||||||
|
(int)Remap((float)a2, -90, 90, 2500, 500), // 0 is middel
|
||||||
|
(int)Remap((float)a3, 90, -90, 2500, 500)); // 0 is middel
|
||||||
|
}
|
||||||
|
else if (invert && startServo != -1)
|
||||||
|
{
|
||||||
|
double a1 = foot.O1 - 90;
|
||||||
|
double a2 = 90 - foot.O2;
|
||||||
|
double a3 = foot.O3 - 90;
|
||||||
|
|
||||||
|
Serial.Instance.send(startServo,
|
||||||
|
(int)Remap((float)a1, -90, 90, 500, 2500),
|
||||||
|
(int)Remap((float)a2, -90, 90, 500, 2500), // 0 is middel
|
||||||
|
(int)Remap((float)a3, 90, -90, 500, 2500)); // 0 is middel
|
||||||
|
}
|
||||||
|
|
||||||
Hip1.transform.localRotation = Quaternion.Euler(0, (float)a1, 0);
|
Hip1.transform.localRotation = Quaternion.Euler(0, (float)a1, 0);
|
||||||
Hip2.transform.localRotation = Quaternion.Euler((float)a2, 0, 0);
|
Hip2.transform.localRotation = Quaternion.Euler((float)a2, 0, 0);
|
||||||
Knie.transform.localRotation = Quaternion.Euler((float)a3, 0, 0);
|
Knie.transform.localRotation = Quaternion.Euler((float)a3, 0, 0);
|
||||||
|
|
||||||
pointShouldBe.transform.localPosition = foot.pos;
|
pointShouldBe.transform.localPosition = foot.pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static float Remap(float value, float from1, float to1, float from2, float to2)
|
||||||
|
{
|
||||||
|
return (value - from1) / (to1 - from1) * (to2 - from2) + from2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
@@ -57,17 +57,17 @@ public class RotationControl : MonoBehaviour
|
|||||||
public GameObject body;
|
public GameObject body;
|
||||||
public GameObject body2;
|
public GameObject body2;
|
||||||
|
|
||||||
public rotation r1 = new rotation(0.1f, -15, 15);
|
public rotation r1 = new rotation(0.1f, -10, 10);
|
||||||
public rotation r2 = new rotation(0.2f, -15, 15);
|
public rotation r2 = new rotation(0.2f, -10, 10);
|
||||||
public rotation r3 = new rotation(0.3f, -15, 15);
|
public rotation r3 = new rotation(0.3f, -10, 10);
|
||||||
|
|
||||||
public rotation r4 = new rotation(0.01f, -3, 3);
|
public rotation r4 = new rotation(0.06f, -3, 3);
|
||||||
public rotation r5 = new rotation(0.02f, -3, 3);
|
public rotation r5 = new rotation(0.08f, -3, 3);
|
||||||
public rotation r6 = new rotation(0.03f, -3, 3);
|
public rotation r6 = new rotation(0.1f, -3, 3);
|
||||||
|
|
||||||
public rotation r7 = new rotation(0.001f, -3, 3);
|
public rotation r7 = new rotation(0.1f, -3, 3);
|
||||||
public rotation r8 = new rotation(0.002f, -3, 3);
|
public rotation r8 = new rotation(0.2f, -3, 3);
|
||||||
public rotation r9 = new rotation(0.003f, -3, 3);
|
public rotation r9 = new rotation(0.3f, -3, 3);
|
||||||
|
|
||||||
// Use this for initialization
|
// Use this for initialization
|
||||||
void Start ()
|
void Start ()
|
||||||
@@ -77,17 +77,17 @@ public class RotationControl : MonoBehaviour
|
|||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void FixedUpdate()
|
void FixedUpdate()
|
||||||
{
|
{
|
||||||
rotation.x = r1.update();
|
//rotation.x = r1.update();
|
||||||
rotation.y = r2.update();
|
//rotation.y = r2.update();
|
||||||
rotation.z = r3.update();
|
//rotation.z = r3.update();
|
||||||
|
|
||||||
transformation.x = r4.update();
|
transformation.x = r4.update();
|
||||||
transformation.y = r5.update();
|
//transformation.y = r5.update();
|
||||||
transformation.z = r6.update();
|
transformation.z = r6.update();
|
||||||
|
|
||||||
transformation2.x = r7.update();
|
/*transformation2.x = r7.update();
|
||||||
transformation2.y = r8.update();
|
transformation2.y = r8.update();
|
||||||
transformation2.z = r9.update();
|
transformation2.z = r9.update();*/
|
||||||
|
|
||||||
body.transform.eulerAngles = new Vector3(rotation.x*-1, rotation.y*-1, rotation.z*-1);
|
body.transform.eulerAngles = new Vector3(rotation.x*-1, rotation.y*-1, rotation.z*-1);
|
||||||
body.transform.position = transformation;
|
body.transform.position = transformation;
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
using System.IO.Ports;
|
||||||
|
|
||||||
|
public class Serial {
|
||||||
|
private static Serial instance;
|
||||||
|
|
||||||
|
private Serial() { }
|
||||||
|
|
||||||
|
~Serial() {
|
||||||
|
serialPort.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Serial Instance
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (instance == null)
|
||||||
|
{
|
||||||
|
instance = new Serial();
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SerialPort serialPort;
|
||||||
|
|
||||||
|
public void send(int start, int a, int b, int c)
|
||||||
|
{
|
||||||
|
if (serialPort == null)
|
||||||
|
{
|
||||||
|
serialPort = new SerialPort(@"\\.\" + "COM10", 115200);
|
||||||
|
|
||||||
|
serialPort.Open();
|
||||||
|
serialPort.DiscardOutBuffer();
|
||||||
|
serialPort.DiscardInBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (serialPort is SerialPort)
|
||||||
|
{
|
||||||
|
|
||||||
|
serialPort.Write(" #");
|
||||||
|
serialPort.Write(start.ToString());
|
||||||
|
serialPort.Write(" P");
|
||||||
|
serialPort.Write(a.ToString());
|
||||||
|
|
||||||
|
start++;
|
||||||
|
|
||||||
|
serialPort.Write(" #");
|
||||||
|
serialPort.Write(start.ToString());
|
||||||
|
serialPort.Write(" P");
|
||||||
|
serialPort.Write(b.ToString());
|
||||||
|
|
||||||
|
start++;
|
||||||
|
|
||||||
|
serialPort.Write(" #");
|
||||||
|
serialPort.Write(start.ToString());
|
||||||
|
serialPort.Write(" P");
|
||||||
|
serialPort.Write(c.ToString());
|
||||||
|
|
||||||
|
serialPort.Write(" \r");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c99b6d9374ff6d3419c7692fdf3c1791
|
||||||
|
timeCreated: 1542057315
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -554,7 +554,8 @@ PlayerSettings:
|
|||||||
incrementalIl2cppBuild: {}
|
incrementalIl2cppBuild: {}
|
||||||
additionalIl2CppArgs:
|
additionalIl2CppArgs:
|
||||||
scriptingRuntimeVersion: 0
|
scriptingRuntimeVersion: 0
|
||||||
apiCompatibilityLevelPerPlatform: {}
|
apiCompatibilityLevelPerPlatform:
|
||||||
|
Standalone: 1
|
||||||
m_RenderingPath: 1
|
m_RenderingPath: 1
|
||||||
m_MobileRenderingPath: 1
|
m_MobileRenderingPath: 1
|
||||||
metroPackageName: Hexapod
|
metroPackageName: Hexapod
|
||||||
|
|||||||
Reference in new issue
Block a user