#VRML_SIM R2023b utf8
# template language: javascript

PROTO UltrasoundModule [
  field SFString name ""
  field SFVec3f translation 0 0 0
  field SFRotation rotation 0 0 1 0
  field SFInt32 range 4
  field SFBool upright FALSE
] {
  DistanceSensor {
    name IS name
    translation IS translation
    rotation IS rotation
    type "sonar"
    numberOfRays 10
    aperture 0.3
    lookupTable [
      # 1% standard deviation, with no deviation at the limits
      0 0 0
      0.01 10 0.01
      %<= fields.range.value * 0.99 >% %<= fields.range.value * 1000 * 0.99 >% 0.01
      %<= fields.range.value >% %<= fields.range.value * 1000 >% 0
      # Return 0 for out of range values
      %<= fields.range.value + 0.001 >% 0 0
    ]
    children [
      Pose {
        %< if (fields.upright.value) { >%
        rotation 0 1 1 3.14159
        %< } else { >%
        rotation 0 0 1 3.14159
        %< } >%
        children [
          Shape {
            appearance PBRAppearance {
              baseColor 0.1 0.1 1
              metalness 0
            }
            geometry Box {
              size 0.002 0.045 0.02
            }
          }
          Pose {
            translation -0.007 0.013 0
            rotation 0 -1 0 1.5708
            children [
              DEF SONAR_TRX Shape {
                appearance PBRAppearance {
                  baseColor 0.92 0.92 0.92
                  roughness 0.3
                }
                geometry Cylinder {
                  radius 0.008
                  height 0.012
                  subdivision 12
                  bottom FALSE
                }
                castShadows FALSE
              }
            ]
          }
          Pose {
            translation -0.007 -0.013 0
            rotation 0 -1 0 1.5708
            children [
              USE SONAR_TRX
            ]
          }
        ]
      }
    ]
  }
}

