1. This forum is obsolete and read-only. Feel free to contact us at support.keenswh.com

Broken Rotor script...

Discussion in 'Programming (In-game)' started by anczak23, Jul 14, 2018.

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

    anczak23 Trainee Engineer

    Messages:
    6
    Hi everyone,

    I've managed to write this script below which works.... once. the idea is when a button is pressed the rotor moves in that direction by 1 degree from its last position.

    Currently the first time you run the block it will set the min and max limits like it should and changes the velocity to positive. For some reason though, the second, third, fourth time the block is run, nothing changes. I'm stumped any help would be greatly appreciated...

    Code:
    public Program()
    
    {
    
    
    }
    
    
    
    public void Save()
    
    {
    
    
    }
    
    
    
    public void Main(string argument, UpdateType updateSource)
    
    {
    
    
    	var pitch_up_program_block = GridTerminalSystem.GetBlockWithName("Pitch Up Program Block") as IMyProgrammableBlock;
    
    //PITCH 1 VARIABLES
    	var light_pitch_1_rotor = GridTerminalSystem.GetBlockWithName("Spotlight Pitch Rotor 1") as IMyMotorStator;
    	float light_pitch_1_position = light_pitch_1_rotor.Angle;
    	
    //set rotor max limit to angle + 1 degree
    light_pitch_1_rotor.SetValue<float>("UpperLimit", (light_pitch_1_position + 1f));
    
    //set rotor min limit to angle
    light_pitch_1_rotor.SetValue<float>("LowerLimit", light_pitch_1_position);
    
    //set rotor velocity to positive 1rpm
    light_pitch_1_rotor.SetValue<float>("Velocity", 1);
    }
    
    
     
  2. Sinbad

    Sinbad Senior Engineer

    Messages:
    2,788
    this info might help:
    thats the exposed definitions for the IMyMotorStator interface.

    you use them in this syntax:

    to get a value use
    float YourVariableName = ThisRotor.UpperLimitDeg;

    to set a value use
    ThisRotor.UpperLimitDeg = YourVariableName

    hope that helps.



     
    Last edited: Jul 14, 2018
Thread Status:
This last post in this thread was made more than 31 days old.