Space Engineers

Space Engineers

Twinkie's Rotor(s) Controller
50 Comments
LasrinPrime 8 Jun, 2024 @ 1:57am 
any way to use a single run command like "+45" so each button press advances the rotor 45 degrees?
Spaceman Spiff 29 Jan, 2021 @ 2:07pm 
Wow! (Slaps head!!) You rock, @CptTwinkie! I don't understand why I didn't get it. :steamhappy:
CptTwinkie  [author] 29 Jan, 2021 @ 11:49am 
1) it's C#
2) no, you don't need to change any of that. only change that true to false as I suggested
3) after the rotation finishes, just call the script with no argument and it will perform the stop function, freeing your rotors for whatever the other thing is
Spaceman Spiff 28 Jan, 2021 @ 3:42pm 
I appreciate the response and recommendation. Sadly, I am a neophyte when it comes to C++, so I'm lost where I should make the Stop(); call. I tried here, but it didn't work, i.e., the program doesn't do anything when it's called, so obviously I screwed it up.

//Loop through each rotor on the list
for (int i = 0; i < listRotors.Count; i++)
{
float setVelocity = 0f;

if (listRotors .RotorLock)
listRotors .RotorLock = false;

float curAngle = RadiansToDegrees(listRotors .Angle);
if (curAngle == setAngle)
return;

setVelocity = (curAngle < setAngle) ? (float)desiredVelocity : -(float)desiredVelocity;

//Set the appropriate limit
if (setVelocity > 0)
listRotors .UpperLimitRad = DegreesToRadians(setAngle);
else
listRotors .LowerLimitRad = DegreesToRadians(setAngle);

//Set the velocity
listRotors .SetValue<float>("Velocity", setVelocity);
}
Stop(); <== ADDED
}

Help?
CptTwinkie  [author] 28 Jan, 2021 @ 11:08am 
Just taking a quick look at the stop function i would say change the lock to false and call that to set your unlimited values

void Stop()
{
//Loop through each rotor on the list
for (int i = 0; i < listRotors.Count; i++)
{
//Setting the angles to more than 360 sets them to unlimited <--- read
listRotors .SetValue<float>("LowerLimit", -361f);
listRotors .SetValue<float>("UpperLimit", 361f);

//Set velocity to 0
listRotors .SetValue<float>("Velocity", 0f);

//Lock
listRotors .RotorLock = true; <--- this guy here controls the lock, set it to false
}
}
Spaceman Spiff 27 Jan, 2021 @ 9:19pm 
I've built a deployable solar array with hinges, and solar rotors to work with Isy's Solar Alignment Script. The rotors rotate to the stow or deploy positions fine, but are left with angle settings still set whereas Isy's script wants "unlimited" on both ends to properly find the optimum angles. Is there a way to reset the rotor angles back to "unlimited" after your script runs, other than to cycle the increase/decrease angle command for the rotors using a timer block a bunch of times?
CptTwinkie  [author] 15 Dec, 2019 @ 7:25am 
The art of programming is managing complexity. Anyone can make code that works, but it takes dedication and experience to make code that is elegant.
Morphyxx 15 Dec, 2019 @ 6:50am 
I just wanna say that yours worked first try and is one of the best rotor scripts out there. Every other one is SUPER frigin complicated but yours was way easier to understand. So i just wanna say thank you for this script and im going to link your work in the description of the world when im done with it.
Morphyxx 15 Dec, 2019 @ 6:41am 
Thanks man
CptTwinkie  [author] 15 Dec, 2019 @ 6:39am 
AstroByte_YT, it's on the workshop to be shared. Use it for anything you like
Morphyxx 14 Dec, 2019 @ 8:13pm 
Am i aloud to use this in a huge project of mine? Its called moon base 111 and i wanted to know if i could use it for a metro station to spin a train to each different section of the base.
CptTwinkie  [author] 12 Nov, 2018 @ 10:41am 
You could add some code for lights. In the normal part of the script add code to turn on lights. In the stop method add the code to turn them off. You will still have to run the script twice at proper intervals. I think mainly what you're looking for is more of a controller style script that runs regularly or as-needed somehow. This script isn't designed to work that way. You could maybe set up some kind of logic with some timer blocks though. Have timer 1 run the script with an angle and start the countdown on timer 2. Have timer 2 run the script with no argument to lock the rotors after an appropriate amount of time. It could mean a lot of setup if you want anything complex but it will work.
Olaf81 12 Nov, 2018 @ 10:08am 
Okay thank you, i think, i understand now. I try to learn how to write a script and i use your script as an example.
That your script has nothing to do with lights, i know. I was like to add this function. I use your script for opening and closing a big door and my idea was that a light turns red when the rotors are moving and when they are stoping it turns again white or turns off. I think now, with your script ver 1.3 or 1.2 was not possible. With the new one 1.4, i don't know, if my idea is possible with your script.
CptTwinkie  [author] 12 Nov, 2018 @ 3:20am 
Olaf81 that's not the way this script works. It runs only once and changes rotor settings immediately. If it locks the rotors then they won't be able to turn.

