Difference between revisions of "S13: Solar Panel Tracker"

From Embedded Systems Learning Academy
Jump to: navigation, search
(Abstract)
(Project Source Code)
 
(38 intermediate revisions by 2 users not shown)
Line 1: Line 1:
=== Grading Criteria ===
+
== Solar Panel Tracker ==
<font color="green">
 
*  How well is Software & Hardware Design described?
 
*  How well can this report be used to reproduce this project?
 
*  Code Quality
 
*  Overall Report Quality:
 
**  Software Block Diagrams
 
**  Hardware Block Diagrams
 
**:  Schematic Quality
 
**  Quality of technical challenges and solutions adopted.
 
</font>
 
 
 
== Project Title ==
 
  
 
== Abstract ==
 
== Abstract ==
Line 17: Line 5:
  
 
== Objectives & Introduction ==
 
== Objectives & Introduction ==
The objective of this project is to create a solar panel that tracks the sun. The project will consist of two stepper motors that control the direction of the solar panel and photo resistors(direct the direction of the sun).
+
Solar Panel Sun tracker uses the inputted voltage from photo resistors in order to adjust the position of the solar panel.  The project uses  and Analog to digital converter.  The servo motors are controlled using a pulse; this controls the position of various angles.  The servo uses in this project is a standard servo which can only position between 0 and 180 degrees.  
 +
 +
The project required the following objectives to be accomplished:
 +
* Read the voltage from photo resistors
 +
* Control servo to move from 0 to 180 degrees
 +
* Compute the location which has the greatest light intensity
 +
* Determine algorithm to convert digital value into servo position
 +
 
  
 
=== Team Members & Responsibilities ===
 
=== Team Members & Responsibilities ===
 
*  Arturo Montoya
 
*  Arturo Montoya
**  Driver Development
+
**  Light Sensors (PWM driver) , Servo motor(ADC driver) , and Matrix (Spi driver)
 
*  Matthew Balhorn
 
*  Matthew Balhorn
 
**  FreeRTOS Software Design
 
**  FreeRTOS Software Design
Line 94: Line 89:
 
</td>
 
</td>
 
<td>
 
<td>
* pending
+
* Completed
* pending
+
* Completed
* pending
+
* Completed
 
</td>
 
</td>
 
</tr>
 
</tr>
Line 111: Line 106:
 
</td>
 
</td>
 
<td>
 
<td>
* pending
+
* Completed
* pending
+
* Completed
* pending
+
* Completed
 
</td>
 
</td>
 
</tr>
 
</tr>
Line 126: Line 121:
 
</td>
 
</td>
 
<td>
 
<td>
* pending
+
* Completed
* pending
+
* Completed
 
</td>
 
</td>
 
</tr>
 
</tr>
Line 134: Line 129:
  
 
== Parts List & Cost ==
 
== Parts List & Cost ==
TODO: Update Parts list with costs and parts numbers
 
  
 
<table class = "wikitable">
 
<table class = "wikitable">
<th>Part</th> <th>Cost</th>
+
<th>Part</th> <th>Quuantity</th><th>Cost</th><th>Link</th>
  
  
 
<tr>
 
<tr>
 
<td>LPC 1758 SJSU Dev Board</td>
 
<td>LPC 1758 SJSU Dev Board</td>
<td align = "right"> 60 </td>
+
<td align = "right"> 1 </td>
 +
<td align = "right"> $60 </td>
 +
<td align = "right">  </td>
  
 
<tr>
 
<tr>
<td>180 Degree Servo (x2)</td>
+
<td>180 Degree Servo </td>
<td align = "right"> </td>
+
<td align = "right"> 2 </td>
 +
<td align = "right"> $25 </td>
 +
<td align = "right">  </td>
  
 
<tr>
 
<tr>
 
<td>Solar Panel</td>
 
<td>Solar Panel</td>
 +
<td align = "right"> 1 </td>
 +
<td align = "right"> $15 </td>
 
<td align = "right">  </td>
 
<td align = "right">  </td>
  
 
<tr>
 
<tr>
 
<td>LED Matrix</td>
 
<td>LED Matrix</td>
 +
<td align = "right"> 1 </td>
 +
<td align = "right"> $25 </td>
 
<td align = "right">  </td>
 
