Welcome to Keen Software House Forums! Log in or Sign up to interact with the KSH community.
  1. You are currently browsing our forum as a guest. Create your own forum account to access all forum functionality.

How to get the current rotor angle ?

Discussion in 'General' started by wagner, Oct 1, 2017.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. wagner Apprentice Engineer

    Messages:
    101
    In the program block, I am missing something or there is no "angle" attribute for the motors ( IMyMotorStator ) ?
     
  2. ShadedMJ Apprentice Engineer

    Messages:
    242
    block.Angle

    Careful on setting velocity with programming block. Last I checked the display is in a different scale than block.Velocity by about 10x.
     
  3. wagner Apprentice Engineer

    Messages:
    101
    Hi Shade thanks for your reply.
    I could not find this property, my IMyMotorBase dont have it, also I could not find anything in the docs, maybe its not there yet ?
     
  4. ShadedMJ Apprentice Engineer

    Messages:
    242
    Last edited: Oct 2, 2017
    • Agree Agree x 1
  5. w0lf3y Apprentice Engineer

    Messages:
    152
    I use ILSpy and it loads the game files when i use it, so it's always current. rotor.Angle is correct but it returns (I believe) radians.

    here's small snippet i use to get a rotor's angle and read it's upper / lower limits then safty lock them (not shown) if it has reach it's limit.

    Code:
    IMyMotorStator rotor = equipment[i] as IMyMotorStator;
      Echo("Rotor Found: " + rotor.CustomName.ToString());
      string rAngle = null;
      string rAngleLength = null;
      string rUpperLimit = null;
      string rLowerLimit = null;
      rAngleLength = MathHelper.ToDegrees(rotor.Angle).ToString();
      string[] angleArray = rAngleLength.Split('.');
      rAngle = angleArray[0];
      Echo("Current Position: " + rAngle);
      rLowerLimit = rotor.GetValue<float>("LowerLimit").ToString();
      Echo("Lower Limit: " + rLowerLimit);
      rUpperLimit = rotor.GetValue<float>("UpperLimit").ToString();
      Echo("Upper Limit: " + rUpperLimit);
    the bits tha are probably most relevant to you are:
    Code:
    rAngleLength = MathHelper.ToDegrees(rotor.Angle).ToString();
    string[] angleArray = rAngleLength.Split('.');
    rAngle = angleArray[0];
    I didn't write the special bits, I found them in a workshop code I tore apart, I would offer reference to original author, but it's been a long time and I've forgotten where i got it from.
     
  6. Pharap Apprentice Engineer

    Messages:
    175
    That's a very expensive way to extract the integer part from a float.

    Two much cheaper options:
    Code:
    float degrees = Math.Round(MathHelper.ToDegrees(rotor.Angle));
    
    Code:
    int degrees = (int)MathHelper.ToDegrees(rotor.Angle);
    
    Assuming of course you don't actually want the fractional part, otherwise
    Code:
    float degrees = MathHelper.ToDegrees(rotor.Angle);
    
    Is perfectly fine.
     
  7. ShadedMJ Apprentice Engineer

    Messages:
    242
    I think the angle is still correct.

    Velocity is quite messed up as of 3 weeks ago. The display is rotations_per_minute but .velocity is radians_per_second, I probably have that wrong but the scales are definitely different between value and display. Setting .velocity to 4 makes the display at 38.2 or so.
     
Thread Status:
This last post in this thread was made more than 31 days old.