Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
owl leader

Convert local coordinates into drone move offsets

Question

This probably was asked numerous times already.
I have a drone, which I am trying to get to move to waypoints, and for testing the waypoints list start and end is the {0, 0, 0} local coordinate (start location), yet the drone ends up 5 or so blocks away. Oh and I lost the drone by telling it to move 2 * coords + offset blocks and it's now somewhere at Y 1300. RIP Jaeger, been a good time.

So, the question is, how does one convert a waypoint into an offset that drone.move() will work with?

The current code is

local waypoints = {
	{x = 0, y = 0, z = 0},
  	{x = 15, y = 25, z = -7},
	-- more waypoints with some values,
  	{x = 0, y = 0, z = 0}
}

local function sleep(s) -- taken from http://lua-users.org/wiki/SleepFunction
  local ntime = os.clock() + s/10
  repeat until os.clock() > ntime
end

local function waitForTargetReach() -- actual implementation is probably slightly different
  	local epsilon = 0.2
  	while drone.getOffset() > epsilon do sleep(1) end
end

local coords = {x = 0, y = 0, z = 0}

local function moveWaypoint(waypoint)
	drone.move(waypoint.x - coords.x, waypoint.y - coords.y, waypoint.z - coords.z)
  	waitForTargetReach() -- busy wait - probably need to make this a signal pull somehow
  	coords = waypoint -- potential for error buildup, probably the cause for the resulting 5 block error
end

for _, v in ipairs(waypoints) do
	moveWaypoint(v)
end

The concern is for the moveWaypoint(waypoint) function, other functions are provided to give some context, but probably one of you will find an issue.

My logic tells me that the function is almost correct, and I just have epsilon set too high, but is it really that high? Besides, how accurate is drone movement even?

It's my first time working with drones, so I have absolutely no idea whether I need or don't need to do certain things.

 

Update.
Turns out I have literally posted working code and it was a matter of setting epsilon to 0.05 and the initial results led me to the conclusion I did something terribly wrong.

There is a lesson to be learned here somewhere.

RIP Jaeger, your loss was really unnecessary and preventable lol

Edited by owl leader
solved
Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.