Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Turtle = {
- IDTurtle = nil,
- IDServer = nil,
- Inici = nil,
- PosActual = nil,
- Inicialitzat = false
- }
- Config = {
- timeout = 25,
- serverName = "ServidorTurtlesVic"
- }
- function main()
- Turtle:inicialitzar()
- end
- function Turtle:inicialitzar()
- rednet.open("right")
- while ( not(self.IDServer)) do
- rednet.broadcast("GetIDTurtleVic")
- local senderId, message = rednet.receive(Config.timeout)
- if message and string.find(message, "IDNEW") then
- args = {}
- for argument in message:gmatch("%w+") do table.insert(args, argument) end
- self.IDServer = senderId
- self.IDTurtle = args[2]
- end
- end
- print("ID de turtle: ".. self.IDTurtle " asignada por el servidor: " .. self.IDServer)
- print("Obtenint senyal GPS.....")
- self:getGPS()
- if self.PosActual == "ERROR" then
- return false
- end
- print("Senyal GPS trobada, la posició actual és: " .. self.PosActual.x .. " x, ".. self.PosActual.y .. " y, " .. self.PosActual.z .. " z")
- self.Inicialitzat = true
- return true
- end
- function Turtle:getGPS()
- local timeout = tonumber(Config.timeout)
- local vectorA = vector.new(gps.locate(timeout))
- if not vectorA.x then
- print(" /!\\ Error al intentar aconseguir la posició GPS /!\\ ")
- self.PosActual = "ERROR"
- else
- self.PosActual = vectorA
- end
- return true
- end
- function Turtle:getID()
- self.IDTurtle = nil --TODO Implementar
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement