Mentions légales du service

Skip to content

Disjoint angle ranges in VPL accelerometer event

Created by: ypiguet-epfl

In the code generated for the accelerometer event in advanced mode, the acceleration angle is divided into ranges of 15 degrees. But these ranges are disjoint, because strict inequality comparisons are used with the limit angle. For instance we can get

onevent acc
  call math.atan2(angle, acc[0], acc[2])
  when angle > -1365 and angle < 1365 do
    motor.left.target = 0
    motor.right.target = 0
    emit pair_run 0
  end
  call math.atan2(angle, acc[0], acc[2])
  when angle > 1365 and angle < 4095 do
    motor.left.target = 0
    motor.right.target = 0
    emit pair_run 1
  end

This leaves a hole (angle==1365) which can give an unexpected and problematic behavior if a larger range is built from two pieces as in the code above.

Suggestion: use >= for the lower limit and < for the higher limit in method Compiler::CodeGenerator::visitEventAcc of CompilerVisitors.cpp