Simulating Ratchet Mechanism

Typically: "How do I... ", "How can I... " questions
Post Reply
Lance21
Posts: 2
Joined: 25 Jun 2020, 02:32

Simulating Ratchet Mechanism

Post by Lance21 »

Hello, I am trying to simulate a robot that has a ratchet mechanism (which will allow the joint and robot to rotate clockwise, but restrict rotation in the counterclockwise direction). I was wondering how I could achieve this using CoppeliaSim as I am a fairly new user. Is there a feature that restricts passive joint rotation in one direction? If not how exactly could I accomplish this?

fferri
Posts: 1217
Joined: 09 Sep 2013, 19:28

Re: Simulating Ratchet Mechanism

Post by fferri »

Hi,

maybe you can do that with a Joint callback function.

Lance21
Posts: 2
Joined: 25 Jun 2020, 02:32

Re: Simulating Ratchet Mechanism

Post by Lance21 »

So I was thinking of achieving this using sim.getjointForce to check if the torque applied to the joint was positive or negative. And if it is negative then write a zero velocity to the joint to restrict it from moving in the opposite direction. I do not require specific position control from the joint that the joint callback provides. Would you recommend implementing this method in the joint callback function within the joint child script or writing it in the main robot control script?

Thank you

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

Re: Simulating Ratchet Mechanism

Post by coppelia »

Hello,

I would put that inside of a joint callback function, inside of a child script attached to that joint. And don't check the torque applied to it, but the movement direction instead. Something like:

Code: Select all

function sysCall_init()
    jointHandle=sim.getObjectHandle('joint')
    lastPos=sim.getJointPosition(jointHandle)
end

function sysCall_jointCallback(inData)
    dx=inData.currentPos-lastPos
    dx=math.atan2(math.sin(dx),math.cos(dx))
    lastPos=inData.currentPos
    local outData={}
    outData.velocity=0
    if dx<0 then
        outData.force=0
    else
        outData.force=10
    end
    return outData
end
Make sure that your joint is dynamically enabled, the motor is enabled, and the control loop is enabled too (and you are in position control).

Cheers

Post Reply