You have to wait until the rotors finish turning, then set the argument to empty (nothing) or the velocity to 0 and run it again. That will lock the rotors.

Also, it has nothing to do with lights so I'm not sure what you're trying to do with those.
Olaf81 11 Nov, 2018 @ 1:34pm 
Hello CptTwinkie,

i have another question. I noticed that your skript don't run until the end. The rotors are stopping moving but only because of the set upper or lower limit. After running the skript i see, that the velocity is still set and the rotor is not locked. I think correct should be, that the rotors are locked after running.
I was like to control also some lights with your skripts, but it was not working, that's why i saw.
CptTwinkie  [author] 11 Nov, 2018 @ 2:48am 
Ok, I tested it. v1.4 is working just fine with -100 for many rotors. I'm happy to take a look at your world if you want.
CptTwinkie  [author] 11 Nov, 2018 @ 2:40am 
That's what it was doing for me before I updated it. It doesn't do it for me anymore though. I'll try it with -100 just to make sure
toddlerself 10 Nov, 2018 @ 4:00pm 
Unfortunately, I'm still having the same problems. I'm using two rotors each with their own PB. One of them moves in both directions. One of them refuses to move counterclockwise even though I'm wanting it to move only 100 degrees. It either wants to move clockwise 260 degrees instead or it doesn't move at all. It doesn't matter if I use a positive or negative velocity. Regardless, I appreciate your efforts to fix it. I know it's not your fault when a game patch breaks scripts.
CptTwinkie  [author] 10 Nov, 2018 @ 11:58am 
UPDATED! Even with velocity mixups, it wasn't working properly. There is some incorrect documentation and a couple of methods behaving incorrectly in the API. I was able to work around them.
CptTwinkie  [author] 10 Nov, 2018 @ 2:53am 
The script wasn't meant to take negative velocities. It figures out direction on its own from the angle you provide.
toddlerself 9 Nov, 2018 @ 9:31pm 
It seems to be an issue only if you set a negative velocity. They move in one direction just fine, but if you want them to move counterclockwise you are out of luck.
toddlerself 9 Nov, 2018 @ 8:52pm 
This isn't working for me at all. The rotors move in random directions and sometimes don't move at all. Every time I trigger the timer block they behave differently, even though I didn't change anything. I'm playing offline so it's not a server/connectivity issue.
Olaf81 31 Oct, 2018 @ 12:08pm 
Thank you very very much. I will try now.:-)
CptTwinkie  [author] 30 Oct, 2018 @ 2:38pm 
UPDATED!!!
Olaf81 30 Oct, 2018 @ 1:46pm 
Thank you very much. I tried by myself, but i have not much experience with programming and didn't find a good guide for beginners.
CptTwinkie  [author] 30 Oct, 2018 @ 1:25am 
yeah, it looks like my rotor (and hinge...and piston) scripts need to be updated. I've had them on my todo list (literally) for a week. I've just had other things to work on. If I don't get to them this week then I'll try to look at them Saturday.
Olaf81 29 Oct, 2018 @ 2:47pm 
Hello CptTwinkie,

is this script still working? In the past I used it and it was working fine and i liked very much. When i run it now it tells me "index was out of the bounds of the array". Can you help?
dichebach 31 Aug, 2018 @ 8:37am 
Well I got Malware's MDK.vsix configured to play nice with VS so I'm good to tinker now! Thanks for the suggestion @CptTwinkie. I will check out that mod.

Another option I'm gonna try is to update this guys Universal Rotor and Piston Sync script so that it runs with the current API https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=404120497

Most of my couple years training and practice are in C++, but writing little snippets of C# to make things do fun stuff in SE seems like a good way to gently start learning some C#
CptTwinkie  [author] 31 Aug, 2018 @ 1:39am 
@dichebach with this script you would need two programming blocks and a way to trigger them both at the same time (a timer maybe). It would be easier to just set limits on the rotors and use the timer or a group to reverse their direction.

This situation is not really ideal. I would recommend checking out the hinge mod. I have a script for that as well. The idea is that the hinges would both face the same direction and move to the same angles. That way you can set them both from a single PB using my hinge script. The advantage here would be that you could pass any angle into the script to achieve fine control.
dichebach 30 Aug, 2018 @ 4:51pm 
I got a mining machine with two long forward facing arms with drills. https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=1498024844 Want to program them so that one key (1) causes both arms (mounted on sides of truck) to go up (to a limit of say 35), and one key (2) causes both arms to go down. Not sure this script will do what I need, but seems like I can at least learn a bit about how the in game scripts work and make some progress toward getting my own running.
Splitsie 16 Jun, 2018 @ 6:06pm 
I'm so happy I found this script - best way to control a turntable for a roundhouse style parking area :)
Skallabjorn 14 Feb, 2017 @ 8:44am 
thumbs up, I will mess with it abit too here if thats ok we can compare notes later.
CptTwinkie  [author] 14 Feb, 2017 @ 6:02am 
Yeah the conditional logic is not intuitive because of the check methods available in System.Double. That's why i want to test it to make sure it actually works
Skallabjorn 13 Feb, 2017 @ 5:59pm 
Nice, let me know how it turns out, this is what I used your script for btw... reseting the solar panels to 0 after they had been tracking the sun. they retract to the sides of the ship so that it can continue on...small and large versions of the ship... they need to go back to unlimited to be able to track properly next deployment... thus the change or in my case the extra block

https://www.youtube.com/watch?v=w03cTM35SaY
CptTwinkie  [author] 13 Feb, 2017 @ 4:08pm 
I wrote an update for the script but I want to test it and try to clean up the code a little before I publish it.
Skallabjorn 13 Feb, 2017 @ 3:24am 
actually, I sussed it out ( with some help ), this run in a separate block did the trick. Values over or under 360 force it to go unlimited

void Main()
{
List<IMyTerminalBlock> blocklist;
blocklist = new List<IMyTerminalBlock>();
GridTerminalSystem.SearchBlocksOfName("Rotor 1b", blocklist);
blocklist[0].SetValue("LowerLimit",(float)-361);
blocklist[0].SetValue("UpperLimit",(float)361);
GridTerminalSystem.SearchBlocksOfName("Rotor 2b", blocklist);
blocklist[0].SetValue("LowerLimit",(float)-361);
blocklist[0].SetValue("UpperLimit",(float)361); }
CptTwinkie  [author] 13 Feb, 2017 @ 12:00am 
Off the top of my head I'd make it accept a command with no argument that would set those values. I'm getting ready for work now but maybe I can look at it tonight
Skallabjorn 11 Feb, 2017 @ 6:56pm 
Specific to my previous, where in your code would you insert this and what changes to make it reset to unlimited once the rotors have hit say Zero??

rotor.SetValue("LowerLimit",(float)-361);
rotor.SetValue("UpperLimit",(float)361);
Skallabjorn 11 Feb, 2017 @ 6:26pm 
This script is great, except one thing I noticed, is there any way to get it to reset the upper and lower limits back to unlimited when its done? i as as I use it on a set of rotors to reset them back to zero so that they can fold up into the ship ( solar aray 0 and it works fantastic, but once I have re delpoyed them, i need to maunaly rsset back to unlimited so thatthe solar tracking will function again. any thoughts?
CptTwinkie  [author] 14 Oct, 2016 @ 3:03am 
yeah, the script is older than the safety locks. it doesn't take that into account at all.
E-Man720 13 Oct, 2016 @ 3:42pm 
Because I have that happen on my D-57 when I don't unlock them. https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=779486933
E-Man720 13 Oct, 2016 @ 3:41pm 
You don't have the rotor, saftey locked?
Ardjuhh 13 Oct, 2016 @ 12:42pm 
I haven't changed the name, the rotor hasn't been changed whatsoever.
CptTwinkie  [author] 13 Oct, 2016 @ 6:39am 
Is something changing the name of your rotors or making them blow up? The only reason for that error is that one or more of the rotors is no longer available.
Ardjuhh 13 Oct, 2016 @ 4:03am 
I have a problem with this script, the script runs smoothly the first time. The second time (with another argument), i get an exception: "Object reference not set to an instance of an object."
kris220b 7 Sep, 2016 @ 3:22am 
oh cool
thanks
CptTwinkie  [author] 7 Sep, 2016 @ 3:18am 
yes, you can make as many pre-set angles as you like
kris220b 2 Sep, 2016 @ 9:40am 
so me not intirely understanding your comment reply
this means i can have my artillery have pre-set fireing angles at every 5 degrees?
CptTwinkie  [author] 11 Mar, 2016 @ 6:24pm 
Yep, that's why I set it up that way. You can set up one programing block for your rotor or group of rotors. Then you can add it to the toolbar as many times as you like with different arguments.
E-Man720 11 Mar, 2016 @ 5:42pm 
Can you set up multiple arguments with different angles?