cmm-21 / a5

0 stars 0 forks source link

About the blown up pattern of task 2 #2

Open Hustwireless opened 3 years ago

Hustwireless commented 3 years ago

Hi,

I've implemented the Ex.2. However, the blown up pattern is somewhat different from the demo. In the demo, the cude circles around the fixed point horizontally like crasy, while in my implementation, it circles vertically like crasy. Does it suggest that there's some mistakes in this implementation?

Thanks!

eastskykang commented 3 years ago

Please record your demo video, upload it to YouTube or any other video hosting platform and link it here.

Hustwireless commented 3 years ago

Thanks for your reply! I indeed found some mistakes and it looks exactly same with the demo now.

luohwu commented 3 years ago

May I ask what's your mistake? I have the same problem. There will be no problem only if I reduce the constant k of the spring.

Hustwireless commented 3 years ago

Yes, I found my expression for tau and angularvelocity are incorrect.

luohwu commented 3 years ago

Thought that's not my case, thanks a lot.

iqiac commented 3 years ago

Sorry to dig this up again. But isn't the torque just computed by the cross product of r and force, where r is the vector from rigid body COM to point where spring is attached in world frame? Where do you need the angular velocity for task 2? BTW I have the same problem.

PanagiotisAnagnostaras commented 3 years ago

yes same here, I did what iqiac said and have the same problem. Actually if I don't compute the torques everything works perfect (only translational dynamics due to spring forces with stable simulation when integrator of task 3 used). But if I add the torque it becomes unstable

Hustwireless commented 3 years ago

Sorry to dig this up again. But isn't the torque just computed by the cross product of r and force, where r is the vector from rigid body COM to point where spring is attached in world frame? Where do you need the angular velocity for task 2? BTW I have the same problem.

Sorry, maybe I didn't express my errors clearly. It's both my expressions for tau and angular velocities that are incorrect. The problem with my tau is that I mistakenly calculated the torque of gravity twice.

In task 2, I just follow the given formulas and update angular velocities in each time steps, it needs to be updated because the rigid body is rotating, which causing changes in both magnitude and direction of omega.

PanagiotisAnagnostaras commented 3 years ago

I resolved my issue. It was in calling getWorldCoordinates function.It's different if you call V3D(getWorldCoordinated(P3D)) or P3D(getWorldCoordinated(V3D)) , one only rotates while the other rotates and translates , see the definitions

Hustwireless commented 3 years ago

I resolved my issue. It was in calling getWorldCoordinates function.It's different if you call V3D(getWorldCoordinated(P3D)) or P3D(getWorldCoordinated(V3D)) , one only rotates while the other rotates and translates , see the definitions

Good to hear! It also took a while to realize the differences between P3D and V3D.

robindurkowitzer commented 3 years ago

Hello, Mine blows up very Extreme and very fast? Did you also have forces in the 12800 range for the first iteration? it seems huge, but I implemented it straight forward.. EDIT: Found the Function I forgot to implement (addSpringToEngine)

eastskykang commented 3 years ago

I reopened this issue since this thread could be beneficial to others :)

iqiac commented 3 years ago

EDIT: Found the Function I forgot to implement (addSpringToEngine)

@robindurkowitzer How did implementing addSpringToEngine() help? Don't you only have to assign spring->l0 to the norm of the distance vector of pJPos and cJPos in world frame?

Edit: solved it now, seems that I just had a very bad understanding of how to implement the force for task 2.

nwicki commented 3 years ago

I still have some troubles implementing the spring force correctly.

The rest length is defined by the vector spanned by the initial anchor points in world coordinates (V3D), where the anchor point in the world is already in world coordinates whereas the anchor point on the rigid body is in local coordinates and needs transformation.

Now, to compute the angular and linear spring force acting on the rigid body, we need to take the new length into account. If the new spring length is greater than the rest length, we want a force acting towards the world anchor point (and vice versa, computed using P3D). This force direction is scaled by the spring constant and the difference in spring length (if I understood anything wrongly, please correct me).

The torque is then defined by the cross product between the world coordinates of the vector of the center of mass to the anchor point (V3D) and the linear force. The problem I have is that the cube rotates towards the spring instead of away of it (which makes no sense since we have gravity pulling it downwards). Therefore, I inverted the torque and now it seems like a physically more plausible simulation, but it seems wrong to just hack a working solution together. Where did I go wrong?

I recorded the scene for a visualisation of the situation: https://youtu.be/1ErBL8IzvHs

Edit: Specified the conversion of either point or vector coordinates.

eastskykang commented 3 years ago

@nwicki

When you convert a moment arm expressed in world frame, please give an attention if you are giving P3D or V3D.

P3D is for a position of a point, and V3D is for a vector. The moment arm is a vector quantity thus you need to use V3D instead of P3D.

I resolved my issue. It was in calling getWorldCoordinates function.It's different if you call V3D(getWorldCoordinated(P3D)) or P3D(getWorldCoordinated(V3D)) , one only rotates while the other rotates and translates , see the definitions

nwicki commented 3 years ago

I made small annotations to my explanation specifying whether I used P3D or V3D world coordinate conversion (I hope that is what you asked for). I used the V3D conversion to compute the rest length of the spring. To compute the linear force, I used P3D and for the torque I used again V3D conversion.

I just noticed that it makes no sense to use V3D to compute the rest length since we want the vector from point to point, so this might be the problem.

Edit: I checked it, and this was indeed the problem. Thanks for the support :)

TunVunDerBunn commented 3 years ago

My version is also still blowing up more or less vertically. I think I am computing the torque in a wrong way. We assume that the rotation is around the center of mass of the rigid body. Then the gravity makes no torque (as it is applied to the center of mass) and nothing compensates the torque produced by the force of the spring. I would be very grateful, if someone could point me in the right direction. I think I am missing the forest through the trees here.

Hustwireless commented 3 years ago

@TunVunDerBunn I think there's no need to compensate the torque, the torque just provide the angular acceleration in this case. I guess the compensation that you are talking about is used in the statics.

TunVunDerBunn commented 3 years ago

Thank you very much for your reply

robindurkowitzer commented 3 years ago

I think I might have an Error in my implementation of the updated Angular velocity.

In the skeleton code, there was a hint that we have to compute the moment of inertia matrix in World frame. However, if I rotate the local MOI to world and then Implement the formula from the eadme, I get non Zero updates on the Angular Velocity, even thoug tau is 0.

Using the MOI in Local frame does get the desired w_dot = 0,

Is the hint wrong, or do I misunderstand it?

Edit: I am using the local MOI now, and it looks like the Demo.

Hustwireless commented 3 years ago

@robindurkowitzer I've checked it with my implementeation and found that the updates on angular velocity is very close to 0, approximately at the magnitute of 1e-16. I might suggest to check the update of MOI in world frame again, but it could be something else too.