Files
hexapod-robot/2026-current/Hexapod_Simulation_Unity/Assets/RotationControl.cs
T
mangavalkandClaude Opus 5.5 935526eab5 Firmware simulation, Unity project, and sim-verified robot fixes
Simulation
- sim/: the unchanged robot firmware compiled into hexapod_sim.dll
  against PC stand-ins (Arduino, Servo, Wire + register-level MPU6050,
  RF24 with matching-config radio), a kinematic body model (support
  plane + planted-foot odometry) that also drives the simulated IMU,
  and a headless smoke test (sim_smoke). build.ps1 builds and tests.
- Hexapod_Simulation_Unity/ folded in (history kept in a bundle
  outside the repo). Assets/HexapodSim loads the DLL, drives the
  existing leg rig, and offers joystick / keyboard / robot-serial
  input plus a test panel.

Robot (all found or confirmed in the simulation)
- Config.h geometry taken from the Unity model.
- IK femur elevation sign, gait stance direction, body pose
  rotation direction, yaw lever arm.
- Stance feet integrated from the current command; gait restarts at
  mid-stance; heading integrates the applied turn rate, only while
  walking.
- Leg clearance and reach checks (Limits::feetFeasible); walk command
  and body pose scaled as a whole, pose scale rate-limited, planted
  feet guarded so the body never snaps or legs collide.
- Robot-gyro self-leveling as an integrator.
- Heading mode: steering relative to the body; S walks backward.
- Standing height from the remote (STANCE_HEIGHT_RANGE_MM).

Protocol v3 (reflash both boards)
- CmdPacket gains body_height (22 bytes).

Remote
- Height slider (Nextion hHeight/nHeight, serial [ ]).
- Fixed unspecified I2C read order in RemoteIMU.

LEGACY/: owner's old Nextion HMI and remote hardware assets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 00:37:12 +02:00

105 lines
2.9 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class rotation
{
public float min = -15;
public float max = 15;
public float speed = 0.3f;
public bool dir = false;
public bool enabled = true;
public float i = 0;
public rotation(float speed, float min, float max)
{
this.speed = speed;
this.min = min;
this.max = max;
}
public float update()
{
if (enabled)
{
if (!dir && i < max)
{
i += speed;
}
else if (!dir)
{
dir = !dir;
i = (float)max;
}
else if (dir && i > min)
{
i -= speed;
}
else if (dir)
{
dir = !dir;
i = (float)min;
}
}
return i;
}
}
public class RotationControl : MonoBehaviour
{
public Vector3 transformation = new Vector3(0, 0, 0);
public Vector3 transformation2 = new Vector3(0, 0, 0);
public Quaternion rotation = new Quaternion(0, 0, 0, 0);
public List<GameObject> rotation2 = new List<GameObject>();
public GameObject body;
public GameObject body2;
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.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.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 ()
{
}
// Update is called once per frame
void FixedUpdate()
{
//rotation.x = r1.update();
//rotation.y = r2.update();
//rotation.z = r3.update();
//transformationBeforeRotation.x = r4.update();
//transformationBeforeRotation.y = r5.update();
//transformationBeforeRotation.z = r6.update();
/*transformationAfterRotation.x = r7.update();
transformationAfterRotation.y = r8.update();
transformationAfterRotation.z = r9.update();*/
body.transform.eulerAngles = new Vector3(rotation.x*-1, rotation.y*-1, rotation.z*-1);
body.transform.position = transformation;
body2.transform.localPosition = transformation2;
for (int index = 0; index < rotation2.Count; ++index)
{
rotation2[index].GetComponent<Leg>().rotation = rotation;
rotation2[index].GetComponent<Leg>().transformationBeforeRotation = transformation;
rotation2[index].GetComponent<Leg>().transformationAfterRotation = transformation2;
rotation2[index].GetComponent<Leg>().FixedUpdate();
}
}
}