<td align = "right">  </td>
 
<tr>
 
<tr>
 
<tr>
 
<tr>
<td>Resistors (x2)</td>
+
<td>Resistors </td>
 +
<td align = "right"> 4 </td>
 +
<td align = "right"> $.25 </td>
 
<td align = "right">  </td>
 
<td align = "right">  </td>
 
<tr>
 
<tr>
 
<tr>
 
<tr>
<td>Photoresistors (x2)</td>
+
<td>Photoresistors </td>
 +
<td align = "right"> 4 </td>
 +
<td align = "right"> $1.50 </td>
 
<td align = "right">  </td>
 
<td align = "right">  </td>
 +
 
<tr>
 
<tr>
 
<tr>
 
<tr>
<td>Jumper wires</td>
+
<td>Jumper wires(x50)</td>
 +
<td align = "right"> 1 </td>
 +
<td align = "right"> $15 </td>
 
<td align = "right">  </td>
 
<td align = "right">  </td>
 
<tr>
 
<tr>
 
<tr>
 
<tr>
 
<td>Servo belt</td>
 
<td>Servo belt</td>
 +
<td align = "right"> 2 </td>
 +
<td align = "right"> $2 </td>
 
<td align = "right">  </td>
 
<td align = "right">  </td>
 
<tr>
 
<tr>
Line 177: Line 188:
  
 
== Design & Implementation ==
 
== Design & Implementation ==
The design section can go over your hardware and software design.  Organize this section using sub-sections that go over your design and implementation.
 
  
 +
[[File:CmpE146_S13_SPT_ProjectFlowchart.png|center|frame]]
 +
<div style="text-align: center;">'''Figure 1:''' Design Flowchart </div>
 
=== Hardware Design ===
 
=== Hardware Design ===
Discuss your hardware design hereShow detailed schematics, and the interface here.
+
 
 +
=====Structure Design=====
 +
The structure of the Solar Panel Tracker consists of a 'base' servo to rotate the solar cell to a position in a 180 degree arch, and a 'top' servo which tilts the 'arm' which holds the solar cell and a photoresistor circuitA second photoresistor circuit, used for the base direction logic, is located on top of the structure and angled in the same direction of the base rotational range.  The base servo rotates the structure using servo belts and pulleys which move the structure resting on an old computer fan bearing.  This provides for a smooth rotation.
 +
 
 +
=====Light Sensor=====
 +
The Solar Panel Sun Tracker consists of the following hardware:
 +
* Resistors
 +
*Photo resistors
 +
This section is responsible for interpreting the voltage of the photo resistors.  The diagram below shows the circuit needed in order to get a voltage division of the two photo resistors.  This voltage divider consists of two resistors on each side of the voltage divider output (ADC pin). When the top photo resistor has a greater resistance then the bottom resistor the voltage output will drop. When they both have the same resistance will hold in the middle.
 +
 
 +
 +
[[File:CmpE146_S13_SPT_LightSensorConnection.png|center|frame]]
 +
<div style="text-align: center;">'''Figure 2:''' LightSensorConnection </div>
 +
 
 +
 
 +
=====Servo Motor=====
 +
The servo section consists of the following hardware:
 +
* Servo Motors / Servo Belts
 +
* Solar Panel
 +
 +
This section is responsible for positioning the solar panels perpendicular to the light source.  The panel is mounted to a frame that pivots according to the top servo. In order to perform a full scan the top servo motor was mounted on pivoting bases that is controlled by the second motor. The diagram below describes the complete setup in order to properly track the sun from sun rise to sun set.
 +
 
 +
[[File:CmpE146_S13_SPT_SJOneBoardSchematic.png|center|frame]]
 +
<div style="text-align: center;">'''Figure 3:''' SjOne Board Schematic </div>
  
 
=== Hardware Interface ===
 
=== Hardware Interface ===
In this section, you can describe how your hardware communicates, such as which BUSes used.  You can discuss your driver implementation here, such that the '''Software Design''' section is isolated to talk about high level workings rather than inner working of your project.
+
[[File:CmpE146_S13_SPT_SjOneInterface.png|center|frame]]
 +
<div style="text-align: center;">'''Figure 4:''' SjOneInterface </div>
 +
<table class = "wikitable">
 +
