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 a0e099f..d35ce34 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:c4c3f4544eb43253b4b9ad94cc8291363a6ce0f6df51feaa403bbfb95295079c -size 1015808 +oid sha256:9202b8dd6cfeae2178ab386ec0e86aad5dfeca5ff21214cee23f3cd8ebd79869 +size 1024000 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 c93e578..018b39c 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:67e4d109d215f82a493b4ce51e540c4865a5526df7a00a03c03ef61814f85448 +oid sha256:fba003802c813b0a87d96cacf1c558f976e2d17d121e27e33b9207cdb44efd72 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 a5e2164..02cfc59 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:2ccfe5eac771e341c240adcad75bc3967f5421a290d5ce27c7a49eb7a82aacfb +oid sha256:edf75adc1c1ee4aac6176c016911cc99350128df50dc38cfbb8202d3a6d03727 size 4140632 diff --git a/2018-unity-sim/Assets/Main.unity b/2018-unity-sim/Assets/Main.unity index dccfa5a..3ab7da8 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:740de46c9249c7078152b640eba341ecc651e214355c14dabc7a6a29355d90d1 -size 9965603 +oid sha256:75c899ee15cdc09c6d7f8705def4a49207aac4f45c6394ed9434aaa3d1d53138 +size 9968810 diff --git a/2018-unity-sim/Assets/RotationControl.cs b/2018-unity-sim/Assets/RotationControl.cs index 9e018a4..8d837fc 100644 --- a/2018-unity-sim/Assets/RotationControl.cs +++ b/2018-unity-sim/Assets/RotationControl.cs @@ -81,9 +81,9 @@ public class RotationControl : MonoBehaviour //rotation.y = r2.update(); //rotation.z = r3.update(); - transformation.x = r4.update(); + //transformation.x = r4.update(); //transformation.y = r5.update(); - transformation.z = r6.update(); + //transformation.z = r6.update(); /*transformation2.x = r7.update(); transformation2.y = r8.update(); diff --git a/2018-unity-sim/Assets/Serial.cs b/2018-unity-sim/Assets/Serial.cs index f904b15..5eb6ece 100644 --- a/2018-unity-sim/Assets/Serial.cs +++ b/2018-unity-sim/Assets/Serial.cs @@ -23,42 +23,47 @@ public class Serial { } } + public bool enabled = false; + SerialPort serialPort; public void send(int start, int a, int b, int c) { - if (serialPort == null) + if (enabled) { - serialPort = new SerialPort(@"\\.\" + "COM10", 115200); + if (serialPort == null) + { + serialPort = new SerialPort(@"\\.\" + "COM10", 115200); - serialPort.Open(); - serialPort.DiscardOutBuffer(); - serialPort.DiscardInBuffer(); - } + serialPort.Open(); + serialPort.DiscardOutBuffer(); + serialPort.DiscardInBuffer(); + } - if (serialPort is SerialPort) - { + if (serialPort is SerialPort) + { - serialPort.Write(" #"); - serialPort.Write(start.ToString()); - serialPort.Write(" P"); - serialPort.Write(a.ToString()); + serialPort.Write(" #"); + serialPort.Write(start.ToString()); + serialPort.Write(" P"); + serialPort.Write(a.ToString()); - start++; + start++; - serialPort.Write(" #"); - serialPort.Write(start.ToString()); - serialPort.Write(" P"); - serialPort.Write(b.ToString()); + serialPort.Write(" #"); + serialPort.Write(start.ToString()); + serialPort.Write(" P"); + serialPort.Write(b.ToString()); - start++; + start++; - serialPort.Write(" #"); - serialPort.Write(start.ToString()); - serialPort.Write(" P"); - serialPort.Write(c.ToString()); + serialPort.Write(" #"); + serialPort.Write(start.ToString()); + serialPort.Write(" P"); + serialPort.Write(c.ToString()); - serialPort.Write(" \r"); + serialPort.Write(" \r"); + } } } diff --git a/2018-unity-sim/Assets/Walk.cs b/2018-unity-sim/Assets/Walk.cs new file mode 100644 index 0000000..4382d70 --- /dev/null +++ b/2018-unity-sim/Assets/Walk.cs @@ -0,0 +1,101 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Walk : MonoBehaviour +{ + public List legs = new List(); + private List legsInitial = new List(); + + // Use this for initialization + void Start() + { + for (int index = 0; index < legs.Count; ++index) + { + legsInitial.Add(legs[index].GetComponent().point); + } + } + + struct step + { + public Vector3 pos; + public bool inAir; + + public step(Vector3 p, bool i) + { + pos = p; + inAir = i; + } + } + + // 1, 3, 5 -= 3 + + int offset(int i, int offset, int max) + { + return i - offset < 0 ? (max - (offset - i)) : i - offset; + } + + step[] s = { + new step(new Vector3(-1, 0, 0), false), + + new step(new Vector3(0, -2, 0), false), + + new step(new Vector3(0, 0, 0), false), // rest + + new step(new Vector3(1, 0, 0), false), + new step(new Vector3(1, 0, 0), false), + + new step(new Vector3(0, 0, 0), false), // rest + + new step(new Vector3(0, 2, 0), true), + new step(new Vector3(-1, 0, 0), false), + }; + + public int st = 5; + public int speed2 = 30; + int speed = 10; + + public float rotation = 0; + + int size = 8; + + public float walkspeed = 1; + + // Update is called once per frame + void FixedUpdate() + { + if (speed <= 0) + { + if (st >= size-1) + st = 0; + else + st++; + + for (int index = 0; index < legs.Count; ++index) + { + int t = st; + if (index == 1 || index == 3 || index == 5) + { + t = offset(st, 4, size); + } + + if (s[t].inAir == false) + { + Vector3 t2 = s[t].pos; + t2.x *= walkspeed; + + // rotate x,y around rotation. + legs[index].GetComponent().point += Quaternion.Euler(0, rotation, 0) * t2; + } + else + { + legs[index].GetComponent().point = legsInitial[index] + s[t].pos; + } + } + + speed = speed2; + } + else + speed--; + } +} diff --git a/2018-unity-sim/Assets/Walk.cs.meta b/2018-unity-sim/Assets/Walk.cs.meta new file mode 100644 index 0000000..72a7f4a --- /dev/null +++ b/2018-unity-sim/Assets/Walk.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 62866dc69f17c5f40a7ec527e34e82f1 +timeCreated: 1542141752 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: