Space Engineers

Space Engineers

Twinkie's Rotor(s) Controller
50 条留言
LasrinPrime 2024 年 6 月 8 日 上午 1:57 
any way to use a single run command like "+45" so each button press advances the rotor 45 degrees?
Spaceman Spiff 2021 年 1 月 29 日 下午 2:07 
Wow! (Slaps head!!) You rock, @CptTwinkie! I don't understand why I didn't get it. :steamhappy:
CptTwinkie  [作者] 2021 年 1 月 29 日 上午 11:49 
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 2021 年 1 月 28 日 下午 3:42 
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  [作者] 2021 年 1 月 28 日 上午 11:08 
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 2021 年 1 月 27 日 下午 9:19 
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  [作者] 2019 年 12 月 15 日 上午 7:25 
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 2019 年 12 月 15 日 上午 6:50 
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 2019 年 12 月 15 日 上午 6:41 
Thanks man
CptTwinkie  [作者] 2019 年 12 月 15 日 上午 6:39 
AstroByte_YT, it's on the workshop to be shared. Use it for anything you like
Morphyxx 2019 年 12 月 14 日 下午 8:13 
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  [作者] 2018 年 11 月 12 日 上午 10:41 
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 2018 年 11 月 12 日 上午 10:08 
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  [作者] 2018 年 11 月 12 日 上午 3:20 
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 2018 年 11 月 11 日 下午 1:34 
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  [作者] 2018 年 11 月 11 日 上午 2:48 
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  [作者] 2018 年 11 月 11 日 上午 2:40 
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 2018 年 11 月 10 日 下午 4:00 
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  [作者] 2018 年 11 月 10 日 上午 11:58 
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  [作者] 2018 年 11 月 10 日 上午 2:53 
The script wasn't meant to take negative velocities. It figures out direction on its own from the angle you provide.
toddlerself 2018 年 11 月 9 日 下午 9:31 
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 2018 年 11 月 9 日 下午 8:52 
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 2018 年 10 月 31 日 下午 12:08 
Thank you very very much. I will try now.:-)
CptTwinkie  [作者] 2018 年 10 月 30 日 下午 2:38 
UPDATED!!!
Olaf81 2018 年 10 月 30 日 下午 1:46 
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  [作者] 2018 年 10 月 30 日 上午 1:25 
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 2018 年 10 月 29 日 下午 2:47 
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 2018 年 8 月 31 日 上午 8:37 
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://psteamcommunity.yuanyoumao.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  [作者] 2018 年 8 月 31 日 上午 1:39 
@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 2018 年 8 月 30 日 下午 4:51 
I got a mining machine with two long forward facing arms with drills. https://psteamcommunity.yuanyoumao.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 2018 年 6 月 16 日 下午 6:06 
I'm so happy I found this script - best way to control a turntable for a roundhouse style parking area :)
Skallabjorn 2017 年 2 月 14 日 上午 8:44 
thumbs up, I will mess with it abit too here if thats ok we can compare notes later.
CptTwinkie  [作者] 2017 年 2 月 14 日 上午 6:02 
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 2017 年 2 月 13 日 下午 5:59 
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  [作者] 2017 年 2 月 13 日 下午 4:08 
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 2017 年 2 月 13 日 上午 3:24 
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  [作者] 2017 年 2 月 13 日 上午 12:00 
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 2017 年 2 月 11 日 下午 6:56 
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 2017 年 2 月 11 日 下午 6:26 
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  [作者] 2016 年 10 月 14 日 上午 3:03 
yeah, the script is older than the safety locks. it doesn't take that into account at all.
E-Man720 2016 年 10 月 13 日 下午 3:42 
Because I have that happen on my D-57 when I don't unlock them. http://psteamcommunity.yuanyoumao.com/sharedfiles/filedetails/?id=779486933
E-Man720 2016 年 10 月 13 日 下午 3:41 
You don't have the rotor, saftey locked?
Ardjuhh 2016 年 10 月 13 日 下午 12:42 
I haven't changed the name, the rotor hasn't been changed whatsoever.
CptTwinkie  [作者] 2016 年 10 月 13 日 上午 6:39 
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 2016 年 10 月 13 日 上午 4:03 
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 2016 年 9 月 7 日 上午 3:22 
oh cool
thanks
CptTwinkie  [作者] 2016 年 9 月 7 日 上午 3:18 
yes, you can make as many pre-set angles as you like
kris220b 2016 年 9 月 2 日 上午 9:40 
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  [作者] 2016 年 3 月 11 日 下午 6:24 
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 2016 年 3 月 11 日 下午 5:42 
Can you set up multiple arguments with different angles?