<th> SJSU Dev Board Pin</th> <th> Destination Pin</th><th>Description</th>
 +
 
 +
 
 +
<tr>
 +
<td>  PWM1.4(p1.23)  </td>
 +
<td align = "right"> Servo Base Control </td>
 +
<td align = "right"> Set pivot </td>
 +
<tr>
 +
<td>  PWM1.5(p1.24)  </td>
 +
<td align = "right"> Servo Top Control </td>
 +
<td align = "right"> Set pivot  </td>
 +
<tr>
 +
<td>  AD0.4(p1.30)  </td>
 +
<td align = "right"> Light Sensor Base</td>
 +
<td align = "right"> Analog Input </td>
 +
<tr>
 +
<td>  AD0.5(p1.31)  </td>
 +
<td align = "right"> Light Sensor Top </td>
 +
<td align = "right"> Analog Input </td>
 +
</table>
 +
 
 +
==== Pulse Width Modulation ====
 +
PWM, or Pulse Width Modulation, was used to control the two 180 degree positional servosThe servos required a 50 Hz (20 ms) duty cycle, and the duration of the high duty cycle (in milliseconds) would control the position to move to.  Typically, the valid high duty cycles are between 1.0 and 2.0 milliseconds, with 1.0 representing '0 degrees', 1.5 representing '90 degrees' and 2.0 representing '180 degrees.'  However, we found that the valid duty cycle range was larger, ranging from 0.2 ms to 3.3 ms.  Knowing this, we expanded the range of the duty cycle and converted the range into a degree range with the <i>change_direction_with_Degree()</i> function.  The servos were connected to a 5V power supply and were controlled by PWM1-4(P1.23)and PWM1-5(P1.24).
 +
 
 +
[[File:146ServoPWM.png|center|frame]]
 +
<div style="text-align: center;">'''Figure 5:''' PWM duty cycle example </div>
 +
 
 +
==== Analog-to-Digital-Converter ====
 +
ADC, or Analog-to-Digital-Converter, was used to convert the analog photoresistor circuit voltage into a digital value for processing.  The pins ADC-4 and ADC-5 were used in the system, each connected to the output of one of the photoresistor circuits.  The raw value was tough to work with, so a conversion to a more manageable range of values was implemented in higher level code.
  
 
=== Software Design ===
 
=== Software Design ===
Show your software design.  For example, if you are designing an MP3 Player, show the tasks that you are using, and what they are doing at a high level.  Do not show the details of the code.  For example, do not show exact code, but you may show psuedocode and fragments of code.  Keep in mind that you are showing DESIGN of your software, not the inner workings of it.
 
  
===== Servo Task =====
+
Our software design centered on using two tasks to pass data used to track the sun.  One task was a Light Sensor task, which is used to load data into the Queue, destined for the other task, a Servo Motor task.  The Servo Motor task then calls a function to change the servo position.  In order to support the tasks, and bridge the gap between them and the drivers, the LightSensors.cpp and ServoMotor.cpp source files were created.
  
===== Light-sensing Task =====
+
[[File:CmpE146_S13_SPT_FreeRTOS.png|center|frame]]
 +
<div style="text-align: center;">'''Figure 6:''' FreeRTOS </div>
 +
 
 +
 
 +
[[File:CmpE146_S13_SPT_SoftwareFlowchart.png|center|frame]]
 +
<div style="text-align: center;">'''Figure 7:''' Flowchart of the Software Design </div>
  
 
=== Implementation ===
 
=== Implementation ===
This section includes implementation, but again, not the details, just the high level.  For example, you can list the steps it takes to communicate over a sensor, or the steps needed to write a page of memory onto SPI FlashYou can include sub-sections for each of your component implementation.
+
 
 +
[[File:CmpE146_S13_SPT_SjOneIO.png|center|frame]]
 +
<div style="text-align: center;">'''Figure 8:''' Pins used for ADC and PWM </div>
 +
 
 +
[[File:CmpE146_S13_SPT_SJOneBoardPWMblockDiagram.png|center|frame]]
 +
<div style="text-align: center;">'''Figure 9:''' PWM Match Register block diagram </div>
 +
 
 +
==== Light sensor Logic ====
 +
