about Path and get object handle

Report crashes, strange behaviour, or apparent bugs
Post Reply
WesFerr
Posts: 3
Joined: 24 Aug 2017, 07:57

about Path and get object handle

Post by WesFerr » 26 Feb 2018, 05:00

i have 2 drones to follow the same Path, but in one of then the method sim.getObjectHandle("Path") work as well, in the other its simply return me this error:

Code: Select all

Lua runtime error: [string "CHILD SCRIPT Quadricopter_target#0"]:1: Object does not exist. (sim.getObjectHandle)
stack traceback:
	[C]: in function 'getObjectHandle'
	[string "CHILD SCRIPT Quadricopter_target#0"]:1: in main chunk
below the code used in the targets:

Code: Select all

--drone 1 - Quadricopter_target
path = simGetObjectHandle('Path0')
object = sim.getObjectHandle('Quadricopter_target')
pathLength = sim.getPathLength(path)
posOnPath = 0
v = 0.5
movement = v

while true do

    l = posOnPath/pathLength
    if(posOnPath > pathLength) then
        movement = -v
    end
    if (posOnPath < 0) then
        movement = v
    end

    position = sim.getPositionOnPath(path, l)
    orientation = sim.getOrientationOnPath(path, l)

    position[3] = 0.9
    sim.setObjectPosition(object, -1, position)
    sim.setObjectOrientation(object, -1, orientation)

    posOnPath = posOnPath+movement*sim.getSimulationTimeStep()

    sim.switchThread()
end

Code: Select all

--drone 2 - Quadricopter_target#0
path = sim.getObjectHandle('Path0')
object = sim.getObjectHandle('Quadricopter_target#0')
pathLength = sim.getPathLength(path)
posOnPath = 0
v = 0.5
movement = v

while true do

    l = posOnPath/pathLength
    if(posOnPath > pathLength) then
        movement = -v
    end
    if (posOnPath < 0) then
        movement = v
    end

    position = sim.getPositionOnPath(path, l)
    orientation = sim.getOrientationOnPath(path, l)

    position[3] = 0.9
    sim.setObjectPosition(object, -1, position)
    sim.setObjectOrientation(object, -1, orientation)

    posOnPath = posOnPath+movement*sim.getSimulationTimeStep()

    sim.switchThread()
end
help me

coppelia
Site Admin
Posts: 6675
Joined: 14 Dec 2012, 00:25

Re: about Path and get object handle

Post by coppelia » 27 Feb 2018, 10:08

Please read this page, Access from associated code.

Cheers

Post Reply