cyberbotics / webots

Webots Robot Simulator
https://cyberbotics.com
Apache License 2.0
3.3k stars 1.72k forks source link

Positional Sensor on Rotational Motor has a discontinuous value change at high speeds #6698

Open austingreisman opened 2 weeks ago

austingreisman commented 2 weeks ago

Describe the Bug When running a custom world (has some buildings and flat ground with grass) simulation of the Tesla Model 3 (proto downloaded from your webots cloud site), I am experiencing an issue when running at speeds over 15 m/s (this depends on the basicTimeStep parameter in the World settings).

I am running Webots R2023b.

Steps to Reproduce

  1. Open up a basic world that has a lot of space to drive.
  2. Set your basicTimeStep parameter to 33.
  3. Run the TeslaModel 3 proto in this world at a speed greater than 15 m/s.
  4. See error of Position Sensor (either wheel) spontaneously jumping up in it's cumulative increase/decrease in rads.

Expected behavior There would be a linear increase in difference between the current Position Sensor value read and the previous past the 1.4 rad mark.

Screenshots image

I'll explain some things in this image _leftPositionSensorData = a private variable which holds the this->_leftPositionSensor->getValue() (rads) where _leftPositionSensor is a webots::PositionSensor pointer to the left wheel's position sensor. _previousLeftPositionSensorValue is _leftPositionSensorData value from the previous timestep (0.03 s). RobotSpeed is the speed we are calculating based on the current RPM knowing the wheel radius. CMD is the velocity (m/s) and spin rate (curvature) we are attempting to command to the vehicle.

As you can see from the first mention of _leftPositionSensorData in the terminal from the screenshot, we have a difference between timesteps of approximately 1.41, then to approximately 1.42, then this large jump happens to 4.86 on the third mention of _leftPositionSensorData in the terminal. This is the behaviour I find weird that is messing up my code.

System

Additional context The speed was going crazy at this point (RobotSpeed) because our math would break when this would happen. I have since figured out that you can get a continuous decrease in the angle difference if you take the _leftPositionSensorData and _previousLeftPositionSensorValue, take the absolute, then subtract that value from 2Pi. This is also fairly confusing, but works at the moment... Here is what the code would look like

this->_leftRPM = ((Constants::TwoPI - std::abs(this->_previousLeftPositionSensorValue - this->_leftPositionSensorData)) / leftRpmSamplingPeriod) * SimulatorRobotChassisConstants::RPMConversion;