Creating a spring
Creating a spring
I have read your posts about using a prismatic joint to create a spring damper system and I am still unclear about how to do that, could you walk me through how you would use a prismatic joint to replicate a 12N/m spring with a rest length of .02 meters.
Re: Creating a spring
Hello,
For a spring, you have Hook's law:
F=k*x
where F is the force of a spring, k its constant, and x its displacement (or stretch/compression)
In V-REP, set your joint (let's suppose it's a prismatic joint) into torque/force mode, the motor enabled, the Control loop enabled, Position control (PID) selected, and Regulate torque/force selected. You can do all this in the joint dynamics properties.
In V-REP, with above settings, your joint will exert a force:
F=ctrl*maxForce
where maxforce is the max. torque/force item, and ctrl is a PID control:
ctrl=x*P+integratedErrors*I+(x-previous_x)*D
So, in case of a pure spring:
F=x*P*maxForce
so, k=P*maxForce. In your case, you could pick: maxForce=12 and P=1.
Cheers
For a spring, you have Hook's law:
F=k*x
where F is the force of a spring, k its constant, and x its displacement (or stretch/compression)
In V-REP, set your joint (let's suppose it's a prismatic joint) into torque/force mode, the motor enabled, the Control loop enabled, Position control (PID) selected, and Regulate torque/force selected. You can do all this in the joint dynamics properties.
In V-REP, with above settings, your joint will exert a force:
F=ctrl*maxForce
where maxforce is the max. torque/force item, and ctrl is a PID control:
ctrl=x*P+integratedErrors*I+(x-previous_x)*D
So, in case of a pure spring:
F=x*P*maxForce
so, k=P*maxForce. In your case, you could pick: maxForce=12 and P=1.
Cheers
Re: Creating a spring
hi
I tried this methond , and it shows a very strange graph.
The first strange thing is that the fig is supposed to plot a sin wave.
In the mean time, the amplitude descend fast along with time. The descend is bigger when simulation step time is bigger.
I set step time to 0.1ms, and get this fig. The descend is still unacceptable.
I tried this methond , and it shows a very strange graph.
The first strange thing is that the fig is supposed to plot a sin wave.
In the mean time, the amplitude descend fast along with time. The descend is bigger when simulation step time is bigger.
I set step time to 0.1ms, and get this fig. The descend is still unacceptable.
Last edited by fferri on 09 May 2018, 20:30, edited 1 time in total.
Reason: changed your image links
Reason: changed your image links
Re: Creating a spring
I've find another way slove this problem.
First disable the prismatic joint motor , we don't need the motor contorl.
Then create a threaded script with the following code:
As you can see in the pic, the fig is real sin wave and the descend is very small
cheers!
This script serves as a real spring between the two objects. Here is the result:
First disable the prismatic joint motor , we don't need the motor contorl.
Then create a threaded script with the following code:
Code: Select all
function sysCall_threadmain()
sim.setThreadAutomaticSwitch(false)
cyhandle=sim.getObjectHandle('Cylinder')
cyhandle0=sim.getObjectHandle('Cylinder0')
initPosition=sim.getObjectPosition(cyhandle,cyhandle0)
k=100
while sim.getSimulationState()~=sim.simulation_advancing_abouttostop do
tempPosition=sim.getObjectPosition(cyhandle,cyhandle0)
distance=tempPosition[3]-initPosition[3]
print(distance)
lastforce=distance*k
sim.addForceAndTorque(cyhandle0,{0,0,distance*k},{0,0,0})
sim.switchThread() -- resume in next simulation step
end
end
cheers!
This script serves as a real spring between the two objects. Here is the result:
Last edited by fferri on 09 May 2018, 20:31, edited 2 times in total.
Reason: changed your image links & format your code
Reason: changed your image links & format your code