We cant figure out why the distance is not correct. We have the light at 4 ft and the camera is 15.5 inches off the ground. We used the equation, and it is giving us strange answers. Any help of ideas would be appeciated

#include <stdio.h>
#include “ifi_aliases.h”
#include “ifi_default.h”
#include “camera.h”
#include “tracking.h”
#include “math.h”

void Tracking_Info_Terminal(void)
{
static unsigned char i = 0;
static unsigned char j = 0;
static unsigned int old_camera_t_packets = 0;
static unsigned int distance_woota = 0 ;
// has a new camera tracking packet arrived since we last checked?
if(camera_t_packets != old_camera_t_packets)
{
// increment the t-packet counter
i++;

``````    distance_woota = (33/(tan(((TILT_SERVO - 144) * 25)/50)));

// reset the "no camera data" loop counter
j = 0;

// only show data on every twenty t-packets
if(i &gt;= 20)
{
// reset the local t-packet counter
i = 0;

// does the camera have a tracking solution?
if(Get_Tracking_State() == SEARCHING)
{
printf("Searching...
``````

“);
}
else
{
printf(”
");

// pan angle = ((current pan PWM) - (pan center PWM)) * degrees/pan PWM step

printf(" Pan Angle (degrees) = %d
", (((int)PAN_SERVO - 144) * 65)/124);

// tilt angle = ((current tilt PWM) - (tilt center PWM)) * degrees/tilt PWM step

printf("Tilt Angle (degrees) = %d
", (((int)TILT_SERVO - 144) * 25)/50);

printf(" Pan Error (Pixels) = %d
", (int)T_Packet_Data.mx -

Tracking_Config_Data.Pan_Target_Pixel);

printf("Tilt Error (Pixels) = %d
", (int)T_Packet_Data.my - Tracking_Config_Data.Tilt_Target_Pixel);

printf(" Blob Size (Pixels) = %u
", (unsigned int)T_Packet_Data.pixels);

printf("Confidence (Pixels) = %u
", (unsigned int)T_Packet_Data.confidence);

printf("DiStAnCe HAHAHHA = %d
", (int) distance_woota);

Any ideas would be greatly appreciated.

Here are a couple things you could try:

1. Are you sure the value you’re passing to tan() is in radians as opposed to degrees?
2. Try typecasting the assignment to distance_woota as an int.