KSP-KOS / KOS

Fully programmable autopilot mod for KSP. Originally By Nivekk
Other
691 stars 229 forks source link

Perimeter detection with LIDAR/RADAR/Laser/Doppler #2907

Closed Skippern closed 3 years ago

Skippern commented 3 years ago

I have tried to make unmanned rovers go preset paths, but keep hitting obstacles on the route. There are no parts in the science tree that allows me to detect obstructions.

Perimeter detection will allow me to build rovers that avoid hitting obstacles, as well as pathfinder rovers that map out a larger area for possible safe paths.

thexa4 commented 3 years ago

This works pretty well for detecting obstacles: https://forum.kerbalspaceprogram.com/index.php?/topic/141697-ksp-1111-laserdist-a-distance-measuring-laser-part-for-kos-krpc-etc/

Skippern commented 3 years ago

Of course another Mod, I'll investigate it. Thanks for the tip.

Dunbaratu commented 3 years ago

Also, that other mod, LaserDist, is one also maintained by me, and it was explicitly designed because of kOS existing and the exact need you're talking about. If you want an example of how to call its PartModule in an actual script, check my rover driving routine here: https://github.com/Dunbaratu/kerboscripts/blob/master/lib/rover.ks

Start from line 106 (looking like the snippet below) where the lasers are detected and some bools are set, then look elsewhere in that file where these bools are queried (search for has_left_lasers for example) because that's where the code that uses the lasers gets invoked:

  set left_lasers to get_terrain_lasers(left_lasers_name).
  set has_left_lasers to left_lasers:length > 0.
  set right_lasers to get_terrain_lasers(right_lasers_name).
  set has_right_lasers to right_lasers:length > 0.
  set leveler_lasers to get_terrain_lasers(downward_lasers_name).
  set has_leveler_lasers to leveler_lasers:length > 0.
  all_lasers_toggle(true).
Dunbaratu commented 3 years ago

Just a warning, not LaserDist's fault necessarily, but because of a weird way KSP implemented the rover scanning arms from Breaking Ground, giving it phantom colliders but putting them on the same layer as the kinds of colliders that are physically real, LaserDist can sometimes return bogus answers if there's such a rover arm on the vessel, hitting a magic sphere around the scanner arm instead of a "real" object.

Dunbaratu commented 3 years ago

I'm going to close this as answered, but feel free to comment further if you think the above things don't sufficiently give you want you wanted.

Skippern commented 3 years ago

good to know so that I can plan where I place lasers and arms on the rover to minimize such bogus impacts.

Dunbaratu commented 3 years ago

It helps to put the lasers inside the bogus collider sphere, since the bogus collider sphere is "one sided" and only registers collisions from the outside going in, not from the inside going out. For more information on that problem, see this comment I made on SQUAD's own tracker, about another user having trouble because of this: https://bugs.kerbalspaceprogram.com/issues/26938#note-3