The <i>LightSensors.cpp</i> file contains the functions that the Light-sensing task calls.  These functions are <i>getDirection()</i>, which reads the referenced Analog-to-Digital Converter pin (ADC-4 or ADC-5), and returns a value which is the new change in direction for the respective servo motor (Top or Base).  The <i>getDirection()</i> function reads the ADC pin value and uses it to decide which direction the servo should move towards, and returns either a positive <i>degreeChange</i>, a negative <i>degreeChange</i>, or a 0 for no change.  For this project, we decided to use 5 degrees as the degree change.  The <i>getDirection()</i> function can be seen below:
 +
 
 +
[[File:146getDirectionBaseCodeSnippet.png|center|frame]]
 +
<div style="text-align: center;">'''Figure 10:''' getDirection function </div>
 +
==== Servo motor Logic ====
 +
The <i>ServoMotors.cpp</i> file contains the <i>change_direction_withDegree()</i> function, which updates the PWM Match Register for the given PWM signal and the degree. This function takes the degree value, ensures that it is within range, then converts it into milliseconds so it can be written to the respective Match Register, using the <i>PWMUpdateMR()</i> function defined in the PWM driver file. We used the definitions <i>Max_degree</i>, <i>Servo_Width</i>, <i>Servo_Start</i>, and <i>freq_ms</i>, whose values may need to be changed if a different servo motor is used.  <i>Max_degree</i> is the farthest degree available to the servo motor (180), <i>freq_ms</i> is the duty cycle (20 ms), and the <i>Servo_Width</i> and <i>Servo_Start</i> are derived from the duty cycle thresholds (in ms) mapped to the degree range (0 - 180) of the servo motor.
 +
 
 +
[[File:146changeDirectionCodeSnippet.png‎ |center|frame]]
 +
<div style="text-align: center;">'''Figure 11:''' change_direction_withDegree function </div>
 +
 
 +
==== Light-sensing Task ====
 +
The Light-sensing task was very simple.  To keep it this way, all of the 'heavy lifting' was completed in lower level code in the <i>LightSensors.cpp</i> file.  Therefore, the only function that the Light-sensing task needs to use is the <i>getDirection()</i> function.    However, there is a small amount of code to prevent the degree values from going out of range (0-180 degrees)The task reads the <i>getDirection()</i> values for both the top and base servo motors, which have valid values of negative five (-5), zero (0), or positive five (5). These values are added to the current positional value to obtain updated values to pass to the Servo Motor task through the Queue.
 +
 
 +
==== Servo Task ====
 +
The Servo Task is even simpler.  It takes the top and base positional values from the Queue, then passes the value to the servo motors using the <i>change_direction_withDegree()</i> function, which is defined in the <i>ServoMotors.cpp</i> file.
 +
 
 +
[[File:CmpE146_S13_SPT_ServoTask.png‎ |center|frame]]
 +
<div style="text-align: center;">'''Figure 12:''' Servo Task </div>
  
 
== Testing & Technical Challenges ==
 
== Testing & Technical Challenges ==
Line 199: Line 294:
 
Make a smooth transition to testing section and described what it took to test your project.
 
Make a smooth transition to testing section and described what it took to test your project.
  
Include sub-sections that list out a problem and solution, such as:
+
=== Servo Motor Mounting challenge ===
 +
Initially, the base servo was mounted directly to the base, holding up the other servo, solar cell, etc.  The base was unsteady and had a risk of damaging the servo.  To fix this, the top servo, solar cell, etc. were mounted on an old computer fan bearing.  The base servo motor was moved off to the side, with 2 belts and pulleys used to translate the rotation to the structure on the base.
  
=== Wifi Connection Issues ===
+
=== Servo Motors Testing ===
Many wifi connection issues were encounteredTo solve this problem, a dedicated task was created to re-connect to wifi if the connection was ever lost.
+
We tested the Servo motors by sending an increasing range of active duty cycle time until the full range was found.  Normally, servo motors have an active duty cycle range of 1.0 ms to 2.0 ms.  Our servo motors had an actual range of 0.2 ms to 3.3 ms.  Once we found this range, we had no  problems with the servo motors.
 +
 
 +
=== Photoresistor Circuit Testing ===
 +
