This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
blunty666's profile picture

starNav - Pathfinding and Mapping

Started by blunty666, 01 July 2014 - 03:54 PM
blunty666 #1
Posted 01 July 2014 - 05:54 PM
starNav 3.0

(Previous version: starNav 2.0 - The Windows 9 Special Edition :lol:/> )



GPS based Turtle pathfinding with efficient movement algorithm and environment mapping


Install from pastebin: pastebin run rNZx09j4


New version features:
- New tinyMap API which drastically reduces the file size of the map saves.
- Implemented sessions which help to increase successful pathfinding in constantly changing environments.
- Added the ability to limit the search area, to stop your turtle wandering off too far!
- Turtle remembers it's position and heading at all times (not between server restarts though).

Usage:
The API has an easy installer available on pastebin at rNZx09j4.
(See Downloads for individual file list)
Setup process:
SpoilerTo get yourself up and running, follow these three easy steps!
1) The turtle requires a reliable GPS network to be able to determine it's position, so make sure to fully cover the area you want to navigate with GPS points.
2) The turtle needs to have a wireless modem to access the GPS network, as well as fuel!!! (You can also optionally equip the turtle with a sensor from openPeripheral to massively speed up it's navigation)
3) Once you have installed all the files, either use the 'starNav.goto' function, or the provided 'goto' program.

Using the 'goto' program: goto x y z

Using the starNav API: starNav.goto(x, y, z)

Downloads:
Programs:
Spoilerinstaller - rNZx09j4
goto - aaxFVEPn
APIs:
SpoilerstarNav - BCk9q0EB
tinyMap - 9GZkMSiF
aStar - BZFJqHBi
location - HPS8KbxL
pQueue - PYbpYrfx

Documentation:
Spoilergoto program - Easy to use program based on the starNav API
SpoilerSimply run the program in shell, providing the co-ordinates you want to pathfind to:

goto x y z

You can provide an additional argument to limit the search area so that the turtle doesn't wander too far:

goto x y z maxDistance

starNav API - Main API that let's you use the pathfinding functions in your own programs
Spoiler

function goto(<number> xPos, <number> yPos, <number> zPos, <(optional)number> maxDistance)

function getPosition()
returns <number> xPos, <number> yPos, <number> zPos, <number> heading

aStar API - The raw A* API
SpoilerUtility functions:

function newMap()
returns a basic 3D map that can be used to store any values

function vectorEquals(<vector> vec1, <vector> vec2)
returns true if vec1 and vec2 have the same value or false otherwise

function adjacent(<vector> vec1)
returns a table with all 6 adjecent coords to the one at vec1 (e.g up, down, left, right, forward, backward)

function distance(<vector> vec1, <vector> vec2)
return the 1-norm / manhattan distance between two vectors

Main function:

function compute(<function> distanceFunction, <vector> startCoord, <vector> endCoord)
returns an array of the path in vector format or false if no path can be found

pQueue API - A binary heap based priority queue
SpoilerCreate a new by calling the new function:

function new(<(optional)function> compareFunction)
return a new instance of a priority queue with compareFunction as the function used two compare two elements in the queue

The priority queue then has the following methods:

queue:insert(element, value)
returns the position the element is inserted into the queue at

queue:remove(element, <(optional)function> elementEqualsFunction)

queue:pop()

queue:peek()

queue:contains(element, <(optional)function> elementEqualsFunction)

queue:isEmpty()

queue:size()

queue:getValue(element, <(optional)function> elementEqualsFunction)

queue:setValue(element, value, <(optional)function> elementEqualsFunction)

tinyMap API - API used to save 3D data
SpoilerTODO

location API - Modified version of an API I found somewhere???, altered to use Minecraft's values for headings
SpoilerTODO
Edited on 12 December 2015 - 03:13 PM
BaRF #2
Posted 09 July 2014 - 11:20 AM
I'm going to try this asap! Can't believe anyone has replied yet, this seems like a great and easy way to add pathfinding without any other 'baggage' :)/>
ReconTurtle #3
Posted 09 July 2014 - 09:23 PM
I saw this post a while back, and it's an amazing idea, I just didn't really no what to do with it. So now I'm interested in what you come up with, result-wise, BaRF.

@blunty666 - How exactly would I go about implementing this in my programs, etc.? I have no experience with APIs such as this.
blunty666 #4
Posted 09 July 2014 - 10:23 PM
Thanks for the feedback, let me know how you get on trying it out BaRF.

@blunty666 - How exactly would I go about implementing this in my programs, etc.? I have no experience with APIs such as this.

At the moment the main way to use it would be to know the world coordinates of the location you want the turtle to move to and call starNav.goto(x, y, z) from within your program with these coordinates (replace starNav with whatever name you have saved/loaded the API under). It will then start pathfinding and will return to your program when it reaches those coordinates. If it can't find a path it will throw errors describing why, though fuel checking is something I need to add, at the moment I'm just testing to see if the pathfinding works successfully.
thewmatt #5
Posted 28 August 2014 - 11:47 PM
i get an error:
starNav:90: could not determine direction - phase 3
blunty666 #6
Posted 31 August 2014 - 01:03 AM
i get an error:
starNav:90: could not determine direction - phase 3
Sorry for the slow response, did you manage to get it working? The error you gave is most likely due to the turtle not having any fuel I think, so it might be worth checking that.
blunty666 #7
Posted 12 December 2015 - 04:17 PM
starNav 3.0 Changelog (everything's changed!)
- Is now more modular, split off the aStar API so it can be used on its own
- New tinyMap API that has smaller file sizes so that a larger area of the world can be mapped and saved
- Various refinements to the starNav goto algorithm to improve success rates when the world changes, and to define a max distance so the turtle can't wander off too far