Page 1 of 1

Plane keeps flickering

Posted: 29 May 2024, 08:12
by arghya003
Hello everyone! This is my first post on this forum so please pardon any mistakes. I am also new to CoppeliaSim.

I am trying to simulate the landing the process of a UAV on a slow moving platform. Currently, my scene looks like this:

Image

There are 2 issues I want to solve.

1. The red plane moves along the path at a constant velocity of 1 m/s. When it reaches the end of the path, it reverses velocity to move at -1 m/s. However, when the plane moves, it keep constantly flickering. The aruco marker does not flicker. Only the red plane keeps flickering. I tried to change the heights of the aruco marker and the plane to solve this issue but it did not work. Currently, the plane is at 0.002 m and the aruco marker is at 0.0022 m from the ground. How do I fix this?

2. When the landing marker reaches the end of its path, it immediately reverses its direction. How can I make the landing marker deaccelerates from a certain distance such that it stops when it reaches the end of the path and gradually accelerates upto 1 m/s?

Threaded child script code for the path -

Code: Select all

#python

import numpy as np

def sysCall_init():
    sim = require('sim')
    self.end = False
    self.objectToFollowPath = sim.getObject('/Landing_Surface')
    self.path = sim.getObject('/Path')
    pathData = sim.unpackDoubleTable(sim.readCustomDataBlock(self.path, 'PATH'))
    
    m = np.array(pathData).reshape(len(pathData) // 7, 7)
    self.pathPositions = m[:, :3].flatten().tolist()
    self.pathQuaternions = m[:, 3:].flatten().tolist()
    
    self.pathLengths, self.totalLength = sim.getPathLengths(self.pathPositions, 3)
    self.velocity = 1.0 # m/s
    self.posAlongPath = 0
    self.previousSimulationTime = 0
    sim.setStepping(True)    

def sysCall_thread():
    while not sim.getSimulationStopping():
        t = sim.getSimulationTime()
        if self.end == False and self.posAlongPath < self.totalLength:
            self.posAlongPath += self.velocity * (t - self.previousSimulationTime)
        elif self.posAlongPath > 0:
            self.posAlongPath -= self.velocity * (t - self.previousSimulationTime)
            self.end = True
        elif self.posAlongPath <= 0:
            self.posAlongPath += self.velocity * (t - self.previousSimulationTime)
            self.end = False
 #self.posAlongPath %= self.totalLength
        pos = sim.getPathInterpolatedConfig(self.pathPositions, self.pathLengths, self.posAlongPath)
        quat = sim.getPathInterpolatedConfig(self.pathQuaternions, self.pathLengths,
               self.posAlongPath, None, [2, 2, 2, 2])
        sim.setObjectPosition(self.objectToFollowPath, pos, self.path)
        sim.setObjectQuaternion(self.objectToFollowPath, quat, self.path)
        self.previousSimulationTime = t
        #print(self.posAlongPath, self.totalLength)
        sim.step()# resume in next simulation step
    #pass

# See the user manual or the available code snippets for additional callback functions and details
Any help would be appreciated. Thank you in advance!

Re: Plane keeps flickering

Posted: 31 May 2024, 14:42
by coppelia
Hello,

not sure where the flickering comes from. But my guess this is due to z-fighting, which happens when 2 planes are almost coincident. You can either move the two planes a bit more apart, or you can try to reduce the vision sensor (or camera) far clipping plane - new clipping plane gap.

For smooth motions, best is to use sim.moveToPose or sim.moveToConfig. Your script will have to run in threaded mode though. Have a look at the demo scene scenes/trajectoryAndMotion/basicTrajectoryGeneration.ttt (or scenes/trajectoryAndMotion/ruckigOnlineTrajectoryGeneratorExamples.ttt).

Cheers