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

Navigation Upgrade, A code newb and his problems

Question

Hi,

I hope this is the right place to post this.

So basically, since I am really not into lua at all, I firstly tried to just play around with the drone, and I wanted to write a program sooner or later, to harvest things. I tried to figure out how getPosition() works and what it actually returns when I tried to setup a variable with that method, it always threw "string expected, got table". Tried like position = {component.navigation.getPosition()}.  <- That somehow had to do with something else, I don't know what exactly.

 

So I tried to get "getPosition()" to work, for to use it to craft some primitive if/else based actions.

What I tried lately was:

local drone = component.proxy(component.list('drone')())
local position = component.navigation.getPosition() -- since I have the navigation upgrade on my drone

if position ~= nil then
	drone.setStatusText("NotNil") -- since I couldn't get a value like setStatusText(position) to work, it expects string
end

while true do
drone.move(0, 0, 0) -- to keep the drone running
end

-- throws error oc:bios:2: attempt to index field 'navigation' (a nil value)

 

Also I couldn't get " x = require("X")" to work at all (I also don't know what I actually require when I say "x = require("component")" or "x= require("event") components? librarys? Can I get a list of these librarys that exist?)

The require attempts threw "attempt to call global 'require' (a nil value)". Things like "table.toString(tableName)" didn't work for me too. Guess toString is just not included maybe.

 

I am really not much into scripting yet, not to mention lua. The only thing I ever learned quite a bit was javascript es5 and a bit React.js with es6.

Quite frustrating for me to not even get a simple variable that calls a method of some component working in lua lmao.

 

Thanks in advance for any help!
 

Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 1
  • Solution

Try this out..

The require function is defined by OpenOS which isn't available in the drone env. 

require is used to load libraries from the package path. See /lib/package.lua

local drone = component.proxy(component.list('drone')())
local position = component.proxy(component.list('navigation')()).getPosition()
-- # The require keyword is for libraries accessed via a filesystem which the drone doesn't have. Therefor it isn't available.
-- # The `component.someComponentName` functionality is defined in the OpenOS component library.. Again, not available here.

if position ~= nil then
  drone.setStatusText("We in business bb")
end

while true do
  drone.move(0, 0, 0) -- to keep the drone running
end

Drones can be a bit of a pain to get used to as they dont have any of the sweet libs defined in OpenOS.

See https://ocdoc.cil.li/tutorial:custom_oses to see what is available in a hardware only env like drones or and hw that is without an OS

Link to post
Share on other sites
  • 0
10 hours ago, Molinko said:

Try this out..

The require function is defined by OpenOS which isn't available in the drone env. 

require is used to load libraries from the package path. See /lib/package.lua


local drone = component.proxy(component.list('drone')())
local position = component.proxy(component.list('navigation')()).getPosition()
-- # The require keyword is for libraries accessed via a filesystem which the drone doesn't have. Therefor it isn't available.
-- # The `component.someComponentName` functionality is defined in the OpenOS component library.. Again, not available here.

if position ~= nil then
  drone.setStatusText("We in business bb")
end

while true do
  drone.move(0, 0, 0) -- to keep the drone running
end

Drones can be a bit of a pain to get used to as they dont have any of the sweet libs defined in OpenOS.

See https://ocdoc.cil.li/tutorial:custom_oses to see what is available in a hardware only env like drones or and hw that is without an OS

This definitely broke my blockade! I completely misunderstood component.proxy functionality. Even managed to create a table put it into a string now to see a specific position also thanks to the tutorial.

Now I'm gonna try to figure out how I can send the string to my client interface since the resolution of the drone interface doesn't allow me to see all coordinates properly.

 

Thank you! :lol:

Link to post
Share on other sites

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.