Servo

Introduction

The servo is used to turn the sensor so that it can scan the grid to be mapped.

The servo may not be oriented with the gird X and Y axes. Therefore an adjustment must be made to the sensor angle used to calculate an object's coordinates.

I am using a servo that rotates counterclockwise from 0 to 180. Each position is assumed to be degrees from the zero direction.

The sensor is attached to the servo at the center of its rotation. The sensor point in the direction the servo has rotated to.

Because the sensor angle is measured from the positive X axis when calculating and objects coordinates, the sensor's adjustment angle must be used.

Note: See object coordinate calculation.

Diagram

image Missing

Calculations (pseudo code)

SRA - servo rotation angle (0 to 180)
      The sensor points in this direction.
SAA - sensor adjustment angle
      Counterclockwise from positive X axis.
SA  - sensor angle used in object coordinate calculations

SA = (SRA + SAA) % 360

Note: For integers only
359   % 360    = 359
360   % 360    = 0
361   % 360    = 1
359.1 % 360.0  = 359
360.1 % 360.0  = 0
361.1 % 360.0  = 1

PERL Code For Floating Point Numbers

use strict;

print "results: " . modFloatingPoint(359.1,360.0) . "\n";
print "results: " . modFloatingPoint(360.1,360.0) . "\n";
print "results: " . modFloatingPoint(361.1,360.0) . "\n";

sub modFloatingPoint
{
   my $n1 = $_[0];             # dividend
   my $n2 = $_[1];             # divisor

   my $n = int($n1/$n2);

   return $n1 - ($n * $n2);    # mod(n1/n2)
}
results: 359.1
results: 0.100000000000023
results: 1.10000000000002