From 63fa89d70fdd8130e7eaf3fb9a21865d3faa6f8d Mon Sep 17 00:00:00 2001 From: ubq323 Date: Thu, 4 Apr 2024 00:01:06 +0100 Subject: launch cactus --- cactus.lua | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'cactus.lua') diff --git a/cactus.lua b/cactus.lua index 756dd89..8e0e887 100644 --- a/cactus.lua +++ b/cactus.lua @@ -17,5 +17,41 @@ local function ensure_scanner() return error("aaa") end assert(ensure_modem()) -local w = vector.new(gps.locate()) -print(w) +local POS = vector.new(gps.locate()) +local function get_facing() + while turtle.detect() turtle.turnRight() end + turtle.forward() + local newpos = vector.new(gps.locate()) + turtle.back() + return newpos - POS +end +local FACING = get_facing() + +local function moveby_y(delta) + local fn = turtle.up + if delta < 0 then fn = turtle.down delta = -delta end + for i=1,delta do fn() end +end + +local function rotatev(v,nq) + -- rotates v by n quarters + nq = nq%4 + for i = 1,nq do + v.x,v.z = -v.z,v.x + end + return v +end + +local v = vector.new(1,0,0) +for i=1,4 do print(i,rotatev(v,i)) end + +local function moveby_xz(dv) + -- y component of dv is ignored + + + + + +local datum = vector.new(-18, 128, -1837) +local dx = w-datum +moveBy(dx) -- cgit v1.2.3