public void Tick() { DrawOutput(); if (path.points.Count == 0) { return; } if (travelState != TravelState.Travelling) { return; } var spline = GetTargetSpline(); var targetDistance = 20; target = SplineUtils.GetAbsolutePointOnSpline(spline, SplineUtils.GetSplineLength(spline, 5), targetDistance); if (AtCurrentPoint()) { // If this is the last point if (path.points.Count - 1 == currentPointIndex) { // Stop moving travelState = TravelState.AtDestination; motorControl.SetMotorCommand(MotorControl.MotorCommand.Stopped); return; } else { // Or update the point to the next one currentPointIndex++; } } MotorControl.MotorCommand command = CalculateMotorCommand(); if (!command.Equals(motorControl.LastCommand)) { motorControl.SetMotorCommand(command); } }
void TravellerDump() { var spline = traveller.GetTargetSpline(); var targetDistance = 20; var target = SplineUtils.GetAbsolutePointOnSpline(spline, SplineUtils.GetSplineLength(spline, 5), 100); Me.GetSurface(0).WriteText(string.Join("\n", SplineUtils.SampleSplineToLine(spline, 10) .Select((position, index) => GPS.Stringify(new GPS.Position($"Spline-{index}", position))) .Concat( spline.Select((position, index) => GPS.Stringify(new GPS.Position($"Control Points-{index}", position))) ) .Concat(new List <string>() { GPS.Stringify(new GPS.Position("Target", target)), }) .Concat( paths[currentPathIndex].points.Select((point, index) => GPS.Stringify(new GPS.Position($"Waypoint Position-{index}", point.position))) ) .Concat( paths[currentPathIndex].points.Select((point, index) => GPS.Stringify(new GPS.Position($"Waypoint Direction-{index}", point.position + (point.direction * 3)))) ) )); }