updated walk and controller input to joystick

This commit is contained in:
2022-12-04 23:11:05 +01:00
parent 40e71c5ce4
commit be04329d65
25 changed files with 677 additions and 941 deletions
+29 -19
View File
@@ -1,12 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine;
public class Leg : MonoBehaviour {
public Transform Hip1;
public Transform Hip2;
public Transform Knie;
// rotation angles for different servos
public double a1 = 0;
public double a2 = 0;
public double a3 = 0;
@@ -14,11 +13,12 @@ public class Leg : MonoBehaviour {
public Vector3 point = new Vector3(10, 10, 0);
public Quaternion rotation = new Quaternion(0, 0, 0, 0);
public Vector3 transformation = new Vector3(0, 0, 0);
public Vector3 transformation2 = new Vector3(0, 0, 0);
public Vector3 transformationBeforeRotation = new Vector3(0, 0, 0);
public Vector3 transformationAfterRotation = new Vector3(0, 0, 0);
public bool invert = false;
public bool invertForLeftLeg = false;
// translation to change origin to middle of body
public double translateX = 0;
public double translateY = 0;
public double translateZ = 0;
@@ -51,16 +51,16 @@ public class Leg : MonoBehaviour {
foot.translateZ = translateZ;
// transform before rotation.
foot.transformation = transformation;
foot.transformation = transformationBeforeRotation;
// transform after rotation.
foot.transformation2 = transformation2;
foot.transformation2 = transformationAfterRotation;
foot.invert = invert;
foot.invert = invertForLeftLeg;
foot.setleg();
if (!invert)
if (!invertForLeftLeg)
{
a1 = foot.O1 - 90;
a2 = 90 - foot.O2;
@@ -73,23 +73,33 @@ public class Leg : MonoBehaviour {
a3 = foot.O3 - 90;
}
if (!invert && startServo != -1)
if (!invertForLeftLeg && 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
if(false)
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
(int)Remap((float)a1, -90, 90, 0, 180),
(int)Remap((float)a2, 90, -90, 0, 180), // 0 is middel
(int)Remap((float)a3, -90, 90, 0, 180)); // 0 is middel
}
else if (invert && startServo != -1)
else if (invertForLeftLeg && 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
// 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
if (false)
Serial.Instance.send(startServo,
(int)Remap((float)a1, 90, -90, 0, 180),
(int)Remap((float)a2, -90, 90, 0, 180), // 0 is middel
(int)Remap((float)a3, 90, -90, 0, 180)); // 0 is middel
}
Hip1.transform.localRotation = Quaternion.Euler(0, (float)a1, 0);