raisimTech / raisimLib

Visit www.raisim.com
http://www.raisim.com
Other
341 stars 91 forks source link

An inverted contact force #482

Closed edward9503 closed 1 year ago

edward9503 commented 1 year ago

Hi,

when I use

for(auto& fs_: footContactState_mrt_) fs_ = false;
    footContactForce_.setZero();

    for(auto& contact_: anymal.back()->getContacts()) {
        if (contact_.skip()) continue; /// if the contact is internal, one contact point is set to 'skip'
        auto it_ = std::find(footIndices_.begin(), footIndices_.end(), contact_.getlocalBodyIndex());
        size_t index_ = it_ - footIndices_.begin();
        if (index_ < 4){
            footContactState_mrt_[index_] = true;
            footContactForce_.segment<3>(index_ * 3) = contact_.getContactFrame().e().transpose() * contact_.getImpulse().e() / dt;
        }
    }

to measure the contact force between foot and ground, the direction is inverted (pointing to the ground). Is it a bug somewhere? Thanks.

jhwangbo commented 1 year ago

Raisim doesn't have a perference on objects to define the contact force direction. That contact force is exerted by the robot to the ground and it is just one of the two possible choices. You have a method call contact_.isObjectA(). If the object is objectA, it means that the contact force is exerted by something else and experienced by the object.

edward9503 commented 1 year ago

Hi @jhwangbo , thanks for the reply. I just updated the raisimLib because I was using the old version since last year, in which the isObjectA() didn't exist.

So if I understand correctly, in order to get the force from the ground and also the corresponding contact frame direction, I need to check isObjectA in the loop, and only True will give me the desired force and contact frame orientation?

jhwangbo commented 1 year ago

https://github.com/raisimTech/raisimLib/blob/86c9e6a94d781605b0656263f695fbaf9e03255b/raisim/linux/include/raisim/contact/Contact.hpp#L164

This method. Yes, but even if the object is objectB you can just put negative on the force and rotate the frame by 180 degree