webots icon indicating copy to clipboard operation
webots copied to clipboard

TouchSensor return zero force when used in a Joint

Open ShuffleWire opened this issue 1 year ago • 0 comments

Describe the Bug I'm using a TouchSensor as a (3d) force sensor, which is placed at the endPoint of a Hinge. But in this configuration, it return 0. However, if configured as a bumper, it work just fine (return 1, indicating collision). If I use the TouchSensor at the root of the Robot, it work just fine.

Code that do not work :

Robot {
  children [
    HingeJoint {
      endPoint TouchSensor {
        children [
          Shape {
            appearance PBRAppearance {
            }
            geometry Cylinder {
            }
          }
        ]
        boundingObject Cylinder {
        }
        physics Physics {
        }
        type "force-3d"
        lookupTable []
      }
    }
  ]
  controller "my_controller"
}

Code that do work, but it's not my use-case

Robot {
  children [
    TouchSensor {
      children [
        Shape {
          appearance PBRAppearance {
          }
          geometry Cylinder {
          }
        }
      ]
      boundingObject Cylinder {
      }
      physics Physics {
      }
      type "force-3d"
      lookupTable []
    }
  ]
  controller "my_controller"
}

the value of the force is measured using this code

#include <stdlib.h>
#include <unistd.h>
#include <webots/Robot.hpp>
#include <webots/TouchSensor.hpp>

int main()
{
    auto robot = webots::Robot();
    const int timeStep{static_cast<int>(robot.getBasicTimeStep())}; /* Ms */

    webots::TouchSensor *tyreForces = robot.getTouchSensor("touch sensor");
    tyreForces->enable(timeStep);

    while (robot.step(timeStep) != -1)
    {
        const double *forceValues = tyreForces->getValues();
        printf("forceValues %f %f %f\n", forceValues[0], forceValues[1], forceValues[2]);
    }

    return 0;
}

Expected behavior The value of the 3d force (0.000000 0.000000 61418.695377), should be always the same, whatever the setup.

System

  • Operating System: Debian 12
  • Webots 2023b

ShuffleWire avatar Jun 14 '24 15:06 ShuffleWire