Trying to emulate a Gimbal in 2 axis (horizontal and vertical) but a joint doesnt rotate

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

Trying to emulate a Gimbal in 2 axis (horizontal and vertical) but a joint doesnt rotate

Post by Javierrc99 »

Hi, i'm using CoppeliaSim trying to emulate a "gimbal" for a visual sensor
attached to it.
The model is pretty simple, i attached 2 joint revolutes with the aux
masses scheme to enable the dinamic simulation. But althought one of the
joints actually revolves, the other doesnt seem to work. Im trying to
control both of them via the camera info. But I think the rotation of both
joints should be able of being tried with just the 2 child scripts setting
velocity references.
Well, i resumed the question, i'm pretty stucked with this and couldn't
find a solution elsewhere.
I leave the scene attached so u can try and check if "pitch" joint rotates, and why it doesnt:
https://drive.google.com/file/d/1DRvTU_ ... sp=sharing
Note: "pitch" and "yaw" are the names of both revolutes joints.
Good afternoon and thanks.

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

Re: Trying to emulate a Gimbal in 2 axis (horizontal and vertical) but a joint doesnt rotate

Post by Javierrc99 »

Note, i just tried with the simple model i attached and it seems both work well, but i wanted to command them from an external Python Script. Here is when things seem to go wrong and it just rotates in "yaw" joint even though i set the target velocity to the "pitch" joint.
Should i try to make the control of both joints in its respective child script (like i compute the velocity reference externally and pass it to each child script) and maybe that way it works?

I attach here the external script trying to command both joints:
https://drive.google.com/file/d/1DRvTU_ ... sp=sharing
Mainly the control is done in lines 155-161

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

Re: Trying to emulate a Gimbal in 2 axis (horizontal and vertical) but a joint doesnt rotate

Post by coppelia »

Hello,

for a camera, there is no need to use dynamic joints (i.e. joints that operate in force/torque), easiest would be to simply use two kinematic joints (passive mode), like:

Code: Select all

base --> yaw --> pitch --> cam
Also, no need to attach a child script to each of the joints. You can directly control those joints, when in kinematic mode, via sim.setJointPosition, also via an external application. Make sure to use the ZeroMQ remote API when using Python.

If you need your joints to move to a specific position not instantly, but via a specific movement profile, then you can use a child script similar to this one, for each of your joints:

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 movCallback(config,vel,accel,handles)
    if sim.isDynamicallyEnabled(joint) then
        sim.setJointTargetPosition(joint,config[1])
    else    
        sim.setJointPosition(joint,config[1])
    end
end

function coroutineMain()
    joint=sim.getObject('.')

    local maxVel=110  
    local maxAccel=40
    local maxJerk=80

    while true do
        local targetAngle=sim.getFloatSignal('tiltAngle')
        if targetAngle then
            sim.clearFloatSignal('tiltAngle')
            sim.moveToConfig(-1,{sim.getJointPosition(joint)},nil,nil,{maxVel},{maxAccel},{maxJerk},{targetAngle},nil,movCallback)
        else
            sim.switchThread()
        end
    end
end
and from your client, you can then set the desired target angle via, e.g. sim.setFloatSignal('tiltAngle',angleInRadians)

Cheers

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

Re: Trying to emulate a Gimbal in 2 axis (horizontal and vertical) but a joint doesnt rotate

Post by Javierrc99 »

Thank you very much, I ve been really busy with University matters (this is also an University project), so I couldn't check on the reply. I just did it, and it seems like it moves like i wanted with the child scripts and the external command of the angle via python.
Have a good day and thanks again

Post Reply