Jump to content

Search the Community

Showing results for tags 'scripting'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements
    • Welcome Aboard
  • Kerbal Space Program 2
    • KSP2 Dev Updates
    • KSP2 Discussion
    • KSP2 Suggestions and Development Discussion
    • Challenges & Mission Ideas
    • The KSP2 Spacecraft Exchange
    • Mission Reports
    • KSP2 Prelaunch Archive
  • Kerbal Space Program 2 Gameplay & Technical Support
    • KSP2 Gameplay Questions and Tutorials
    • KSP2 Technical Support (PC, unmodded installs)
    • KSP2 Technical Support (PC, modded installs)
  • Kerbal Space Program 2 Mods
    • KSP2 Mod Discussions
    • KSP2 Mod Releases
    • KSP2 Mod Development
  • Kerbal Space Program 1
    • KSP1 The Daily Kerbal
    • KSP1 Discussion
    • KSP1 Suggestions & Development Discussion
    • KSP1 Challenges & Mission ideas
    • KSP1 The Spacecraft Exchange
    • KSP1 Mission Reports
    • KSP1 Gameplay and Technical Support
    • KSP1 Mods
    • KSP1 Expansions
  • Community
    • Science & Spaceflight
    • Kerbal Network
    • The Lounge
    • KSP Fan Works
  • International
    • International
  • KerbalEDU
    • KerbalEDU
    • KerbalEDU Website

Categories

There are no results to display.


Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Skype


Twitter


About me


Location


Interests

