Determine orientation of turtle
xZise opened this issue ยท 12 comments
Hi all,
as far as I can see there is no way to determine in which direction the turtle is currently looking. At the moment I want my turtle to stay in a certain region, but without knowing the orientation I cannot be sure that it won't leave the region. The only way around is to move and to check the new coordinate.
My idea would be to either add that to gps
(like gps.direction()
) or turtle
. It would return a vector
(or just x/z-pair) with the direction where it is facing.
Maybe it would be possible to include something like that.
Allow a compass as a gui upgrade slot? Then call turtle.compass(), which would return degrees away from north
@OttersMeep
Something similar was already suggested.
Allow a compass as a gui upgrade slot? Then call turtle.compass(), which would return degrees away from north
EDIT: Lupus590 is correct, it was already suggested. However, what I meant to say with this comment is the function that you could use to determine the orientation, not the compass idea, which is not mine.
I know this is an old issue but I just stumbled over it and wanted to give my solution for the last couple years. Maybe it helps someone.
At program start (whether initial start or restart because of a server restart) the turtle places 4 blocks to surround the block above it horizontally (it obviously has to move in order to do this) and then places a torch above it. Since the torch can't be placed on the turtle it is placed on one of the 4 blocks. The trick is that this block is always the same, independent of the turtles orientation. I forgot which one that is now (I believe east?) but you can simply test that. It then breakes the 4 blocks again one by one, checking each time whether the torch fell down (which would mean it was attached to that block which would give you the orientation).
Ever since the turtle api exposes the turtle.inspect() functions, this can be done a lot less complicated. Simply make sure there is only one block the torch can attach to, place the torch against that block and inspect it. The data should contain metadata about the direction the torch is facing which you can use to get the turtles orientation.
This is one of the few things that keeps me from actually using this mod. Not being able to know what direction a turtle is facing without manual state tracking or placing a torch and parsing its state is dumb when IRL compasses are dirt simple, their IC versions are just as dirt simple (you read six bytes over I2C for three-way rotation data and check a status byte to see if it's tracking properly), and you only have to track four states in Minecraft because a turtle is a block. Make an equippable compass if you don't want it to be "magic data that you just get", but just add the basic spatial data everyone needs to orient themselves in a 3D environment.
would be nice for a pocket computer to be able to take up to two peripherals like how turtles can. this'll allow either taking a compass and modem or if the compass is not added, then an entity scanner from plethora and a modem
would be nice for a pocket computer to be able to <...>
See #1406, it's dedicated to the idea of making pocket computers a bit better.
The sad thing with facing is that it has to be information the turtle just "magically" knows, unlike GPS, which is done entirely through modems. I don't really like exposing more magical information without a good reason, though there's many ways to infer the direction (GPS+move in a known direction, place a torch and read is blockstate). I guess it's not like we're really exposing anything which can't be known already.
Would definitely like some other people's thoughts on this!
Some older discussions on the original ComputerCraft repo:
[Suggestion] turtle.getFacing()
Add turtle.getTurn()
Just my two cents.
To keep it from seeming too magical, maybe a craftable magnetometer that requires calibration, and so long as it is equipped, it will report the difference from it's original calibrated direction.
That would remove the need to persist "inertial" direction in a file, which IMO is error prone and difficult to keep fault tolerant, but still reduce the "magic" of just knowing. (For inertial x/y/z it's possible to recover from restarts/crashes by comparing saved fuel values)
GPS devices IRL only know direction when they have magnetometers, I believe, so it seems natural to require moving to check the direction that way. I could be wrong about my armchair knowledge of it.
I've written an API for keeping track of the turtle's location/orientation relative to its starting position that might be helpful to you: https://forums.computercraft.cc/index.php?topic=316.0 (You'll need flex.lua and dig.lua)
Would definitely agree with @SquidDev here in that this is something easily determined using GPS and is part of the innate challenges of ComputerCraft - like robotics in the real world you're not given all of the information for free, some of it has to be inferred from the environment.