We tested the photoresistor circuit by connecting it to an ADC pin and monitoring the digital values.  Varying amounts of light were given to the circuit and appropriate changes in values were observedFor example, when the photoresistor connected to 5V receives more light than the other photoresistor(connected to ground), the voltage to the ADC pin drops.  A corresponding drop in value was observed with the digital value.  The same comparison was true with a spike in voltage and the spike in digital value, when the other photoresistor receives more light.
 +
 
 +
=== Integrated Testing ===
 +
We tested the system after full integration by using a flashlight as a simulated sun.  The Solar Panel Tracker correctly adjusted for every sun movement.
  
 
== Conclusion ==
 
== Conclusion ==
Conclude your project hereYou can recap your testing and problemsYou should address the "so what" part here to indicate what you ultimately learnt from this project.  How has this project increased your knowledge?
+
 
 +
Ultimately, we were not able to make it completely battery powered.  Otherwise, the project turned out wellThe Solar Panel Tracker correctly sensed the light and adjusted accordinglyThe main difficulties were with mounting the servos, keeping the wires protected, and other minor adjustments to the design, which wasted an unfortunate amount of time.  Had we been able to finish the design and made it portable earlier, we would have had time to add other features, such as an LED matrix to display status values.  Despite the structural difficulties, we learned and experienced much from the project, such as FreeRTOS implementation, driver development, how to implement Pulse Width Modulation and Analog-to-Digital Conversion, how to use servo motors and photoresistorsOverall, it was a successful project without extra functions.
  
 
=== Project Video ===
 