Found 4 results

  1. I'm trying to make a quadcopter that's actually flyable intuitively, and to that end I'm developing a kOS script to control it. I'm using the Breaking Ground rotors and controlling them using their max RPM fields. Here's the code: // Fly-by-wire for a quadcopter // Declare variables representing the four motors, which are tagged set frontLeft to ship:partsTagged("front left")[0]. set frontRight to ship:partsTagged("front right")[0]. set rearLeft to ship:partsTagged("rear left")[0]. set rearRight to ship:partsTagged("rear right")[0]. // Use setField(rpmLimit) set frontLeftThrottle to frontLeft:getModule("ModuleRoboticServoRotor"). set frontRightThrottle to frontRight:getModule("ModuleRoboticServoRotor"). set rearLeftThrottle to rearLeft:getModule("ModuleRoboticServoRotor"). set rearRightThrottle to rearRight:getModule("ModuleRoboticServoRotor"). set motors to list("frontLeft", "frontRight", "rearLeft", "rearRight"). function throttleMotor { parameter motor, throt. // throt is a float between 0 and 1 if motor = "frontLeft" { frontLeftThrottle:setField(throt * 460). } else if motor = "frontRight" { frontRightThrottle:setField(throt * 460). } else if motor = "rearLeft" { rearLeftThrottle:setField(throt * 460). } else if motor = "rearRight" { rearRightThrottle:setField(throt * 460). } else { // Catch-all, this should never happen print("Error: invalid motor!"). } } function calcMotorSpeed { // Make the speed of each motor proportional to the main throttle plus the input from steering set rotorSpeed to 230 * pilotMainThrottle. set speedOffset to rotorSpeed * 0.25. // Pitch: If negative, front rotors slow down and rear rotors speed up // If positive, front rotors speed up and rear rotors slow down // This happens until the measured pitch is +/- 15 degrees, // at which point the four motors briefly change speed to stop the pitch // If zero, reverse pitch until forward speed is zero set pitchOutput to list(0, 0, 0, 0). if pilotPitch = -1 { set pitchOutput[0] to -speedOffset. set pitchOutput[1] to -speedOffset. set pitchOutput[2] to speedOffset. set pitchOutput[3] to speedOffset. } else if pilotPitch = 1 { set pitchOutput[0] to speedOffset. set pitchOutput[1] to speedOffset. set pitchOutput[2] to -speedOffset. set pitchOutput[3] to -speedOffset. } else { // Reverse outputs until measured forward speed is zero, then set all input offsets to 0. } // Yaw: If negative, front left and rear right rotors speed up, and rear left and front right rotors slow down // If positive, front right and rear left rotors speed up, and rear right and front left rotors slow down // If zero, set all rotors to equal speed. set yawOutput to list(0, 0, 0, 0). if pilotYaw = -1 { set pitchOutput[0] to -speedOffset. set pitchOutput[2] to -speedOffset. set pitchOutput[1] to speedOffset. set pitchOutput[3] to speedOffset. } else if pilotYaw = 1 { set yawOutput[0] to speedOffset. set yawOutput[2] to speedOffset. set yawOutput[1] to -speedOffset. set yawOutput[3] to -speedOffset. } else { set yawOutput[0] to 0. set yawOutput[1] to 0. set yawOutput[2] to 0. set yawOutput[3] to 0. } // Roll: If positive, left rotors speed up and right rotors slow down // If negative, left rotors slow down and right rotors speed up // This happens until the measured roll is +/- 15 degrees, // at which point the rotors briefly change speed to stop the roll // If zero, reverse roll until lateral speed is zero set rollOutput to list(0, 0, 0, 0). if pilotRoll = -1 { set rollOutput[0] to -speedOffset. set rollOutput[2] to -speedOffset. set rollOutput[1] to speedOffset. set rollOutput[3] to speedOffset. } else if pilotPitch = 1 { set rollOutput[0] to speedOffset. set rollOutput[2] to speedOffset. set rollOutput[1] to -speedOffset. set rollOutput[3] to -speedOffset. } else { // Reverse outputs until measured forward speed is zero, then set all input offsets to 0. } // Total: Sum all inputs and that's the final output. set totalOutput to list(0, 0, 0, 0). for element in pitchOutput { set totalOutput[element] to pitchOutput[element] + yawOutput[element] + rollOutput[element] + rotorSpeed. } for m in motors { throttleMotor(m, totalOutput[indexOf(m)]). } } I have yet to implement the auto-leveling, which I have no idea how to do. How do real drones pull it off?
  2. Does Mechjeb allow scripting or ai control of a vessel? I want to have them scripted so I only need to record and move the camera. Like go up or something like nodes and do the bd armory guard mode?
  3. This thread can now be used for development discussion. Release thread is now here instead.
  4. LaserDist LaserDist v1.4.0 for KSP 1.10x. and KSP 1.11.x The only real change here is compiling against KSP 1.10.x DLLs and support for putting LaserDist parts inside the new KSP inventory system. The KSP 1.11.x updates added an EVA inventory system for parts and they require parts have a new "ModuleCargoPart" section added to its Part.cfg files to use it. This release also works on the previous KSP version, KSP 1.10.x too, but it may cause a startup complaint (which it is safe to ignore) in the logs on KSP 1.10.x when it sees the new "ModuleCargoPart" section in the config files. LaserDist v1.3.0 for KSP 1.8.1 Why does this Mod exist? The intended purpose of this part is to be used in conjunction with scripted autopilots like [kOS](https://github.com/KSP-KOS/KOS/releases), to provide a way to for you to write scripted pilot software that can see the distance to the ground (or anything else like a ship) along the laser line. See the image in the picture album to see what its meant by this.The reason this can be useful is so you can detect things like terrain slope and mountains in the way. The default radar altimiter in KSP only shows you the distance directly under the craft. Hey, where'd the pictures go? This post used to contain some embedded images illustrating what LaserDist looks like. They no longer appear because I no longer want to support the IMGUR site due to their awful willingness to let advertisers run whatever Javascript they feel like without properly vetting it for safety. So I pulled my albums off that site. Too many random ad redirects and browser-hijackings on that site for me. If KSP forums support some other image hosting site, I may put the images back but I don't know at the moment how to get the forum to use anything other than IMGUR.\ KSP 1.8 update. No changes to Laserdist except API usage with KSP 1.8. KSP 1.8 deprecated some API calls, replacing them with alternate versions. In particular, the shader used with LineRenderer to draw the laser lines needed to be built with a new kind of constructor. The V1.1.0 update: Another go at fixing the phantom hits bug. See: https://github.com/Dunbaratu/LaserDist/pull/24 The V1.0.0 update: I believe I have finally fixed the phantom hit problems (I found that Squad changed a few of the layer numbers in 1.2.2. My raytracing calls were giving phantom hits to the UI elements and the map view's planets because the layermask that worked fine in 1.1 wasn't right for 1.2.2.) Since the phantom hits problem was the main thing making me consider the mod "not ready", and tha'ts been fixed - I now am moving it to version 1.0. (1.0 also includes a few minor tweaks to the laser visual animation you should barely notice.) Releases, from major download sites: http://mods.curse.com/ksp-mods/kerbal/246141-laserdist https://spacedock.info/mod/765/LaserDist https://github.com/Dunbaratu/LaserDist/releases ZIP Download (See release page above): Source Code Hosting site: * https://github.com/Dunbaratu/LaserDist License: * GPL v3 Copyright (C) 2014,2015,2016 Steven Mading (aka Dunbaratu on Github) [email protected] 100x model This is a very small plugin. It makes a KSP Part that measures straight line distances by laser. The "Beamer 100x Disto-o-meter" Part aims a laser in a lin and then measures the distance in meters to the first object the laser hits. The result is displayed in the right-click menu for the part and can be read by kOS (and other?) script mods. 200x model The "Beamer 200x Bendable Disto-o-meter" Part is the same as the 100x part described above, but it lets you choose a deflection angle with the "Bend X" widget on the slider, (or by using SETFIELD in kOS on it), and the laser can dynamically change it's aim along this one axis. 500x model The "Beamer 500x Aimable Disto-o-meter" Part is the same as the 200x part described above, but it lets you bend the laser in two different axes, to aim it whereever you like within a zone, using both "Bend X" and "Bend Y" settings. All models: The laser can work over long distances - here it's measuring the distance from a Kerbin orbit vessel to the Mun: The direction of the laser is whichever way the laser gun is pointed when you mounted it on the craft. ### Information about the data fields the part displays: ![LaserDist Rightclick panel 1](rightpanel.png) KSPField: 'Distance' is a float - the number of meters being shown in the display. It's -1 if there is currently no hit. KSPField: 'Hit' is a string - the name of the object being hit. KSPField: 'Enabled' is a bool - true if the measuring device is on. KSPField: 'Visible' is a bool - true if the laser should be drawn when it's activated or false if it should be (realistically) invisible because, hey, it's coherent light and it's not supposed to be seen from the side. KSPField: 'CPUGreedyPercent' is a float (called "CPU hog" in the GUI) ranging from 0.0 to 20.0. It's how much of a single physics tick of time this mod will allow itself to consume during a single Update. If it hasn't gotten a good enough answer within that much time, it will wait until the next update to continue the calculation. KSPField: 'UpdateAge' is an integer - It's how many Unity Updates (animation frames, basically) it's been since the value you are seeing was calculated. Because of the logic of CPUGreedyPercent (see above) sometimes the value being displayed is stale by a few update ticks and shouldn't be trusted until the next time that UpdateAge becomes zero again. If you're in a situation where this mod needs to spend more than 1 update of time to get to a good answer for the distance, you'll see this value spinning a bit, quickly going 0,1,2,3,0,1,2,3,0,1,2,3...etc. When you see that, only when it hit the zeros was the distance value perfectly correct at THAT moment. KSPField: 'Bend X' is a float - the number of degrees the laser is deflected in its relative Yaw direction, if it's the type of laser that can be deflected. KSPField: 'Bend Y' is a float - the number of degrees the laser is deflected in its relative Pitch direction, if it's the type of laser that can be deflected. KSPField: 'Max Bend X' is a float - the range of bending the laser can do in its relative Yaw direction. If this is zero, then the laser cannot bend that way. The range is always centered at zero, plus or minus this number. KSPField: 'Max Bend Y' is a float - the range of bending the laser can do in its relative Pitch direction. If this is zero, then the laser cannot bend that way. The range is always centered at zero, plus or minus this number. Note: The higher that CPUGreedyPercent ("CPU hog") is, the less likely it is that UpdateAge will ever be nonzero, but the bigger hit your framerate might take. ### How to Mount it. ![icon of Electronics node](http://wiki.kerbalspaceprogram.com/w/images/d/dd/Electronics.png). The Beamer 100x Dist-o-Meter is located in the "Electronics" tech node of the career tech tree. It's a 300-point node on the tree so you might not have it yet in a new fresh career game. It appears in the science tab of the parts bin. The Laser can be mounted anywhere as a surface-mount item. Take care to note the orientation of the laser emiiter. (KSP lets you fine-tune the rotation of a part by using the SHIFT key while you hit the WASDQE keys.) The Laser will bounce back and give you a distance measurement when it encounters *ANY* object, including parts of your own craft. So take care to mount it somewhere where the laser beam will have a clear line of sight without obstruction. To ensure a good mounting point, you can use "tweakables" to enable the laser and make it show up in the VAB to look and see if you have it aimed well. ### Lightspeed Note that if you use it to measure the distance to a far away body (i.e. like aiming it at Duna from Kerbin), the mod does take into account lightspeed. You have to hold the laser on an object steady and unchange for the entire duration of time it takes for lightspeed delay to bounce the signal back or you won't get a measurement, so using it at that great distance will be very hard. ### How do I use it from my script then? Quick synopsis: Getting a handle on the laser, then turning on the laser using that module: SET laser_module TO SHIP:MODULESNAMED("LaserDistModule")[0]. IF not laser_module:GETFIELD("Enabled") { laser_module:SETFIELD("Enabled",true). } Getting a reading from the laser: SET laser_module TO SHIP:MODULESNAMED("LaserDistModule")[0]. PRINT "Laser distance is measuring " + laser_module:GETFIELD("Distance") + " meters." PRINT "Laser is hitting: " + laser_module:GETFIELD("Hit"). Transforming the laser reading into a 3-D co-ordinate: The part model is designed such that emitter of the laser line is located exactly at the part's local transform origin position, aimed along the part's ``facing:vector`` unit vector, allowing you to get its 3D vector position from a script like so, *Provided you haven't bent the laser with the ``"Bend X"`` or ``"Bend Y"`` settings. If you have bent the laser, then you need to apply these offset angles yourself with an ANGLEAXIS rotation in kOS*: SET laser_module TO SHIP:MODULESNAMED("LaserDistModule")[0]. set dist to laser_module:GETFIELD("Distance"). set emitter_position to laser_module:part:position. set emitter_unit_vec to laser_module:part:facing:vector. set laser_hit_position to emitter_position + (dist * emitter_unit_vec). Laser_hit_position is now a 3D vector position of where the laser hit something To do the same general thing but when the ``Bend X`` and ``Bend Y`` fields are nonzero, rotate the vector around the part's facing unit vectors: SET laser_module TO SHIP:MODULESNAMED("LaserDistModule")[0]. set dist to laser_module:GETFIELD("Distance"). set emitter_position to laser_module:part:position. set emitter_center_vec to laser_module:part:facing:vector. set x_bend to laser_module:GETFIELD("Bend X"). set y_bend to laser_module:GETFIELD("Bend Y"). set bending_rotation to angleaxis(x_bend, laser_module:part:facing:topvector) * angleaxis(y_bend, laser_module:part:facing:starvector). set emitter_unit_vec to bending_rotation * emitter_center_vec. set laser_hit_position to emitter_position + (dist * emitter_unit_vec). . ### Part modeling help? I am aware that the artwork on the model isn't pretty. I'm a programmer, not a graphic artist, and I don't have experience with things like Maya and Blender. In fact I just made the model by slapping together some stretched Cube and Cylnder objects in Unity itself, without the aid of a modeling program. The model is good enough to work with, but I'd be happy to have someone better at art redesign the model. I included the model in the github directory if you want to have a look.
×
×
  • Create New...