Cannot fix the orientation of my object

Typically: "How do I... ", "How can I... " questions
Post Reply
Javierrc99
Posts: 23
Joined: 08 May 2022, 18:34

Cannot fix the orientation of my object

Post by Javierrc99 »

Hello, in this scene attached:
https://drive.google.com/file/d/19vaGMK ... share_link

I have the standard quadrotor model with the default control that follows the "target" object.
However, when the drone moves, it naturally changes its inclination towards the target. That makes that the cameras i have attached move accordingly to that movement.
In the "Camara_GranAngular" child script I am trying to force its orientation so that the camera keeps looking towards the ground despite the drone's orientation changes while moving.
It doesn't seem to work, you can try moving the target and the camera will change its orientation.

Is there any better way to have this orientation of the camera fixed and stable even when the drone moves?
Maybe another solution could be to change the Quadcopter control script to not change the quadcopter orientation but that seems harder.
Any clues?
Thanks in advance

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

Re: Cannot fix the orientation of my object

Post by coppelia »

Hello,

simplest would be to continuously set the initial orientation of the vision sensor, e.g.:

Code: Select all

function sysCall_init()
    cam = sim.getObject("/Quadcopter/BaseCamaras/Camara_GranAngular")
    initPose=sim.getObjectPose(cam,sim.handle_world)
end

function sysCall_sensing()
    local pose=sim.getObjectPose(cam,sim.handle_world)
    pose[4]=initPose[4]
    pose[5]=initPose[5]
    pose[6]=initPose[6]
    pose[7]=initPose[7]
    sim.setObjectPose(cam,sim.handle_world,pose)
end
Cheers

Javierrc99
Posts: 23
Joined: 08 May 2022, 18:34

Re: Cannot fix the orientation of my object

Post by Javierrc99 »

That seems to work pretty smoothly keeping the orientation fixed, Thanks a lot.
However, do you think if I were to do this stabilization more realistic, like programming a controller for the 3 axis gimbal for the camera, with say a PID per axis, would it be fast enough to keep the camera stable even against fast drone movements. If so, what would be the way to make the control faster (which I believe it is essential to keep its camera stable) making it in a child script directly in Coppelia, or from a python client using the ZMQ remote API.
I would like to hear your view on this task before trying to develop one of those 2 options.

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

Re: Cannot fix the orientation of my object

Post by coppelia »

I you wanted to implement this in a more realistic manner, then you would use 2 revolute joints mounted on top of each other, and actuate those joints, instead of directly setting the orientation of the vision sensor.

For that, have a look at the demo scene scenes/eulerAngles.ttt and the user manual section on positions, orientations, and transformations. You'd basically arrange the two joints so that you could directly apply the desired angles from the desired Euler angle pose.

Then, you could use kinematic joints with some motion constraints via sim.setJointTargetPosition(handle,desiredAngle,motionData). Or Dynamically enabled joints (with some auxiliary masses in-between) where the motion constraints would be given by the position controller.

Cheers

Javierrc99
Posts: 23
Joined: 08 May 2022, 18:34

Re: Cannot fix the orientation of my object

Post by Javierrc99 »

Hello again, i have the gimbal already mounted.
The thing is each joint should have this (https://drive.google.com/file/d/1x1gSpe ... share_link) particular dynamic and response, that graph is for a step reference.

I have been looking at the "motorControllerExamples.ttt" demo and i believe what I want is pretty similar to the position control example there for each axis.
However, since those transfer functions I attached already include the controller, I am not so sure I can model the dynamic this way.
Is there any way to implement those custom dynamics from the transfer functions attached?
In those systems, the reference would be the angular position (deg), and the output would already be the result of the controlled system (also angular position (deg)).

I know it is not a trivial question, I will be trying to solve it myself, but I would really appreciate some useful hints.

Thanks again for your response.

Javierrc99
Posts: 23
Joined: 08 May 2022, 18:34

Re: Cannot fix the orientation of my object

Post by Javierrc99 »

For my last question i think I made it work.
I have another question, when you send signals via sim.setFloatSignal in a loop after some calculations within a zmq client
and check for them within a threaded child script in the "While true" loop, can it cause overload if the signals are being send faster than the speed the child script receives and clear them?. Im not sure if this can cause a problem, and the signals might be arriving or being received wrongly.
I believe that the child script would be faster than the client since it hasn't much calculations and there shouldn't be problems.

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

Re: Cannot fix the orientation of my object

Post by coppelia »

A same string signal can only exist once. So if you set a new string signal, the old value would be erased. If CoppeliaSim hasn't read it yet, then if would be lost.

Better is to call a specific script function, that buffers values, so that they can be processed later, or in next simulation step. You'd use sim.callScriptFunction from your client side. Something like that on CoppeliaSim side, if running threaded:

Code: Select all

function sysCall_init()
    corout=coroutine.create(coroutineMain)
end

function sysCall_actuation()
    if coroutine.status(corout)~='dead' then
        local ok,errorMsg=coroutine.resume(corout)
        if errorMsg then
            error(debug.traceback(corout,errorMsg),2)
        end
    end
end

function addValue(value)
    bufferedValues[#bufferedValues+1]=value
end

function coroutineMain()
    bufferedValues={}
    sim.setThreadAutomaticSwitch(false)
    while #bufferedValues>0 do
        -- process the whole buffer at once
        local v=bufferedValues[1]
        table.remove(bufferedValues,1)
        -- Do something with v
    end
    sim.switchThread()
end
From your client side, when you need to add a new value, simply call addValue in that script, via sim.callScriptFunction

Cheers

Post Reply