=== Project Video ===
Upload a video of your project and post the link here.
+
[http://youtu.be/hmtO0O_00to Demonstration Video]<BR/>
  
 
=== Project Source Code ===
 
=== Project Source Code ===
Send me your zipped source code and I will upload this to SourceForge and link it for you.
+
*  [https://sourceforge.net/projects/sjsus13/files/ Project source code is available at SourceForge]
  
 
== References ==
 
== References ==
 
=== Acknowledgement ===
 
=== Acknowledgement ===
Any acknowledgement that you may wish to provide can be included here.
+
Preet Kang
 +
 
 +
Dr. Haluk Ozemek
  
 
=== References Used ===
 
=== References Used ===

Latest revision as of 21:56, 23 May 2013

Solar Panel Tracker

Abstract

The objective of this project is to create a solar panel that tracks the sun. The project will consist of two stepper motors that control the position of the solar panels by using the photo resistors to detect the sun location.

Objectives & Introduction

Solar Panel Sun tracker uses the inputted voltage from photo resistors in order to adjust the position of the solar panel. The project uses and Analog to digital converter. The servo motors are controlled using a pulse; this controls the position of various angles. The servo uses in this project is a standard servo which can only position between 0 and 180 degrees.

The project required the following objectives to be accomplished:

  • Read the voltage from photo resistors
  • Control servo to move from 0 to 180 degrees
  • Compute the location which has the greatest light intensity
  • Determine algorithm to convert digital value into servo position


Team Members & Responsibilities

  • Arturo Montoya
    • Light Sensors (PWM driver) , Servo motor(ADC driver) , and Matrix (Spi driver)
  • Matthew Balhorn
    • FreeRTOS Software Design

Schedule

WeekPlanned TasksStatus

1

  • Order parts
  • Completed

2

  • Look over datasheet(s)
  • Test Servos
  • Design System Logics
  • Completed
  • Completed
  • Completed

3

  • Test Light-sensing circuit
  • Create System Schematics
  • Code Servo Task
  • Create Structure Design (Autodesk Inventor)
  • Completed
  • Completed
  • Completed
  • Completed

4

  • Code Light-sensing Task
  • Build/Machine Structure
  • Code Glue Logics (Directional Logic)
  • Completed
  • Completed
  • Completed

5

  • Integrate system
  • Test System
  • Project report
  • Completed
  • Completed
  • Completed

6

  • Finalize project
  • Finalize report
  • Completed
  • Completed

Parts List & Cost


Part QuuantityCostLink
LPC 1758 SJSU Dev Board 1 $60
180 Degree Servo 2 $25
Solar Panel 1 $15
LED Matrix 1 $25
Resistors 4 $.25
Photoresistors 4 $1.50
Jumper wires(x50) 1 $15
Servo belt 2 $2

Design & Implementation

CmpE146 S13 SPT ProjectFlowchart.png
Figure 1: Design Flowchart

Hardware Design

Structure Design

The structure of the Solar Panel Tracker consists of a 'base' servo to rotate the solar cell to a position in a 180 degree arch, and a 'top' servo which tilts the 'arm' which holds the solar cell and a photoresistor circuit. A second photoresistor circuit, used for the base direction logic, is located on top of the structure and angled in the same direction of the base rotational range. The base servo rotates the structure using servo belts and pulleys which move the structure resting on an old computer fan bearing. This provides for a smooth rotation.

Light Sensor

The Solar Panel Sun Tracker consists of the following hardware:

  • Resistors
  • Photo resistors

This section is responsible for interpreting the voltage of the photo resistors. The diagram below shows the circuit needed in order to get a voltage division of the two photo resistors. This voltage divider consists of two resistors on each side of the voltage divider output (ADC pin). When the top photo resistor has a greater resistance then the bottom resistor the voltage output will drop. When they both have the same resistance will hold in the middle.


CmpE146 S13 SPT LightSensorConnection.png
Figure 2: LightSensorConnection


Servo Motor

The servo section consists of the following hardware:

  • Servo Motors / Servo Belts
  • Solar Panel

This section is responsible for positioning the solar panels perpendicular to the light source. The panel is mounted to a frame that pivots according to the top servo. In order to perform a full scan the top servo motor was mounted on pivoting bases that is controlled by the second motor. The diagram below describes the complete setup in order to properly track the sun from sun rise to sun set.

CmpE146 S13 SPT SJOneBoardSchematic.png
Figure 3: SjOne Board Schematic

Hardware Interface

CmpE146 S13 SPT SjOneInterface.png
Figure 4: SjOneInterface


SJSU Dev Board Pin Destination PinDescription
PWM1.4(p1.23) Servo Base Control Set pivot
PWM1.5(p1.24) Servo Top Control Set pivot
AD0.4(p1.30) Light Sensor Base Analog Input
AD0.5(p1.31) Light Sensor Top Analog Input

Pulse Width Modulation

PWM, or Pulse Width Modulation, was used to control the two 180 degree positional servos. The servos required a 50 Hz (20 ms) duty cycle, and the duration of the high duty cycle (in milliseconds) would control the position to move to. Typically, the valid high duty cycles are between 1.0 and 2.0 milliseconds, with 1.0 representing '0 degrees', 1.5 representing '90 degrees' and 2.0 representing '180 degrees.' However, we found that the valid duty cycle range was larger, ranging from 0.2 ms to 3.3 ms. Knowing this, we expanded the range of the duty cycle and converted the range into a degree range with the change_direction_with_Degree() function. The servos were connected to a 5V power supply and were controlled by PWM1-4(P1.23)and PWM1-5(P1.24).

146ServoPWM.png
Figure 5: PWM duty cycle example

Analog-to-Digital-Converter

ADC, or Analog-to-Digital-Converter, was used to convert the analog photoresistor circuit voltage into a digital value for processing. The pins ADC-4 and ADC-5 were used in the system, each connected to the output of one of the photoresistor circuits. The raw value was tough to work with, so a conversion to a more manageable range of values was implemented in higher level code.

Software Design

Our software design centered on using two tasks to pass data used to track the sun. One task was a Light Sensor task, which is used to load data into the Queue, destined for the other task, a Servo Motor task. The Servo Motor task then calls a function to change the servo position. In order to support the tasks, and bridge the gap between them and the drivers, the LightSensors.cpp and ServoMotor.cpp source files were created.

CmpE146 S13 SPT FreeRTOS.png
Figure 6: FreeRTOS


CmpE146 S13 SPT SoftwareFlowchart.png
Figure 7: Flowchart of the Software Design

Implementation

CmpE146 S13 SPT SjOneIO.png
Figure 8: Pins used for ADC and PWM
CmpE146 S13 SPT SJOneBoardPWMblockDiagram.png
Figure 9: PWM Match Register block diagram

Light sensor Logic

The LightSensors.cpp file contains the functions that the Light-sensing task calls. These functions are getDirection(), which reads the referenced Analog-to-Digital Converter pin (ADC-4 or ADC-5), and returns a value which is the new change in direction for the respective servo motor (Top or Base). The getDirection() function reads the ADC pin value and uses it to decide which direction the servo should move towards, and returns either a positive degreeChange, a negative degreeChange, or a 0 for no change. For this project, we decided to use 5 degrees as the degree change. The getDirection() function can be seen below:

146getDirectionBaseCodeSnippet.png
Figure 10: getDirection function

Servo motor Logic

The ServoMotors.cpp file contains the change_direction_withDegree() function, which updates the PWM Match Register for the given PWM signal and the degree. This function takes the degree value, ensures that it is within range, then converts it into milliseconds so it can be written to the respective Match Register, using the PWMUpdateMR() function defined in the PWM driver file. We used the definitions Max_degree, Servo_Width, Servo_Start, and freq_ms, whose values may need to be changed if a different servo motor is used. Max_degree is the farthest degree available to the servo motor (180), freq_ms is the duty cycle (20 ms), and the Servo_Width and Servo_Start are derived from the duty cycle thresholds (in ms) mapped to the degree range (0 - 180) of the servo motor.

146changeDirectionCodeSnippet.png
Figure 11: change_direction_withDegree function

Light-sensing Task

The Light-sensing task was very simple. To keep it this way, all of the 'heavy lifting' was completed in lower level code in the LightSensors.cpp file. Therefore, the only function that the Light-sensing task needs to use is the getDirection() function. However, there is a small amount of code to prevent the degree values from going out of range (0-180 degrees). The task reads the getDirection() values for both the top and base servo motors, which have valid values of negative five (-5), zero (0), or positive five (5). These values are added to the current positional value to obtain updated values to pass to the Servo Motor task through the Queue.

Servo Task

The Servo Task is even simpler. It takes the top and base positional values from the Queue, then passes the value to the servo motors using the change_direction_withDegree() function, which is defined in the ServoMotors.cpp file.

CmpE146 S13 SPT ServoTask.png
Figure 12: Servo Task

Testing & Technical Challenges

Describe the challenges of your project. What advise would you give yourself or someone else if your project can be started from scratch again? Make a smooth transition to testing section and described what it took to test your project.

Servo Motor Mounting challenge

Initially, the base servo was mounted directly to the base, holding up the other servo, solar cell, etc. The base was unsteady and had a risk of damaging the servo. To fix this, the top servo, solar cell, etc. were mounted on an old computer fan bearing. The base servo motor was moved off to the side, with 2 belts and pulleys used to translate the rotation to the structure on the base.

Servo Motors Testing

We tested the Servo motors by sending an increasing range of active duty cycle time until the full range was found. Normally, servo motors have an active duty cycle range of 1.0 ms to 2.0 ms. Our servo motors had an actual range of 0.2 ms to 3.3 ms. Once we found this range, we had no problems with the servo motors.

Photoresistor Circuit Testing

We tested the photoresistor circuit by connecting it to an ADC pin and monitoring the digital values. Varying amounts of light were given to the circuit and appropriate changes in values were observed. For example, when the photoresistor connected to 5V receives more light than the other photoresistor(connected to ground), the voltage to the ADC pin drops. A corresponding drop in value was observed with the digital value. The same comparison was true with a spike in voltage and the spike in digital value, when the other photoresistor receives more light.

Integrated Testing

We tested the system after full integration by using a flashlight as a simulated sun. The Solar Panel Tracker correctly adjusted for every sun movement.

Conclusion

Ultimately, we were not able to make it completely battery powered. Otherwise, the project turned out well. The Solar Panel Tracker correctly sensed the light and adjusted accordingly. The main difficulties were with mounting the servos, keeping the wires protected, and other minor adjustments to the design, which wasted an unfortunate amount of time. Had we been able to finish the design and made it portable earlier, we would have had time to add other features, such as an LED matrix to display status values. Despite the structural difficulties, we learned and experienced much from the project, such as FreeRTOS implementation, driver development, how to implement Pulse Width Modulation and Analog-to-Digital Conversion, how to use servo motors and photoresistors. Overall, it was a successful project without extra functions.

Project Video

Demonstration Video

Project Source Code

References

Acknowledgement

Preet Kang

Dr. Haluk Ozemek

References Used

List any references used in project.

Appendix

You can list the references you used.