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 5df4b81..5c6dedd 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:c5b87e0aea8f57f9afcffeeea959d9d5b13096fae5391f81a94f7e9694bb8aaa +oid sha256:4d594c616b0eb44e6b6f7b9ec1d4cba6468f7fc2519ad2ce517541d0ecb26e9a 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 dcc869e..37d99f5 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:f0c126c2227bb98418c09496e3947d76db4257919f65046cedba9b2e1b8e9716 +oid sha256:cbd9fdc6275465a9b1715e2ab62259322eee14a7b04282e195f4ac025bff3255 size 4140632 diff --git a/2018-unity-sim/Assets/Main.unity b/2018-unity-sim/Assets/Main.unity index 46bcf37..2f3e2f3 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:cccf856e8bc96b9a519d22d7f282f3b9c28a8c17a6ee9109118d5071805e88d0 -size 9969207 +oid sha256:b58d8e9b8bde13d367cf00d433c5a643695c6ae1e342bcbf448a7be16f5c7b34 +size 9969204 diff --git a/2018-unity-sim/Assets/Serial.cs b/2018-unity-sim/Assets/Serial.cs index d082e17..39e31ba 100644 --- a/2018-unity-sim/Assets/Serial.cs +++ b/2018-unity-sim/Assets/Serial.cs @@ -29,47 +29,37 @@ public class Serial { public void send(int start, int a, int b, int c) { + if (serialPort == null) + { + serialPort = new SerialPort(@"\\.\" + "COM10", 115200); + + try + { + serialPort.Open(); + serialPort.DiscardOutBuffer(); + serialPort.DiscardInBuffer(); + + enabled = true; + } + catch + { + enabled = false; + } + } + if (enabled) { - if (serialPort == null) - { - serialPort = new SerialPort(@"\\.\" + "COM10", 115200); - - try - { - serialPort.Open(); - serialPort.DiscardOutBuffer(); - serialPort.DiscardInBuffer(); - } - catch - { - enabled = false; - } - } - if (serialPort is SerialPort) { - - serialPort.Write(" #"); - serialPort.Write(start.ToString()); - serialPort.Write(" P"); - serialPort.Write(a.ToString()); - + string send = " #" + start.ToString() + " P" + a.ToString(); start++; - - serialPort.Write(" #"); - serialPort.Write(start.ToString()); - serialPort.Write(" P"); - serialPort.Write(b.ToString()); - + send = send + " #" + start.ToString() + " P" + b.ToString(); start++; + send = send + " #" + start.ToString() + " P" + c.ToString(); - serialPort.Write(" #"); - serialPort.Write(start.ToString()); - serialPort.Write(" P"); - serialPort.Write(c.ToString()); + send = send + " \r"; - serialPort.Write(" \r"); + serialPort.Write(send); } } } diff --git a/2018-unity-sim/Assets/Walk.cs b/2018-unity-sim/Assets/Walk.cs index 8b03700..4ecba33 100644 --- a/2018-unity-sim/Assets/Walk.cs +++ b/2018-unity-sim/Assets/Walk.cs @@ -92,11 +92,8 @@ public class Walk : MonoBehaviour } else { - Vector3 t2 = s[t].pos; - t2.x *= walkspeed; - - // rotate x,y around rotation. - step2[index] = (Quaternion.Euler(0, rotation, 0) * t2) / speed2; + Vector3 t2 = (legsInitial[index] + s[t].pos) - legs[index].GetComponent().point; + step2[index] = t2 / speed2; } } diff --git a/2018-unity-sim/Assets/Walk2.cs b/2018-unity-sim/Assets/Walk2.cs index 548a1ec..fbb7cc2 100644 --- a/2018-unity-sim/Assets/Walk2.cs +++ b/2018-unity-sim/Assets/Walk2.cs @@ -15,6 +15,7 @@ public class Walk2 : MonoBehaviour legsInitial.Add(legs[index].GetComponent().point); step2.Add(0); step3.Add(0); + step4.Add(new Vector3(0, 0, 0)); } } @@ -66,6 +67,7 @@ public class Walk2 : MonoBehaviour //public float walkspeed = 1; private List step2 = new List(); private List step3 = new List(); + private List step4 = new List(); // Update is called once per frame void FixedUpdate() @@ -89,11 +91,12 @@ public class Walk2 : MonoBehaviour { step2[index] = (rotation * s[t].rotation) / speed2; step3[index] = s[t].height / speed2; + step4[index] = new Vector3(0, 0, 0); } else { - step2[index] = (rotation * s[t].rotation) / speed2; - step3[index] = s[t].height / speed2; + Vector3 t2 = legsInitial[index] - legs[index].GetComponent().point; + step4[index] = t2 / speed2; } } @@ -110,11 +113,19 @@ public class Walk2 : MonoBehaviour { for (int index = 0; index < legs.Count; ++index) { - Vector3 n = legs[index].GetComponent().getWorldPos(); - n = Quaternion.Euler(0, step2[index], 0) * n; - n.y += step3[index]; - // rotate x,y around rotation. - legs[index].GetComponent().setWorldPos(n); + if (step4[index] == new Vector3(0, 0, 0)) + { + Vector3 n = legs[index].GetComponent().getWorldPos(); + n = Quaternion.Euler(0, step2[index], 0) * n; + n.y += step3[index]; + // rotate x,y around rotation. + legs[index].GetComponent().setWorldPos(n); + } + else + { + // return to home + legs[index].GetComponent().point += step4[index]; + } } } }