IMyMotorStator.Angle function appears to be bugged (my exploration of the problem)

Luca G. shared this bug 19 days ago
Reported

I'm by no means an intermediate or advanced programmer but i've noticed the following:

For a project I require the use of IMyMotorStator.Angle. This should return the current angle in radians. I've noticed that outputting the float Angle value to a text panel doesn't seem to output the correct value.

The problem doesn't exist when only reading IMyMotorStator.Angle and outputting it to a LCD (in that case it appears to be working fine). However it does emerge when outputting the IMyMotorStator.Angle to an LCD while also setting the position of the rotor in the same script.


It seems as if the angle read becomes "stuck" even when turning the rotor in the aforementioned conditions.

I clearly observed this when I used:

IMyMotorStator.RotateToAngle(MyRotationDirection.AUTO, var targetRotationDegrees, var rotorVelocity);

It gets unstuck for me when the angle surpasses 1*PI (or half a circle), which makes sense if the value is stuck because MyRotationDirection.AUTO should find the shortest path to the target rotation based on its current angle. (using Radians) This means a +/- rotorvelocity should become a -/+ (so switch) one if the difference between the current angle and target angle becomes more than 1*PI or less than -1*PI.


I even wrote my own version of a MyRotationDirection "determinant" to see if that would work. It gave the same results:

The issue is consistently: as the rotor surpasses the IMyMotorStator.Angle value (that I read on the LCD) +- 1*PI, it instantly switches the sign of the velocity indicating the Angle value is indeed stuck. even though the rotor is visually rotating.

once it flips it doesn't seem to update the current angle as displayed on the LCD once/briefly before leading to more issues again.

Runtime.UpdateFrequency does seem to affect the problem somewhat but i've not yet been able to see how it makes a difference exactly. The higher the frequency the more predictable the results seem to be.


I hope this is of help and the issue can be resolved so I can finish the script.

Kind regards,

Luca

Replies (2)

photo
1

This is one of the scripts i've used when i encountered the problem:


Vector3D velocity;

MatrixD mat;

IMyShipController cockpit;

IMyTextPanel textPanel;

IMyMotorStator stator;


float rotorVelocity = 30f;


double XSpeed;

double YSpeed;

double ZSpeed;


public enum State

{

FwU,

FwD,

BwD,

BwU,

H,

}


public Program()

{

Runtime.UpdateFrequency = UpdateFrequency.Update1;

cockpit = GridTerminalSystem.GetBlockWithName("Cockpit") as IMyShipController;

textPanel = GridTerminalSystem.GetBlockWithName("Text Panel") as IMyTextPanel;

stator = GridTerminalSystem.GetBlockWithName("Stator") as IMyMotorStator;

}

public void Main(string argument, UpdateType updateSource)

{

velocity = cockpit.GetShipVelocities().LinearVelocity;

mat = cockpit.WorldMatrix.GetOrientation();

Vector3D localVelocity = Vector3D.Transform(velocity, MatrixD.Transpose(mat));

YSpeed = -localVelocity.Z; XSpeed = localVelocity.X; ZSpeed = localVelocity.Y;

textPanel.WriteText($"Y:{YSpeed}\nZ:{ZSpeed}\n");


int movestate = (int)GetMoveState(YSpeed, ZSpeed);

double rotationTargetD = RotationTarget(movestate, YSpeed, ZSpeed);

float rotationTarget = (float)rotationTargetD;

textPanel.WriteText($"rotationTarget= {rotationTarget}\n", true);

float statorAngle = stator.Angle;

textPanel.WriteText($"angle (using GetAngle) = {statorAngle}\n");

SetRotation(rotationTarget, stator, statorAngle, movestate);

}


public State GetMoveState(double Forward, double Upward)

{

if (Forward > 0f)

{

if (Upward > 0f)

{

return State.FwU;

}

return State.FwD;

}

if (Upward > 0f)

{

return State.BwU;

}

return State.BwD;

}


public double RotationTarget(int Enum, double YSpeed, double ZSpeed)

{

if (Enum == 4)

{

return 0;

}


double YSpeedN = Math.Abs(YSpeed);

double ZSpeedN = Math.Abs(ZSpeed);

double divider = YSpeedN + ZSpeedN;

double partialPos;

if (Enum == 1 || Enum == 3)

{

partialPos = (ZSpeedN/divider)*(Math.PI*0.5);


//fwd

if (Enum ==1)

{

return partialPos+ (0.5*Math.PI);

}


//bwu

else

{

return partialPos + (1.5*Math.PI);

}

}

else

{

partialPos = (YSpeedN/divider)*(Math.PI*0.5);

//fwu

if (Enum == 0)

{

return partialPos;

}

//bwd

else

{

return partialPos+Math.PI;

}

}

}


public void SetRotation(double targetRotation, IMyMotorStator Stator, float Angle, int Enum)

{

float targetRotationDegrees = ((float)((360/(2*Math.PI))*targetRotation));

textPanel.WriteText($"TargetDegrees = {targetRotationDegrees}\n", true);

stator.RotateToAngle(MyRotationDirection.AUTO, targetRotationDegrees, rotorVelocity);

}


public void Save()

{

}

photo
1

Hello Luca,

thank you for reaching our forum with this.

Issue has been reported into our internal system.

Kind regards,

Keen Software House: QA Department

Leave a Comment
 
Attach a file