Welcome to Keen Software House Forums! Log in or Sign up to interact with the KSH community.
  1. You are currently browsing our forum as a guest. Create your own forum account to access all forum functionality.

Lidar mapper/scanner and data visualization

Discussion in 'Programming Released Codes' started by Innoble, Jul 24, 2017.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. Innoble Apprentice Engineer

    I have been working on a good Lidar scanner/mapper and a visualization script (this is not a mod). I started with Elfi Wolfe's Lidar script as a basis, which sped things up, but changed almost everything about it during the process. I started with a single script to do everything, but that is not realistic, given the large amount of code required to do what I want it to do.

    I currently have:

    This script is designed to map, scan or track anything in range using a grid with camera's. The most effective way to do this is to use a small ship with loads of cameras on it and an antenna to send the information to a control center or another grid with LCD panels to visualize the data.

    The second script is the visualization script:

    The last script is the firing script, which I won't post here, but can be grabbed from a demo world. It is just one version of a firing design/script. This uses a very accurate ore cannon powered by 84 gravity generators, but of course this is very vulnerable to trash removal (stuff got deleted from my test world in flight). It should be easy to adapt the visualization script to fire any other kind of projectile or missile.

    Lidar scanner/tracker:

    Required blocks:

    -Antenna linked to the PB for tranmitting
    -Timer with nametag [CameraTimer]
    -Optional visualization PB with tag [LidarVisual]
    -A ton of camera's

    [​IMG] (camera ship, right click the link and open)


    map: Toggles the mapping process
    scan: Toggles the scanning process, provided a valid target has been selected
    scanid: Select a scanning target by id, this target must first have been mapped. Usage: "scanid 00000000"
    scanitem: Select a scanning target by item on the list. 0 is the first item on the list, 1 the second and so on
    scanradius: This is unnecessary, but if you wish to set the radius manually, you can: Usage: "scanradius 1000"
    rebuild: Rebuilds the list of cameras and other blocks (just recompiling is ususally safer)
    transmit: Turn on/off the transmitting of data
    clean: Remove all mapping data
    range: Set the range of the mapping. Usage: "range 20000"
    track: Toggles tracking
    track enemy, friend, enemy, unowned, owned: Does what it says, it is a toggle
    track delay: Time between tracking beams. The lower the more accurate it is.

    Inside of the script you will find more things to change, such as the "maxBeamsPerTick" setting. This is set to 1 by default, to keep your CPU safe, but of course you can set it as high as you like. Mind the camera recharge though.

    The program will Echo it's status, so you know whats going on. It does not output anything to LCD as it is not meant to do this.

    Data visualization

    Required blocks:

    -Antenna linked to the PB to receive data transmissions
    -Timer with nametag [MapTimer]
    -Large LCD panel with nametag [Map] and [GUI]
    -Two normal LCD panels with nametag[Scan] and [Depth], both also with tag [GUI]
    -An interior turret in view of all 3 panels with nametag [MapTurret]
    -Normal LCD panel with nametag [Target]
    -Possibly a different PB with a firingscript to fire missiles or whatever with nametag [Fire]
    -Control chair or cockpit with nametag [MapController]


    clean: removes all targets, if you dont want it to remove all, do "clean 500" to remove all targets older than 500 ticks that haven't been updated
    lock: Lock a target to make sure it can't change. This must be done before firing, except when you select with WASD
    fire: Activate the firing method inside the script to run the firing pb (which is optional)

    The visualization script can do a lot. It automatically adds everything that is transmitted to it, to the map (the large LCD). If it receives scan information, it will use the other two panels. The scan information LCDs are very high res, so expect some problems in MP. The map panel is updated in real time.

    The depth scan is designed to give a sense of depth but does not tell you the target type or relation. The regular scan is a scan that tells you what type of entity you are looking at and your relation to it.

    You can select targets in two ways. If you are in the control chair, you can change targets with WASD (AD). If you control the turret, you can target the map or the scans. If you target the scans you can target individual parts of a ship or base. The turret has to have a view of the panels and not be too far away of course.


    There might be many issues. This is a very complicated project and I have only tested it in my own way (see demo world) with a camera ship and a large grid with a specific block setup. You might encounter bugs and I will try to fix them if you can explain them well.

    Some things I know of:

    1) The tracking can be ineffective if you don't have many camera's. It can also miss if the target accelerates or if the target has a hole where the center of the bounding box is.

    2) The scanning process is CPU intensive and takes 10 minutes with 1 beam/tick (it collects 30k+ pixels)

    It is also hard to keep everything updated with the demo world, scan script and visualization script being separate things.

    It is fine if you change stuff I made, even if you share it, just mention me somewhere, just like I mentioned Elfi Wolfe.

    Video's and workshop links:

    Targeting method:

    Mapping pattern:

    Visualization script workshop: http://steamcommunity.com/sharedfiles/filedetails/?id=1087817508
    Mapping/scanning script workshop: http://steamcommunity.com/sharedfiles/filedetails/?id=1087887058
    Test world: http://steamcommunity.com/sharedfiles/filedetails/?id=1088511960

    Use a different testworld if you want, just grab the two ships (the camera and Iron spitter) and place them somewhere else. Make sure the spitter has ammo.

    More images:


    Last edited: Jul 24, 2017
    • Like Like x 2
  2. Elfi Wolfe Apprentice Engineer

  3. Elfi Wolfe Apprentice Engineer

    What protocol message does the Data Visualization script want?
    I can add that protocol into the lidar Mapper drones.

    Looks like
    time + "," + countdown + "," + type + "," + relation + "," + entityId + "," + position + "," + velocity + "," + size + "," + name;


    so it would be?
    Last edited: Jul 27, 2017
  4. Innoble Apprentice Engineer

    I used your message protocol, but I don't do much checking. It just takes the 5th part of the message (which is the actual "message" in your protocol). If it gets other messages that are not intended for it, there may be some issues.

    A message is just an update on a list of targets or on an array/stringbuilder of scanpixels. This message is split into several parts with "," that contain the information about the update.

    However, it uses two classes, a "Target" class which has 9 parts of information and a "Scanpixel" class which has 5 or 6 parts (check it, i forgot). Both of them are not, as you might expect, MyDetectedEntityInfo objects. I found that the information contained in those, did not exactly meet my requirements, so I made my own custom classes. I guess the Target objects are the closest to the MyDetectedEntityInfo object, but the ScanPixel is not at all close. I need depth info and pixelnumbers as information in the update. This may complicate things for you.

    When the visualization script receives a "Target" update, it checks the list to see if it already has an item with the same entityID and updates that. If not, it adds a new item to the list. A scanPixel will just be added to an array and appended to the stringbuilder used in the two scan LCDs.

    By the way, if you want to completely change my script, I will not be at all offended. I am not sure if my way is the best way to deal with this. There might be better ways to send updates.
    --- Automerge ---
    Ahh you were still editing your post. Correct, that is the Target class converted to string and those are the 9 parts of it. Don't forget there is also a Scanpixel class and it may receive updates of that kind as well.
    --- Automerge ---
    By the way, I am not currently using the "countdown" part of the update in the visualization script. That is an integer that keeps track of how long it will take before the next time there has to be sent a tracking beam (by default 1 second). That is if tracking is even on. I do use the "time" part so you are able to clean old information.
  5. Elfi Wolfe Apprentice Engineer


    p.s. The radio message can have more than one message attached to a radio transmission. split by \n so if you feed it right to the data visualizer from a radio message.
  6. Innoble Apprentice Engineer

    By the way, I am not currently using the "countdown" part of the update in the visualization script. That is an integer that keeps track of how long it will take before the next time there has to be sent a tracking beam (by default 1 second). That is if tracking is even on. I do use the "time" part so you are able to clean old informatio
    I think I do this already, but I think I split them differently (not '\n' I think). Check the other script for how the message is built up. I have a "messageString" I add stuff to. There should usually never be more than 1 item in it, but there is an option to have multiple beams per tick (default = 1). With multiple beams, the message has to have multiple Targets or scanPixels in it. This is nice for bugtesting. I often set it to 10, to quickly watch a scan image build up or to quickly obtain a map.
  7. Elfi Wolfe Apprentice Engineer

    You have the radio system set to append.
    So if yo have 2 messages waiting to go out the radio system appends the second message on the the first with a \n between them

    and you are putting a ; before anything added to he messageString.
    messageString.Append(";" + targets);

    So the radio does this.

    And the direct message to the visualPB is
    visualPB.TryRun(";" + ";" + ";" + ";" + messageString);

    and appears visual PB breaks that down into 2 messages


    so I send a
    MSG;to;from;options;GPS:large Grid:0:0:0::\n

    I then use commo receiver script
    pull the gps off to display
    well I can do what your receiveData does.
    and then on Length 9 or 6 send it to receiveData (well not 6 since lidarMapper will not be doing ScanPixel)

    Should work. Unless you want to put a protocol ID at the front. If you do change the protocol let me know so I can update the lidar mappers.

    If this works then you can have several lidar mappers or lidar scanners out around your ship feeding you back info to the data visualizer.

    --- Automerge ---
    There.. that would take
    MSG;to;from;options;GPS:large Grid:0:0:0::\n

    GPS goes to the GPS LCD
    and the 3 target info would be fed one at a time to the DataVisualizer PB.
    I have tried to harden the code so that only something that looked correct would go in.
    oh.. let me add the scanpixel as well.

    					} else if {
    						string[] tar = message[i].Split(',');
    						if (tar.Length == 9 && int.TryParse(tar[0]) && int.TryParse(tar[1]) && long.TryParse(tar[2]) && int.TryParse(tar[4]) && int.TryParse(tar[5])({
    							for (int i=0; i < visualPB.Length; ++){
    								visualPB.TryRun(";" + ";" + ";" + ";" + message[i]);
    						} else if (tar.Length == 6 &&  int.TryParse(tar[0]) && int.TryParse(tar[1]) && long.TryParse(tar[2]) && int.TryParse(tar[4]) && int.TryParse(tar[5])){
    							for (int i=0; i < visualPB.Length; ++){
    								visualPB.TryRun(";" + ";" + ";" + ";" + message[i]);
    						} else if (message[i].Contains("scanMiss"){
    							for (int i=0; i < visualPB.Length; ++){
    								visualPB.TryRun(";" + ";" + ";" + ";" + message[i]);
    --- Automerge ---
    So I'll add this to LidarMapper transmissions

    Will not be able to take the radio message directly.
    This is what a single hit transmission from a LidarMapper will look like after these changes

    MSG;to;from;options;GPS:large Grid:0:0:0::\n
    Last edited: Jul 27, 2017
  8. Innoble Apprentice Engineer

    Good catch about the redundant ";" in the first part of the message. I wasn't sure what I was doing there. See that is what happens when you simply copy someone elses code. That was the only part I did not change and apparently thats why I misunderstood the protocol. I guess it worked anyway, because it ignores the extra ";". It is just discarded when received.

    I don't think I ever use the append functionality you put in though (with '\n'), because there is only one call of "send messages" per tick on my mapper, even with multiple beams. That one call contains multiple messages, but they are not appended through your protocol, but through my own appending of the messageString (with ';'). It is still 1 message, but I am splitting it up when it is received.

    Mmh that last bit of code looks odd. Are you running a PB in a loop? You can only run a PB from the same source once per tick, so that should not be possible.

    My way of feeding data should already accept multiple mappers as input, because every message will be processed and integrated in the targetlist, no matter the source of the message, as long as it is formatted correctly. It will not accept multiple scanners though. It can only process one scan at a time. It should be easy to test. Just throw a bunch of cameraships out there and see if it works :)

    EDIT: lol you're adding posts faster than I can keep up. Just mess around for a bit, see if you can come up with some improvements and I will take a look at it and integrate them with my own scripts. I'm sure there is lots of room for improvement, but I need to see the whole thing before I understand exactly what you're doing. This is complicated stuff!

    If you have the time, take a look at my mapping pattern. It is not easy to find, but I think it is the coolest part of the mapping script and my main contribution to the LIDAR mapping. Everything else has pretty much been done by you in some way or other. The method is : GetScanTargetAndIncrement
    Last edited: Jul 27, 2017
  9. Elfi Wolfe Apprentice Engineer

    The append only happen if there is a radio message still waiting.
    so your messages look like


    And the lidarMapper messages looks like

    MSG;to;from;options;GPS:large Grid:0:0:0::\n

    oh.. I need to change some settings in CommoReceiver so it can understand.
    --- Automerge ---
    I think I got the CommoReceiver able to understand both.

    This is written on paper so there is spelling errors and coding errors.
    --- Automerge ---
    Using a LidarMapper to feed to a CommoReceiver to Feed to Data Visualizer

    --- Automerge ---
    Should put down the font and font size settings on the LCD. Monospace and .296 for the map and .100 for the other 2
    Right now you have to have a PB for firing even if you do not use it.
    LidarScanner sends a radio message ever tic, even if there is nothing in the message.
    Suggest changing that to only send when there is a message.
    if(transmitting && messageString.Length > 0)
    LowPriority(outRadios, "anyone", Me.CubeGrid.DisplayName, "", messageString.ToString(), commWho, true);
    --- Automerge ---
    The turret and the LCD if turned on the ship grid will not line up
    <PB (on same floor facing left)

    <turret (facing to the left)
    The gun will be mirrored but it will when lined right at the LCD light a target there. but if you move the gun left the selected dots are to the right.

    Your example has

    , PB (facing up, bottom to the left)
    turret (facing toward the LCD, turret button is rear)
    --- Automerge ---
    This works.
    <PB (on same floor facing left)

    turret> (facing to the right)

    Possible the turret has to face the front of the local grid?
    --- Automerge ---
    Here is a world with Lidar Mappers talking to CommoReceiver which screens and sends on messages to Innoble's Data Visualization script.

    --- Automerge ---
    Here is the script that can take Lidar Data and send to the Visualizer script.

    WARNING: with a LidarMapper and Camera Drone, sending data to the commo receiver sending data to the data visualizer will break SE at this time. Bug in SE renderer engine for LCDs.
  10. halipatsui Senior Engineer

    So the targeter can be used to aim at the actual point you designate from the map with a turret?
  11. cpy Trainee Engineer

    What does it do and what can I use this for?
  12. Enigmus Trainee Engineer

    Not sure where to post or ask this question. However, there are reports that Antennas (both laser and radio) will not transmit/receive beyond the simulation's render/view range. This prompts me to ask if LIDAR (Camera raycasting) is viable outside of render range. Has anyone tested?
  13. Lander1 Trainee Engineer

    I can not stress enough the Awesomeness of this script. It took me 5 hours of tinkering to get it to work but I got there in the end and I now have this as the centerpiece of the bridge in my Flagship; the Ojo Caliente XP R2.

    I particularly love the way the map moves with the ship, it's a priceless navigation aid... no more bumping asteroids in the night.

    I do have a question or two though;

    Is there a way of making the Camera Drone and Visualizer use a Laser Antenna instead of radio? I could not get any data on the map using laser link. If not it would be on my high priority of requests for this script.

    Is there a way of designating a target on the map for depth scan using the MapTurret? So far I have been manually trying to match up size and scanid, through the remote terminal on the camera ship, which can be a tedious task with 30+ targets to choose from.

    Are there any "Drop in" replacement firing/Mining AI scripts that would work for the firing script that you would recommend?
    Last edited: Oct 6, 2017
  14. Innoble Apprentice Engineer

    Sorry guys, sometimes I don't check the forums in a while:

    Yes, thats the idea. It is pretty hard to set up correctly, with a lot of testing and corrections.

    There are a few concepts, namely:

    1) Creating a list of targets using Lidar and transmitting them.
    2) Visualizing a target or a map with an LCD.
    3) Targeting the map with a turret.

    They're all hard to adapt, which is why i added a testworld. I wouldn't bother with this unless you're a good scripter. It's not a ready made copy paste thingy. Some things may not work anymore due to PB changes.

    No idea, I haven't tested.

    -You can use a laser antenna instead of radio i think. It should not be too hard to adapt it, but I don't have the time personally. I meant to share this code mostly to "throw it out there" to see what people can make of it.

    -Not sure what you mean by designating a target. Yea it can be a tedious process to sift through targets. I did not make the script advanced enough to make this easier. Someone could do that.
    By the way, if you use mods, I would recommend my holo projector: https://forum.keenswh.com/threads/wip-holo-projector.7384553/
    It is far more advanced as a mapping tool and gives you a holographic map (3D) of grids and asteroids and such. However, it is a mod, so I guess that may be an issue. Unlike my scripts though, this mod is actually very advanced.

    -I have no specific recommendations for scripts. I don't really use other scripts much. In fact I don't play the game much and when I do, I just design, script and sometimes mod things, which I share when they are far enough along. I never actually go and play an actual game of SE with them. Other players have plenty of recommendations though. Any weapon (or mining ship) that targets GPS coordinates, should be compatible with my ideas.
Thread Status:
This last post in this thread was made more than 31 days old.