Hm, looks interesting. I'll test it out when I get home later.
First off, bear with me, this is my first contraption in wiremod of any decent size. I use four expression chips that I wrote, 14 wire thrusters, one gyroscope, a button, and an advanced pod controller. I call it Version 2 btw as I had a Version 1 but it wasn't nearly as good, it bounced around a lot.
Now first off let me explain the controls. W, A, S, and D move you left right and forward backward. Left and Right mouse button rotate. Shift and Alt move you up and down. Spacebar turns on and off rotation breaking, R turns on and off Movement breaking. The Reset button resets the learned values back to 0.
What I mean by learning is that it will sense if it is off from being at perfectly flat or perfectly at the specified altitude and will continue to fudge it until it comes into place. This gets to the specified altitude or angle within 10 seconds or so out to within 3 decimal places. So if you stand on it it will even out to be flat even with you standing on one side of it. This works well enough that I have 4 white blocks on the platform such that you can change the weight from 1 to 1000 on one corner and it will rapidly go back to flat. It does the same thing for altitude.
What I mean by breaking is that when it is on if no input is being put in of that kind then it will rapidly break all motion of that kind. The spin, forward-back, and left-right are each each separate. So if you are holding down both W and S and moving diagonally like that and you let go of Left then it will break all horizontal movement while you continue to move forward.
Also one warning, it doesn't like being frozen. I put in some code to mitigate it but if you freeze it very near (or at) completely flat and almost exactly at the altitude it is trying to get to the learning code keeps trying to adjust itself and it cant so it keeps increasing and increasing. So if you do freeze it at flat, before you use it, it is suggested you hit the reset button otherwise it will be temporarily crazy as it quickly readjusts itself.
Here is the code for my expression chips. I am sorry that it is uncommented but if anyone has questions just ask. Anyone is welcome to use the chips or modify them. You don't have to tell me, but I would appreciate it if you told me when you do so. All this code is mine but I took inspiration from random bits of code I used to learn from.
I welcome any suggestions for improvement or critiques anyone has.
Roll Control v2
Inputs: Roll - Roll from an input gyroscope. ExOn - Reset button.
Outputs: ThrustR - Thrust to right side thruster. ThrustL - Thrust to left side thruster.
N@Roll Control v2
I@Roll ExOn
O@ThrustR ThrustL
interval(20)
first() -> RBalance = 0;
(!ExOn & ~ExOn) -> RBalance = 0;
clk() ->
Roll > 0 -> RollNew = Roll - 180;
Roll < 0 -> RollNew = Roll + 180;
Roll == 0 -> RollNew = 180;
ThrustL = 0, ThrustR = 0, Smoother = 10
abs($RollNew) < 0.1 & !($RollNew == 0 & abs(RollNew) > 1) -> RBalance += 0.01 * RollNew;
ThrustR = RollNew + RBalance + $RollNew * Smoother
ThrustL = -ThrustR;
Pitch Control v2
Inputs: Same as above (but with pitch)
Outputs: Same as above (but front and back)
N@Pitch Control v2
I@Pitch ExOn
O@ThrustF ThrustB
interval(20)
first() -> PBalance = 0;
(!ExOn & ~ExOn) -> PBalance = 0;
clk() ->
ThrustF = 0, ThrustB = 0, Smoother = 10
abs($Pitch) < 0.1 & !($Pitch == 0 & abs(Pitch) > 1) -> PBalance += 0.01 * Pitch;
ThrustF = Pitch + PBalance + $Pitch * Smoother
ThrustB = -ThrustF;
Altitude Control v2
Inputs: Up - Up key from pod controller. Down - Down key from pod controller. Fast - Unused on my platform, but increases up down speed by 10 when held down and also going up or down. ExOn - Same ExOn as above.
Outputs: Thrust - Thrust to the four downward thrust thrusters.
N@Altitude Control v2
I@Up Down Fast ExOn
O@Thrust
interval(20)
Smoother = 10, Speed_smth = 500, Speed = 200
first() -> ZBalance = 0, Target = round(extposz() / (Speed * 0.02)) * (Speed * 0.02);
!ExOn & ~ExOn -> ZBalance = 0;
clk() ->
Fast -> Speed *= 10;
Target += Speed * 0.020 * (Up - Down)
Zloc = extposz(), Dist = Target - Zloc
Thrust = Dist + ZBalance + -$Zloc * Smoother
abs($Zloc) > 5 -> Thrust += -$Zloc * Speed_smth;
abs($Zloc) < 0.1 & !Up & !Down & !($Zloc == 0 & abs(Dist) > 1) -> ZBalance += 0.01 * Dist;;
Yaw and Movement Control v2
Inputs: Inputs labeled with their output names from adv pod controller are obvious. Yaw - Input Yaw from Gyroscope. Yaw_In - The key for turning on and off Yaw Breaking. Thrust_In - The key for turning on thrust breaking.
Outputs: YawR - Output to Yaw Thrusters. Forward - Thrust to the thruster that makes you move forward (the one in the back). Back - Thrust to the thruster that makes you move back (the one in the front). Same for Right and Left (reversed like that).
N@Yaw and Movement Control v2
I@W A S D Mouse1 Mouse2 Yaw Yaw_In Thrust_In
O@YawR Forward Back Right Left
interval(20)
first() -> Yaw_Break = 0, Thrust_Break = 0, Yaw_last = Yaw, Test = 0;
~Yaw_In & Yaw_In -> (Yaw_Break ? Yaw_Break = 0 : Yaw_Break = 1);
~Thrust_In & Thrust_In -> (Thrust_Break ? Thrust_Break = 0 : Thrust_Break = 1);
clk() ->
X = extposx(), Y = extposy(), Forward = 0, Back = 0, Left = 0, Right = 0
(Mouse1 | Mouse2 | !Yaw_Break ? YawR = Mouse2 - Mouse1 : YawR = $Yaw)
New_Y_chg = cos(Yaw) * $X + sin(Yaw) * $Y
New_X_chg = sin(Yaw) * $X + cos(Yaw) * -$Y
(W | S | !Thrust_Break ? Forward = W - S : Forward = -New_Y_chg)
Back = -Forward
(D | A | !Thrust_Break ? Right = D - A : Right = -New_X_chg)
Left = -Right;
Advanced Duplicator Save is included. Highly suggest that you use it instead of trying to reuse the chips.
Edit: Updated my hover platform slightly. The chips are exactly the same except a very few slight modifications (added some outputs of values that were already there). Outputed those values to 5 Wire HUD Indicators so when you get in you can see your current Pitch, Roll, Yaw, Target Altitude, and current Z Altitude. Also made an online version that is slightly modified with a few less thrusters (14 down to 10) so that it can be uploaded on to servers and used without the server removing thrusters. Also removed thruster effects for online version. (I might add it doesn't work quite as well, little more sluggish, but other than that it is fine.)
Last edited by Ergzay; 05-22-2008 at 05:17 PM. Reason: Put the $ back again
Hm, looks interesting. I'll test it out when I get home later.
That sure is a lot of code just to make something hover? Or maybe i'm missing something... do you have a video?
- Drew
It isn't just hovering. It has Yaw breaking as well as movement breaking. More so movement breaking only in the directions you aren't currently moving in. And even more than that it has a self balancer, so you can through on 1000 weight on a corner and after a few seconds it will learn the weight and make it go back to level, although with that much weight to one side it doesn't move straight anymore, but it does stay level.
No sorry no video. I've only been using Gmod for a week or two here so don't know many of the details on how people make videos and such. (I have used Gmod some before but not in over a year and it was at a friend's house and on my computer for 30 days.)
To see how well it balances modify the altitude control to output the Target and Zloc values and then hook up a debugger. Also hook up the debugger to the gyroscope to see how accurate it gets.
I will probably be updating it more later to make it stay on course when its unbalanced in terms of tons of weight on a corner and also add more nifty features like autopilot (fly to GPS coords).
Last edited by Ergzay; 05-20-2008 at 09:06 AM.
Umm I jsut realized something. Are those attached files loading for anyone? I get linked to a "clear.gif" file that is a 1x1 white pixel.
Same... coming up as a gif file.
- Drew
I think the attachments may have gotten left behind after the server move? I'll reupload them.
Edit: Okay, fixed. Should work now.
Edit2: Oh great, it seems that the forums have chopped out the $ signs out of the code... Attachments should be fine though.
Edit3: I put them back.
Last edited by Ergzay; 05-20-2008 at 03:09 PM.
On phone at school but I'll check this stuff out when i get home.
[I][SIZE="2"]intel e6750 2.66 ghz
bfg 8800gt oc
2 gb G.Skill ram
750w psu
250 gb hd
22'' LG 1680x1050
ms sidewinder
windows xp
[/SIZE][/I]
I modified my original post with an added edit. Here is the text I posted.
I should add I am currently working on a version 3 that will add among other things: Pitch and Roll control with support for loop-de-loops and Roll spins. Vector thrusters for main thrusters so no matter your angle it will keep your altitude right. Trigonometry for, depending on your angle of pitch or roll, if you thrust forward or sideways while angling up or down it will change the target height by the downward or upward thrust thrust you did.Updated my hover platform slightly. The chips are exactly the same except a very few slight modifications (added some outputs of values that were already there). Outputed those values to 5 Wire HUD Indicators so when you get in you can see your current Pitch, Roll, Yaw, Target Altitude, and current Z Altitude. Also made an online version that is slightly modified with a few less thrusters (14 down to 10) so that it can be uploaded on to servers and used without the server removing thrusters. Also removed thruster effects for online version. (I might add it doesn't work quite as well, little more sluggish, but other than that it is fine.)
Edit: Wrong forum.
Last edited by Ergzay; 05-24-2008 at 05:02 PM.
Bookmarks