diff --git a/2018-unity-sim/.vs/Hexapod/v15/Server/sqlite3/storage.ide b/2018-unity-sim/.vs/Hexapod/v15/Server/sqlite3/storage.ide index 1772fc1..a0e099f 100644 --- a/2018-unity-sim/.vs/Hexapod/v15/Server/sqlite3/storage.ide +++ b/2018-unity-sim/.vs/Hexapod/v15/Server/sqlite3/storage.ide @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a112b1a23f82fb2ee5a227783908ee15220ae6538d132124814dbe046b8e7456 -size 704512 +oid sha256:c4c3f4544eb43253b4b9ad94cc8291363a6ce0f6df51feaa403bbfb95295079c +size 1015808 diff --git a/2018-unity-sim/.vs/Hexapod/v15/Server/sqlite3/storage.ide-shm b/2018-unity-sim/.vs/Hexapod/v15/Server/sqlite3/storage.ide-shm index 14821ca..c93e578 100644 --- a/2018-unity-sim/.vs/Hexapod/v15/Server/sqlite3/storage.ide-shm +++ b/2018-unity-sim/.vs/Hexapod/v15/Server/sqlite3/storage.ide-shm @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:96725131fe70ef3e5f0c802dfedf2c719ad4b2b18f84abe4342371cb742a04fc +oid sha256:67e4d109d215f82a493b4ce51e540c4865a5526df7a00a03c03ef61814f85448 size 32768 diff --git a/2018-unity-sim/.vs/Hexapod/v15/Server/sqlite3/storage.ide-wal b/2018-unity-sim/.vs/Hexapod/v15/Server/sqlite3/storage.ide-wal index 1a46983..a5e2164 100644 --- a/2018-unity-sim/.vs/Hexapod/v15/Server/sqlite3/storage.ide-wal +++ b/2018-unity-sim/.vs/Hexapod/v15/Server/sqlite3/storage.ide-wal @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3e4665df57796556f6e9f3b54e1d87794d3e61d4637e00c94f699696e3016e1a +oid sha256:2ccfe5eac771e341c240adcad75bc3967f5421a290d5ce27c7a49eb7a82aacfb size 4140632 diff --git a/2018-unity-sim/Assets/Foot.cs b/2018-unity-sim/Assets/Foot.cs index 7e4cb66..ddac315 100644 --- a/2018-unity-sim/Assets/Foot.cs +++ b/2018-unity-sim/Assets/Foot.cs @@ -28,7 +28,7 @@ public class Foot : Component public Vector3 transformation = 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() { diff --git a/2018-unity-sim/Assets/Leg.cs b/2018-unity-sim/Assets/Leg.cs index eead909..b38c499 100644 --- a/2018-unity-sim/Assets/Leg.cs +++ b/2018-unity-sim/Assets/Leg.cs @@ -26,6 +26,8 @@ public class Leg : MonoBehaviour { public GameObject pointShouldBe; public Vector3 pos = new Vector3(0, 0, 0); + public int startServo = -1; + private Foot foot = new Foot(); // Use this for initialization @@ -71,10 +73,34 @@ public class Leg : MonoBehaviour { 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); Hip2.transform.localRotation = Quaternion.Euler((float)a2, 0, 0); Knie.transform.localRotation = Quaternion.Euler((float)a3, 0, 0); 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; + } } diff --git a/2018-unity-sim/Assets/Main.unity b/2018-unity-sim/Assets/Main.unity index 50665ef..dccfa5a 100644 --- a/2018-unity-sim/Assets/Main.unity +++ b/2018-unity-sim/Assets/Main.unity @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:95a2ba9a07a7566824cb024cd928f08c80c2820fdcd86abfc6642b43253d0ab4 -size 9965616 +oid sha256:740de46c9249c7078152b640eba341ecc651e214355c14dabc7a6a29355d90d1 +size 9965603 diff --git a/2018-unity-sim/Assets/RotationControl.cs b/2018-unity-sim/Assets/RotationControl.cs index 0652173..9e018a4 100644 --- a/2018-unity-sim/Assets/RotationControl.cs +++ b/2018-unity-sim/Assets/RotationControl.cs @@ -57,17 +57,17 @@ public class RotationControl : MonoBehaviour public GameObject body; public GameObject body2; - public rotation r1 = new rotation(0.1f, -15, 15); - public rotation r2 = new rotation(0.2f, -15, 15); - public rotation r3 = new rotation(0.3f, -15, 15); + public rotation r1 = new rotation(0.1f, -10, 10); + public rotation r2 = new rotation(0.2f, -10, 10); + public rotation r3 = new rotation(0.3f, -10, 10); - public rotation r4 = new rotation(0.01f, -3, 3); - public rotation r5 = new rotation(0.02f, -3, 3); - public rotation r6 = new rotation(0.03f, -3, 3); + public rotation r4 = new rotation(0.06f, -3, 3); + public rotation r5 = new rotation(0.08f, -3, 3); + public rotation r6 = new rotation(0.1f, -3, 3); - public rotation r7 = new rotation(0.001f, -3, 3); - public rotation r8 = new rotation(0.002f, -3, 3); - public rotation r9 = new rotation(0.003f, -3, 3); + public rotation r7 = new rotation(0.1f, -3, 3); + public rotation r8 = new rotation(0.2f, -3, 3); + public rotation r9 = new rotation(0.3f, -3, 3); // Use this for initialization void Start () @@ -77,17 +77,17 @@ public class RotationControl : MonoBehaviour // Update is called once per frame void FixedUpdate() { - rotation.x = r1.update(); - rotation.y = r2.update(); - rotation.z = r3.update(); + //rotation.x = r1.update(); + //rotation.y = r2.update(); + //rotation.z = r3.update(); transformation.x = r4.update(); - transformation.y = r5.update(); + //transformation.y = r5.update(); transformation.z = r6.update(); - transformation2.x = r7.update(); + /*transformation2.x = r7.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.position = transformation; diff --git a/2018-unity-sim/Assets/Serial.cs b/2018-unity-sim/Assets/Serial.cs new file mode 100644 index 0000000..f904b15 --- /dev/null +++ b/2018-unity-sim/Assets/Serial.cs @@ -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"); + } + } + +} diff --git a/2018-unity-sim/Assets/Serial.cs.meta b/2018-unity-sim/Assets/Serial.cs.meta new file mode 100644 index 0000000..1b69f45 --- /dev/null +++ b/2018-unity-sim/Assets/Serial.cs.meta @@ -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: diff --git a/2018-unity-sim/ProjectSettings/ProjectSettings.asset b/2018-unity-sim/ProjectSettings/ProjectSettings.asset index 88ea0ba..95f3d08 100644 --- a/2018-unity-sim/ProjectSettings/ProjectSettings.asset +++ b/2018-unity-sim/ProjectSettings/ProjectSettings.asset @@ -554,7 +554,8 @@ PlayerSettings: incrementalIl2cppBuild: {} additionalIl2CppArgs: scriptingRuntimeVersion: 0 - apiCompatibilityLevelPerPlatform: {} + apiCompatibilityLevelPerPlatform: + Standalone: 1 m_RenderingPath: 1 m_MobileRenderingPath: 1 metroPackageName: Hexapod