IR Tracker

download IR Tracker

of 16

Transcript of IR Tracker

  • 7/31/2019 IR Tracker

    1/16

  • 7/31/2019 IR Tracker

    2/16

    o 5.1 Outline of Code

    o 5.2 main()

    o 5.3 runsetup()

    o 5.4 encodersave()

    o 5.5 positioncount()

    o 5.6 ircheck()o 5.7 equalize()

    o 5.8 servotrack()

    6 Resultso 6.1 Final Design

    o 6.2 Video

    7 Reflectionso 7.1 Objectives Met

    o 7.2 Problems Encountered

    o 7.3 Future Work

    Team Members

    Left to right: Matt, Mark and Alice

    Mark Straccia (Mechanical Engineering, Class of 2009) Matt Turpin (Mechanical Engineering, Class of 2009) Alice Zhao (Electrical Engineering, Class of 2008)

    Overview

    http://hades.mech.northwestern.edu/index.php/IR_Tracker#Outline_of_Codehttp://hades.mech.northwestern.edu/index.php/IR_Tracker#main.28.29http://hades.mech.northwestern.edu/index.php/IR_Tracker#runsetup.28.29http://hades.mech.northwestern.edu/index.php/IR_Tracker#encodersave.28.29http://hades.mech.northwestern.edu/index.php/IR_Tracker#positioncount.28.29http://hades.mech.northwestern.edu/index.php/IR_Tracker#ircheck.28.29http://hades.mech.northwestern.edu/index.php/IR_Tracker#equalize.28.29http://hades.mech.northwestern.edu/index.php/IR_Tracker#servotrack.28.29http://hades.mech.northwestern.edu/index.php/IR_Tracker#Resultshttp://hades.mech.northwestern.edu/index.php/IR_Tracker#Final_Designhttp://hades.mech.northwestern.edu/index.php/IR_Tracker#Videohttp://hades.mech.northwestern.edu/index.php/IR_Tracker#Reflectionshttp://hades.mech.northwestern.edu/index.php/IR_Tracker#Objectives_Methttp://hades.mech.northwestern.edu/index.php/IR_Tracker#Problems_Encounteredhttp://hades.mech.northwestern.edu/index.php/IR_Tracker#Future_Workhttp://hades.mech.northwestern.edu/index.php/Image:IR_Tracker_Team.jpghttp://hades.mech.northwestern.edu/index.php/Image:IR_Tracker_Team.jpghttp://hades.mech.northwestern.edu/index.php/IR_Tracker#Outline_of_Codehttp://hades.mech.northwestern.edu/index.php/IR_Tracker#main.28.29http://hades.mech.northwestern.edu/index.php/IR_Tracker#runsetup.28.29http://hades.mech.northwestern.edu/index.php/IR_Tracker#encodersave.28.29http://hades.mech.northwestern.edu/index.php/IR_Tracker#positioncount.28.29http://hades.mech.northwestern.edu/index.php/IR_Tracker#ircheck.28.29http://hades.mech.northwestern.edu/index.php/IR_Tracker#equalize.28.29http://hades.mech.northwestern.edu/index.php/IR_Tracker#servotrack.28.29http://hades.mech.northwestern.edu/index.php/IR_Tracker#Resultshttp://hades.mech.northwestern.edu/index.php/IR_Tracker#Final_Designhttp://hades.mech.northwestern.edu/index.php/IR_Tracker#Videohttp://hades.mech.northwestern.edu/index.php/IR_Tracker#Reflectionshttp://hades.mech.northwestern.edu/index.php/IR_Tracker#Objectives_Methttp://hades.mech.northwestern.edu/index.php/IR_Tracker#Problems_Encounteredhttp://hades.mech.northwestern.edu/index.php/IR_Tracker#Future_Work
  • 7/31/2019 IR Tracker

    3/16

    The goal of this project was to create a device that would follow a moving infrared light.The IR Tracker does this by continuously detecting the position of an infrared emitter intwo axises, and then tracking the emitter with a laser.

    The IR Tracker follows two major steps: (1) Identify the position of the IR emitter (2)Rotate the device to align itself with the IR emitter.

    1. The IR Tracker finds the location of the maximum infrared intensity in both the x-axis and y-axis. Two encoders continuously record the position of the IR emitterbased on intensity levels detected by two IT detectors.

    2. Given the information about the location of the IR emitter, the device rotates itselfin two dimensions to adjusts its plane to be normal to the IR emitter. At this point,the laser should point to the IR emitter.

    We will discuss the mechanical design, electrical design, PIC code, resulting project andour team reflections.

    Mechanical Design

    Primary Components

    The primary components used in this device are:

    2 Pitman Motors 2 RC Servos 1 Turntable (6031K17, McMaster-Carr, $2.20, readily available) 1 Cylindrical Bearing 1 Laser Mirror Plexiglas

  • 7/31/2019 IR Tracker

    4/16

    Detecting Component

    Detecting Component

    http://hades.mech.northwestern.edu/index.php/Image:Detecting_Component.jpghttp://hades.mech.northwestern.edu/index.php/Image:Detecting_Component.jpghttp://hades.mech.northwestern.edu/index.php/Image:Mechanical_Design.jpg
  • 7/31/2019 IR Tracker

    5/16

    On the main plane of the device, two encoders are placed perpendicular to each other (ableto track on two axises). Mirrors are placed on the output shafts of the two encoders at 45degree angles. Two infrared detectors are placed in line with the encoders. While theencoders are constantly spinning, the mirrors detect light from the IR emitter and bouncethe light to the IR detectors.

    Rotating Component

    Rotating Component

    Below the main plane of the device, two servos are used to rotate the entire device to alignthe main plane to be normal to the emitter. The main plane is attached to a block ofPlexiglas that surrounds a cylindrical bearing. This bearing allows the main plane to rotatealong the y-axis. This block of Plexiglas is mounted on a turntable which allows the mainplane to rotate along the x-axis.

    Electrical Design

    Primary Components

    http://hades.mech.northwestern.edu/index.php/Image:Rotating_Component.jpghttp://hades.mech.northwestern.edu/index.php/Image:Rotating_Component.jpg
  • 7/31/2019 IR Tracker

    6/16

    The primary components used in this circuit are:

    1 PIC (18F4520) 2 IR Detector / Emitter Pairs 2 Hall Sensors & Small Magnets

    2 MOSFETs 1 Inverting Schmidt Trigger (74HC14)

    IR Tracker Schematic (includes original H-Bridge in design --> use MOSFETs instead)

    http://hades.mech.northwestern.edu/index.php/Image:Circuit_Diagram.jpghttp://hades.mech.northwestern.edu/index.php/Image:Circuit_Diagram.jpg
  • 7/31/2019 IR Tracker

    7/16

    IR Tracker Top View

    IR Detector

    IR Detector / Emitter Pairs

    The IR Detector detects the intensity of IR light coming from the IR Emitter. Over eachrevolution of the encoder's output shaft, the location of the maximum IR intensity isrecorded. This information is given to the PIC to determine the servo's next position.

    http://hades.mech.northwestern.edu/index.php/Image:IR_Detector_Emitter.jpghttp://hades.mech.northwestern.edu/index.php/Image:IR_Detector_Emitter.jpghttp://hades.mech.northwestern.edu/index.php/Image:Circuit_Top_View.jpghttp://hades.mech.northwestern.edu/index.php/Image:Circuit_Top_View.jpg
  • 7/31/2019 IR Tracker

    8/16

    Hall Sensors

    Hall Sensors

    The Hall Sensors are used as a position marker for the encoders. They are located justbelow the output shafts of the encoders. A small magnet is placed on the side of the outputshafts. As both encoder shafts spin, the Hall Sensor detects the location of the magnet. Thepurpose of the Hall Sensors is to use this information to sync the rotations of the twoencoder shafts.

    PIC

    The PIC is the central controller of the IR Tracker.

    MOSFETs

    The MOSFETs are used as intermediate components between the PIC and the servomotors. It allows the Pittman motors to run in one direction.

    Inverting Schmidt Trigger

    The Schmidt Trigger acts as an intermediate between both the PIC to the encoders on themotors and the PIC to the Hall Sensors. It helps filter out noisy signals and invert signals tobe readable for the PIC.

    Code

    See full code here

    Outline of Code

    Here is a general outline of what the IR Tracker does:

    http://hades.mech.northwestern.edu/images/1/1b/IR_Tracker_Code.chttp://hades.mech.northwestern.edu/index.php/Image:Hall_Sensors.jpghttp://hades.mech.northwestern.edu/index.php/Image:Hall_Sensors.jpghttp://hades.mech.northwestern.edu/images/1/1b/IR_Tracker_Code.c
  • 7/31/2019 IR Tracker

    9/16

    1. Spin encoder shafts2. Record current position of the servo3. Determine location of the maximum IR intensity detected4. Convert encoder position to servo position5. Rotate the main plane to the new servo position

    6. Sync rotations of the two encoder shafts7. Repeat steps 2-6

    main()

    This is the main function of our code:

    void main(){

    runsetup();

    while (TRUE){

    encodersave();positioncount();ircheck();equalize();

    }}

    The five functions it encompasses are described in detail below.

    runsetup()

    The interrupts for both servos and Hall sensors are set, and motors begin to spin at fullvelocity. This function is only called once at the beginning of the main function.

    void runsetup(){

    setup_timer_0(RTCC_EXT_L_TO_H | RTCC_DIV_1); //External inputfrom quadrature encoder 0

    setup_timer_1(T1_EXTERNAL | T1_DIV_BY_1); //External input

    from quadrature encoder 1setup_timer_2(T2_DIV_BY_4, 255, 5); //Servoincrememnting timer at 1 kHz

    setup_timer_3(T3_INTERNAL | T3_DIV_BY_4); //Servo resetingtimer

    enable_interrupts(INT_TIMER2); //Enable ISR2 forservo

    enable_interrupts(INT_TIMER3); //Enable ISR3 forservo

  • 7/31/2019 IR Tracker

    10/16

    enable_interrupts(INT_EXT); //EnableInterrupt for Hall sensor X

    enable_interrupts(INT_EXT1); //EnableInterrupt for Hall sensor Y

    enable_interrupts(global);

    setup_ccp1(ccp_pwm); //Setup PWM1setup_ccp2(ccp_pwm); //Setup PWM2

    set_timer0(0); //Clear starting

    point of countersset_timer1(0);

    set_PWM1_duty(0); //Motors off for

    startupset_PWM2_duty(0);

    for(ii=0;ii

  • 7/31/2019 IR Tracker

    11/16

    {if (PositionCountX >4875){

    output_high(pin_D3);}else if(PositionCountX>0){

    output_low(pin_D3);}if (PositionCountY > 4875){

    output_high(pin_D4);}else if(PositionCountY>0){

    output_low(pin_D4);}

    }

    ircheck()

    This finds the location of maximum infrared light in both the x-axis and y-axis. Thisinformation is originally collected as an encoder position count value, is converted into anangle in degrees and is then converted again into servo position count value, so that theservo can move to the appropriate location.

    void ircheck() //Check to seewhere in the rotation{

    if(PositionCountX=4875)&&(MomentCountX>5)) //Runs when this

    function is called and IR detector{

    AverageAngleX = (MomentX/MomentCountX); //Average themoment to give the center of IR in terms of motor encoder counts

    if (((AverageAngleX)>650)&&((AverageAngleX)

  • 7/31/2019 IR Tracker

    12/16

    {AnglePositionX = 3647-23*AverageAngleX/34; //Convert motor

    encoder counts to servo values

    if (ServoCurrent[0] + AnglePositionX < 1950) //Less than 90degress

    {ServoTargetX = 400;

    }else if (ServoCurrent[0] + AnglePositionX> 4250) //Greater

    than 450 degrees{

    ServoTargetX = 2700;}else //between 90 and

    450 degrees{

    ServoTargetX = AnglePositionX + ServoCurrent[0] - 1550;}

    }

    MomentX = 0; //reset momentvariables

    MomentCountX = 0;}

    if(PositionCountY=4875)&&(MomentCountY>5)){

    AverageAngleY = (MomentY/MomentCountY);

    if (((AverageAngleY)>650)&&((AverageAngleY) 4250) // greater

    450 deg{

    ServoTargetY = 2700;}

  • 7/31/2019 IR Tracker

    13/16

    else{

    ServoTargetY = AnglePositionY + ServoCurrent[1] - 1550;}

    }MomentY = 0;MomentCountY = 0;

    }}

    equalize()

    This syncs the speed and direction of the rotation of the two encoder motors.

    void equalize() //puts motors inphase with each other{if(PositionCountX>PositionCountY){

    set_PWM1_duty(850);set_PWM2_duty(1023);

    }else if (PositionCountX

  • 7/31/2019 IR Tracker

    14/16

    ServoCurrent[0] = ServoTargetX;}SlowServoX=0;

    }if(((SlowServoY>15)&&(abs(ServoTargetY-ServoCurrent[1])>5))||

    ((SlowServoY>8)&&(abs(ServoTargetY-ServoCurrent[1])>125))||((SlowServoY>3)&&(abs(ServoTargetY-ServoCurrent[1])>450))||

    SlowServoY>100)

    {if (ServoCurrent[1] < ServoTargetY - ServoMove){

    ServoNextY = ServoCurrent[1] + ServoMove;ServoCurrent[1] = ServoNextY;

    }else if (ServoCurrent[1] > ServoTargetY + ServoMove){

    ServoNextY = ServoCurrent[1] - ServoMove;ServoCurrent[1] = ServoNextY;

    }

    else{

    ServoCurrent[1] = ServoTargetY;}SlowServoY=0;

    }

    SlowServoX++;SlowServoY++;

    }

    Results

    Final Design

  • 7/31/2019 IR Tracker

    15/16

    Video

    "See Spot Run": Clickhere to see a movie of our final project.

    Reflections

    Overall, our team is very satisfied with our end result.

    Objectives Met

    Ability to locate the position of an IR emitter on two axises. Ability to rotate to align its plane to be normal to an IR emitter. Ability to continuously track an IR signal.

    Problems Encountered

    (Mechanical) Initially, the device had very shaky movements. We added additionalscrews to make the device more stable.

    (Electrical) We added Schmidt Triggers to clean up the noisy signals from the servomotors to the PICs.

    http://depot.northwestern.edu/mht363/public_html/IR%20Track/Mar%2019%20IR%20tracker.mp4http://hades.mech.northwestern.edu/index.php/Image:Final_Design.jpghttp://depot.northwestern.edu/mht363/public_html/IR%20Track/Mar%2019%20IR%20tracker.mp4
  • 7/31/2019 IR Tracker

    16/16

    (Code) Originally coded to track direction of change of the IR emitter and supposedto move accordingly. We encountered a lot of noise. We changed the code to findthe exact position of the IR emitter instead.

    (Electrical) The L298N H-bridge ended up heating up the entire circuit. In our finaldesign, we chose to use MOSFETS in their place.

    Future Work

    More powerful servos and a more accurately calculated counterweight would helpsmooth the movement of the device.

    A more sensitive IR detector could track lower intensities of IR light in a room,instead of specifically an IR emitter.

    With more precise measurements of the relationship between the encoder and servovalues, the IR Tracker could more accurately determine the position of an IR signal.