Mimic Thrust Force Model - Cuboid
-
- Posts: 44
- Joined: 24 Feb 2015, 17:06
Mimic Thrust Force Model - Cuboid
I'm trying to make a cuboid rise to a certain height and then stop. The cuboid should keep itself in air till the simulation ends. I'm using the simAddForceAndTorque command and I know that the force and torque are cumulative. How do I keep the object fixed at a certain height after rising?
Here's my model of build:
http://www.filedropper.com/thrustforcep ... uboidstest
Side question:
Do I use height comparison with a constant co-ordinate (example: {0,0,5} ) to adjust the force applied onto the cuboid?
It works like:
If cuboid reaches a a height of z= "5" (from 0,0,5), then the force applied will change. Else, keep rising.
Regards,
Danny
Here's my model of build:
http://www.filedropper.com/thrustforcep ... uboidstest
Side question:
Do I use height comparison with a constant co-ordinate (example: {0,0,5} ) to adjust the force applied onto the cuboid?
It works like:
If cuboid reaches a a height of z= "5" (from 0,0,5), then the force applied will change. Else, keep rising.
Regards,
Danny
Re: Mimic Thrust Force Model - Cuboid
Hello Danny,
the forces/torques you apply with simAddForceAndTorque (or simAddForce) are cumulative in a given simulation step. But the cumulated force/torque will be cleared at the end of one simulation step.
But your approach is correct. I would implement a simple P controller for your force, instead of an on/off controller.
Cheers
the forces/torques you apply with simAddForceAndTorque (or simAddForce) are cumulative in a given simulation step. But the cumulated force/torque will be cleared at the end of one simulation step.
But your approach is correct. I would implement a simple P controller for your force, instead of an on/off controller.
Cheers
-
- Posts: 44
- Joined: 24 Feb 2015, 17:06
Re: Mimic Thrust Force Model - Cuboid
I've tried using this coding:coppelia wrote:Hello Danny,
the forces/torques you apply with simAddForceAndTorque (or simAddForce) are cumulative in a given simulation step. But the cumulated force/torque will be cleared at the end of one simulation step.
But your approach is correct. I would implement a simple P controller for your force, instead of an on/off controller.
Cheers
Code: Select all
simAddForceAndTorque(propeller,force,torque)
position1={0,0,0.5}
if simGetObjectPosition(propeller,-1)>=position1 then
force={0,0,0}
torque={0,0,0}
else
force={0,0,10}
torque={0,0,0}
end
-
- Posts: 44
- Joined: 24 Feb 2015, 17:06
Re: Mimic Thrust Force Model - Cuboid
Update to previous reply: I've found out how to refer the "Z" co-ordinate of the object, turns out I just have to define the object's position usingDannyYeong wrote:I've tried using this coding:coppelia wrote:Hello Danny,
the forces/torques you apply with simAddForceAndTorque (or simAddForce) are cumulative in a given simulation step. But the cumulated force/torque will be cleared at the end of one simulation step.
But your approach is correct. I would implement a simple P controller for your force, instead of an on/off controller.
Cheers
Apparently I can't compare <= or >= for a vector. I want to let it "float" itself on air after it reaches a specific height. However I could only use "==" or "~=", which is not the best option since the object will always surpass the specific height due to inertia, which keeps the object flying upwards. So how do I use the Z position as a variable to be compared with a fixed constant/threshold?Code: Select all
simAddForceAndTorque(propeller,force,torque) position1={0,0,0.5} if simGetObjectPosition(propeller,-1)>=position1 then force={0,0,0} torque={0,0,0} else force={0,0,10} torque={0,0,0} end
Code: Select all
pos=simGetObjectPosition(propeller,-1)
Code: Select all
pos[3] -- the "3" refers to the 3rd vector, Z co-ordinate
Code: Select all
if (sim_call_type==sim_childscriptcall_initialization) then
propeller=simGetObjectHandle('Cuboid')
ground={0,0,0} --ignore this for the moment
pos1={0,0,0.5}
end
if (sim_call_type==sim_childscriptcall_actuation) then
pos=simGetObjectPosition(propeller,-1)
simAddForceAndTorque(propeller,force,torque)
if pos[3]<pos1[3] then
force={0,0,10}
torque={0,0,0}
else
force={0,0,0}
end
end
I wanted the object to stay in air while "bouncing about" (like a quadcopter rising motion to achieve balance in Z direction) but it keeps hitting the ground eventhough I've programmed it to apply force if the height drops a specific level. What coding I should use if the current one is not suitable or is there any add-on branch I should include in the ifelse case?
Regards,
Danny
Re: Mimic Thrust Force Model - Cuboid
You need to write a correct controller for your force. You also need drag (the D component of a PID controller). Maybe something like:
Cheers
Code: Select all
if (sim_call_type==sim_childscriptcall_actuation) then
local pos=simGetObjectPosition(propeller,-1)
local accel=simGetArrayParameter(sim_arrayparam_gravity)
-- cm is the proportional parameter of the PD controller:
local cm=(pos1[3]-pos[3])/0.05
if (cm>1.05) then cm=1.05 end
if (cm<0) then cm=0 end
-- str is the derivative paramter of the PD controller
local str=-5 -- drag
simAddForceAndTorque(propeller,{0,0,-accel[3]*cm})
local linV,angV=simGetVelocity(propeller)
local mass=simGetShapeMassAndInertia(propeller)
local f={linV[1]*mass*str*cm,linV[2]*mass*str*cm,linV[3]*mass*str*cm}
simAddForceAndTorque(propeller,f)
end
-
- Posts: 44
- Joined: 24 Feb 2015, 17:06
Re: Mimic Thrust Force Model - Cuboid
coppelia wrote:You need to write a correct controller for your force. You also need drag (the D component of a PID controller). Maybe something like:CheersCode: Select all
if (sim_call_type==sim_childscriptcall_actuation) then local pos=simGetObjectPosition(propeller,-1) local accel=simGetArrayParameter(sim_arrayparam_gravity) -- cm is the proportional parameter of the PD controller: local cm=(pos1[3]-pos[3])/0.05 if (cm>1.05) then cm=1.05 end if (cm<0) then cm=0 end -- str is the derivative paramter of the PD controller local str=-5 -- drag simAddForceAndTorque(propeller,{0,0,-accel[3]*cm}) local linV,angV=simGetVelocity(propeller) local m=simGetObjectMatrix(propeller,-1) local mass=simGetShapeMassAndInertia(propeller) m[4]=0 m[8]=0 m[12]=0 local mi=simGetInvertedMatrix(m) linV=simMultiplyVector(mi,linV) linV[1]=0 linV=simMultiplyVector(m,linV) local f={linV[1]*mass*str*cm,linV[2]*mass*str*cm,linV[3]*mass*str*cm} simAddForceAndTorque(propeller,f) end
Hi, I don't understand the Derivative part of the coding, added my comments into it below:
Code: Select all
-- str is the derivative paramter of the PD controller
local str=-5 -- drag
simAddForceAndTorque(propeller,{0,0,-accel[3]*cm})
local linV,angV=simGetVelocity(propeller)
local m=simGetObjectMatrix(propeller,-1)
local mass=simGetShapeMassAndInertia(propeller)
m[4]=0
m[8]=0
m[12]=0
local mi=simGetInvertedMatrix(m)
linV=simMultiplyVector(mi,linV)
linV[1]=0 -- ||||||||||||||||||why set the first value to 0?
linV=simMultiplyVector(m,linV) -- |||||||||||||||||Why multiplied?
local f={linV[1]*mass*str*cm,linV[2]*mass*str*cm,linV[3]*mass*str*cm}
simAddForceAndTorque(propeller,f)
Re: Mimic Thrust Force Model - Cuboid
You are right, the code was copy-pasted from another example, where the drag had to be relative to the shape frame, and only radial to it. See the updated version above.
Cheers
Cheers
-
- Posts: 44
- Joined: 24 Feb 2015, 17:06
Re: Mimic Thrust Force Model - Cuboid
Might need some clarification on the 1.05 constant chosen, how it's that obtained?coppelia wrote:You are right, the code was copy-pasted from another example, where the drag had to be relative to the shape frame, and only radial to it. See the updated version above.
Cheers
-
- Posts: 44
- Joined: 24 Feb 2015, 17:06
Re: Mimic Thrust Force Model - Cuboid
DannyYeong wrote:Might need some clarification on the 1.05 constant chosen, how it's that obtained?coppelia wrote:You are right, the code was copy-pasted from another example, where the drag had to be relative to the shape frame, and only radial to it. See the updated version above.
Cheers
Found out for its reason, its just a self-made constant to provide a force more than the gravity force so it'll lift up. Thanks for the info provided. I tried my own, and apparently the Drag is really a problem. At this point of coding:
Code: Select all
pos=simGetObjectPosition(propeller,-1)
grav=simGetArrayParameter(sim_arrayparam_gravity)
mass=simGetShapeMassAndInertia(propeller)
diff=pos1[3]/pos[3] -- <1 shows over extended, >1 shows under extended
if diff<1 then -- upward force
f={0,0,-grav[3]*mass*0.99}
simAddForceAndTorque(propeller,f)
end
if diff>1 then --downward force and to prevent drag force
f={0,0,-grav[3]*mass*1.01}
simAddForceAndTorque(propeller,f)
end
http://www.filedropper.com/thrustforcep ... uboidstest
The object is currently being dragged up but it exceeds the height and then drops. After the first process, the object goes up and down by alittle to balance itself. However, onwards process seems to go higher and more lower than the first cycle. Is this caused by the drag? If so, could I try a different approach to control the drag using another way other than velocity?
Re: Mimic Thrust Force Model - Cuboid
You are using a simple 2-state controller. Either you apply a force of X, or a force of Y. It is normal that your control won't be good. You will have to use something more sofisticated, at least a P/PD controller. You will have to try.
Cheers
Cheers