Sunteți pe pagina 1din 41

Solar Cooker with Sun Tracking

Final Report
METRE 4400 Group: James Alexander Samantha Chan Jeffery Kornder

Dr. Chan Ham 12/3/2012


1

Abstract: The objective of this project is to develop and construct a solar cooker of our own design. The cooker focuses the suns solar radiation, called insolation, onto a cooking pot via a reflective parabolic dish, cooking the food within the pot. Power for motion and monitoring will come from solar panels fixed to the frame, so the solar cooker is entirely self-sustained and able to operate without human interaction. Solar cookers have been around for centuries, and a parabolic dish is the most powerful form. By tracking the sun to keep constant focus we will use the optimum setup, and develop solar tracking components that have uses in a wide variety of other applications. In doing so we have gained greater insight into the engineering design process and project management from start to finish.

Table of Contents, List of Figures, and List of Tables: Page 4 1. Introduction (Sam) 4 1.1 Project Overview: related technologies & applications (Sam, James) 5 1.2 Major Objectives & Developments (main focus of the project) (James) 5 1.3 Team chart & major responsibility (Sam) 5 2. System Requirements & Specifications (Jeff) 5 2.1 Technical Requirements & Specifications (Jeff, Sam) 9 2.2 Functional Features (Jeff) 9 2.3 Minimum Success Criteria James) 10 2.4 Design Verification Plan (Sam) 10 3. System Overview (Sam) 11 3.1 Configuration: block diagram & description (Jeff, James) 13 3.2 Major Subsystem & Components (James) 13 3.3 Trade Study for Major Parts (Sam, James) 15 4. Prototype Development (James, Jeff) 16 4.1 Introduction of Major Works (James) 17 4.2 Hardware: drawings & circuit diagrams (major or system level) (Jeff) 19 4.3 Software (Sam) 20 4.4 Budget & Project Schedule: bill of materials and Gantt chart (Jeff) 27 4.5 Analysis and Test Results: including discussion about results (James) 27 5 Conclusions 27 5.1 Achievements and Lessons Learned (James) 27 5.2 Future Improvements and Design Optimization (Jeff, Sam) 29 References (Sam) 29 Appendix (Jeff) 6 11 12 13 15 16 17 17 18 18 19 Fig 1: Front view of parabolic dish Fig 2: Final Cooker Design Fig 3: Block Diagram of overall System Fig 4: Comparison of Paint to Mylar strips Fig 5: construction of initial prototype dish Fig 6: Construction of final prototype dish Fig 7:Gimbal and spine Fig 8:The A-frame Fig 9: Linear Actuator Fig 10:Prototype frame in steel Fig 11:Wiring and circuit diagram of overall system

5 10 14 14 20 27 3

Table 1: Team Chart and Task Responsibility Table 2: Design Verification Chart Table 3: Pughs Method Trade Study for reflective material Table 4: Pughs Method Trade Study for light sensors Table 5: Bill of Materials Table 6: Test Results from Prototype dish

1. Introduction 1.1 Project Overview: introduction, related technologies & applications We have elected to design and build a relatively advanced parabolic solar cooker. There are many types of solar cookers, but the vast majority of them in current use are fairly cheap, low-technology devices, such as: Box Cooker: A box cooker consist of a transparent glass or plastic top, which may have additional reflectors to concentrate sunlight into the box. The top is usually removable to allow dark pots containing food to be placed inside. One or more reflectors of shiny metal or foil-lined material may be positioned to bounce extra light into the interior of the oven chamber. Cooking containers and the inside bottom of the cooker should be dark-colored or black, while the inside walls should be reflective to reduce radiate heat loss and bounce the light towards the pots and the dark bottom, which is in contact with the pots. The box should have insulated sides. Panel Cooker: Panel solar cookers use reflective panels to direct sunlight to a cooking pot that is enclosed in a clear plastic bag. It can be produced by pasting a reflective material, such as aluminum foil, onto a cut and folded backing, usually corrugated cardboard. It is lightweight and folds for storage. Solar Kettles: The solar kettle-thermos flask is a solar thermal design that uses an evacuated solar glass tube (solar vacuum glass tube) constructed from borosilicate glass to capture and store energy from the sun. The tube consists of an inner glass layer characterized by a dark exterior that heats up in sunlight, whereas the outer glass layer is transparent allowing sunshine to penetrate. This sunshine transports the solar infra-red energy and penetrates through this outer layer and subsequently through the vacuum layer onto the inner layer where it is absorbed. The air is evacuated between these two layers with a consequent insulating vacuum. The difference between a classic solar cooker and a solar kettle is the latter runs off the principle of accumulated rather than concentrated solar thermal energy. In essence these kettles only need diffused sunlight to work and needs no sun tracking at all.

Hybrid Cooker: A hybrid solar oven is a solar box cooker equipped with a conventional electrical heating element for cloudy days or nighttime cooking. It consists of an adjustable parabolic reflector suspended in a tripod with a movable grill surface. When solar energy is not available, the design uses any conventional fuel as a heat source, including gas, electricity, or wood. However, a hybrid cooker ends up being very expensive compared to other types of solar cookers. Although various ideas for high-tech solar cookers have been proposed, such as the electric oven powered by solar cells, very few of them have progressed past the experimental stage to the point where they are used in practice, because they are generally much more expensive than low-tech cookers. 4

1.2 Major Objectives & Developments (main focus of the project) The main focus of this project is to design and construct a system to focus the sun s energy with no other stimuli or inputs on a pot to the point that it is hot enough to cook food (boil water). In order to achieve this we must: Design and construct frame using CAD Design and create gimbal to hold pot Derive optimal equation for parabola Determine best material and reflective coating for production Devise a Solar tracking using light sensors Use only solar energy converted by solar panel and stored by battery to achieve this

1.3 Team chart & major responsibility

Table 1: Team Chart and Task Responsibility 2. System Requirements & Specifications 2.1 Technical Requirements & Specifications In order to create the reflective dish we had to generate an equation of the parabola that would reflect rays into its center. The focal point of this parabola must also be nearly level with its height.

This equation yields the following parabolic dish:

Fig 1: Front view of parabolic dish With the focal point just above the level to the edge of the dish we can have the cooking apparatus sit just inside the dish to absorb the maximum energy along the underside of the pot rather than a small single point. Additionally, we had to analyze the potential size of the dish. If the dish is too small, it will not reflect enough energy into the pot to create sufficient heat.

Our calculation yielded a much smaller dish is needed if we can ensure a high efficiency. We elected to use a 50% efficiency to adjust for several factors that may affect the efficiency of the system. cooker may be used on partly cloudy days cooker may become dirty the pot cannot retain all energy put into it some light will inevitably be absorbed by the reflective material some light will, despite our best efforts, scatter

In a test we successfully boiled 1 Liter of water and using the data gathered, found the energy output of our prototype dish using the size and shape we calculated.

Subtracting the area blocked by the pot and supports we had a area of effectiveness of 0.747sqm. This correlates to 404.1 available watts based on the earlier calculations.

Finally, we had to calculate the torque needed for the motor to turn a dish of this size and track the sun. The following equations show the maximum predicted torque:

In addition to the calculated torque, we know that the bearings holding the pot will add some additional friction force that will increase the maximum torque. To offset this, we planned to place the solar panel and as much of the control system as possible on the opposite side of the central axis of the bearings. This would subtract from the moment of the dish as it turns and decrease the torque from weight. Ultimately however, this proved unnecessary. Our final motor is a CHM-2401-1M with an output of 50 In-lb. This is equivalent to 5.65N-m. Based on the torque calculations we will be using a 3:1 gear ratio on our motor pulley in order to achieve the maximum torque plus a 50% factor of safety.

2.2 Functional Features The functional features of the dish are related to the solar tracking systems. Using three chip style light sensors to track the suns movement in the sky and trigger the motor to rotate the dish when needed 2.3 Minimum Success Criteria The final system should be comparable in size and maneuverability to a typical backyard grill. 60 x 50 Disassembled, it must be packable to allow for shipping ( sum of dimensions less than 165) Able to cook unwatched until completion Able to withstand typical outdoor conditions ( 40-100 Degree Fahrenheit, sun, rain, wind, etc) Support up to 10 lb in gimbal (pot + food) Disassembled, able to fit in box whose sum of dimensions is no greater than 165 (this is the maximum allowed size for shipping)

2.4 Design Verification Plan Each part of the design was verified independently by analysis, testing, and simulation. The following table shows how we verified.

Items Motor Aluminum Foil Chrome Spray Paint White Fiber Glass Adhesive Mylar Frame Strength Program Code

Analysis x x

Simulation x

Test x x x x

x x x x Table 2: Design Verification Chart

x x

Test: All reflective practical materials will be tested on a prototype dish. The motor and Arduino code were tested independently at first to ease potential troubleshooting. Simulation: The motor and code will both be simulated in MATlab. Final frame design will be put through Finite Element Analysis (FEA). Analysis: All components will be analyzed individually to ensure proper function and that all desired criteria is met.

3. System Overview Design and construct a reflective parabolic dish capable of cooking a meal and tracking the sun across the sky without any external stimuli.

10

3.1 Configuration: block diagram & description

Fig 2: Final Cooker Design The parabolic dish shape is effective only when pointing directly at the sun, which has a well known tendency to move across the sky at a constant rate. For this reason the design is solar tracking, meaning it will follow the suns trajectory across the sky. Tracking the sun will allow the cooker to cook as hot as possible for as long as possible. 11

In order to move of its own volition, the cooker must have a source of power. Since it will already be tracking the sun the addition of a solar panel also tracking the sun to generate DC power is obvious. If the system is well balanced the power demand will be minimal and not constant, only needed to move the dish, not hold its place. The sun will be tracked east to west by two light sensors placed next to each other, one east and one west, bisected with a single blade raised toward the sun. As the sun moves across the sky the blades shadow will fall on one of the sensors. This difference between the sensors shall be compared by the Arduino which will control the motor to rotate the dish until the two sensors are receiving equal sunlight. There is a third sensor and another blade to adjust North/South tilt, but this will only be checked once at the start of cooking since the suns path will not change longitudinally. With this method the blades height can be altered to adjust the systems sensitivity. The taller the blade the more the suns movement will be Block Diagram exaggerated and the quicker the shadow will move to cover/uncover a sensor.

Temperature Sensors

Light Sensors

Arduino

Motors

Solar Collector

Battery

Solar Panel

Fig 3: Block Diagram of overall System

12

3.2 Major Subsystem & Components Structure: The primary feature of the structure component will be a frame designed by us in CAD to hold and support all other components in their proper place. The gimbal to hold the pot level inside the rotating dish is a smaller substructure that will be a part of the final frame. Dish: The key aspect of the dish construction was to find the optimal equation for a parabola, and from that curve determine the best material and reflective coating for a production model. Control System: The chief goal of the control system is powered solar tracking using light sensors and a motor with linear actuator for North/South tilt Power System: The power for the controls will be stored in a 12V battery charged from a solar panel also tracking the sun.

3.3 Trade Study for Major Parts Dish material: Several materials were considered for the dish materiel. Polished stainless steel and aluminum are much too expensive and shaping them into the parabola is beyond any of our abilities. Mirrors would be impossible to shape into a perfect parabola and would just seem like an inside out disco ball. Fiberglass was chosen due to its price and relative ease of shaping. The reflective materials will need be coated on separately.

Fig.4 Comparison of paint to Mylar strips on final dish

13

Reflective material: Weighted Pughs method White Aluminu Coat m Importan ce Weight (%) reflectivity 30 cost uniformity Total 25 45 Criteria Rating Weighted Rating Rating

Chrome Spray Paint Weighted Rating Weighted Rating Rating

Mylar

Rating

Weighted Rating

0 3 1 NA

0 1.3 0.45 1.75

3 3 1 NA

0.9 0.75 0.45 2.1

3 3 4 NA

0.9 0.75 1.8 3.45

4 3 4 NA

1.2 0.75 1.8 3.75

Table 3: Pughs Method Trade Study for reflective material Drive type: To transfer the motors motion into dish rotation chord, v-belt, and timer pulleys as well as gears were considered. Ultimately v-belt was selected due to being cheapest and since some slipping is permissible with no encoders being used.

Sensor Type SMD Importance Weight (%) low power 25 dissipation high 35 operating temperatur e high 30 photocurre nt low cost 10 100 Criteria Rating 1 3 Weighted Rating 0.3 1 ThroughHole Rating 1 3 Weighted Rating 0.3 1 Chip Rating 4 3 Weighted Rating 1.5 1.2

1.2

1.2

0.3

2 NA

0.8 3.3

4 NA

1.3 3.8

2 NA

0.8 3.8

Table 4: Pughs Method for Light Sensors 14

4. Prototype Development Construction of the prototype dish began in early June 2012. The mold for the dish was cut out of Styrofoam insulation using a super-heated piece if NiChrome wire. After applying and curing the fiberglass the original dish was used to test both for adequate size and various reflective surfaces. Construction of the final prototype began October 20th and was completed November 10th.

Fig 5: Constructing the initial prototype dish

15

Fig 6: Constructing final prototype dish

4.1 Introduction of Major Works Structure The frame is fully designed and laid out in SolidWorks CAD We have constructed a gimbal to keep the pot of food level to the ground Dish The parabola equation for the dish has been calculated for optimal focal point Different materials have been tested for reflectivity and efficiency Control System Light sensors will be used to keep the dish tracking on the sun Thermostat will be used to keep food from overheating Power System The entire apparatus will be designed to run on solar energy

16

4.2 Hardware: drawings & circuit diagrams (major or system level)

Fig.7 Gimbal and spine

Fig.8 The A-frame 17

Fig. 9 Linear Actuator

Fig.10 Prototype frame in steel

18

Fig 11: Wiring and circuit Diagram of overall System 4.3 Software SolidWorks MatLab Arduino Environmen 19

4.4 Budget & Project Schedule: bill of materials and Gantt chart
Item Bearings DC motor Linear Actuator 1 Square 6061 Al .75 Square 6061 Al .5 6061 Al rod 3/16 Pin V-belt 1 dia Pulley 3 dia Pulley Arduino Uno H-bridge Various color and size wires and connectors Solar Panel Photo sensitive Chip Resistors (various sizes) 1/16 steel sheet metal 12V Battery Fiberglass Resin Fiberglass Mat Fiberglass Weave 5x Bolts Quantity 4 1 1 84 70 46 4 16 1 1 1 1 Apx 5' 1 3 Apx 4 1x28.27 1 3 Gallon 24 sq. ft. 12 sq. ft. 2 Total Price Cost ($) 20 40 10 27.25 15.5 15 4 5 2 2 30 45 5 40 7.5 2 2.5 22 60 10 20 .25 385

Table 5: Bill of Materials All items are provided by sponsor, Jebadiah Moulten of Atlanta Robotics. Some components are made by his company and therefore would not be full cost, and many parts can be used for multiple iterations. 20

Gant Chart

21

22

23

24

25

26

4.5 Analysis and Test Results: including discussion about results To Tf Water Tambient Time Material With Aluminum Foil Water (C) (C) pot Cover (C) 29 30 30 18 min White Paint no 45 76 30 1 hour Aluminum Foil no 34.6 50.2 32 20 min Aluminum Foil no 28 70 28 37 min Chrome Spray Paint no 32 86 28 45 min Chrome Spray Paint yes 30 101 22 1 hour Mylar Adhesive yes 39.8 98.5 25 26 min Mylar Adhesive yes Table 6: Test Results from Prototype dish Many of the tests were unable to go for a full hour without cloud cover. However covering the pot combined with the better reflective materials was an effective enough combination that the full hour was not even necessary to achieve minimum success. Whether this will still be the case in the dead of winter remains to be tested. The efficiency is so low for a myriad of reasons many of which can be overcome in final prototype. Factors such as the bubbles and creases in the Mylar and the imperfect nature of our dish will not be factors in the final model. Factors like the pots inability to perfectly retain heat or the shiny glaze of the pot cannot be completely eliminated, but their impact one efficiency can and will be reduced.

5 Conclusions 5.1 Achievements Lessons learned The importance of assembly consideration in design became obvious early on in the project. Any great design must also be buildable after all or it is just an idea. Also important is adherence to the schedule, and likewise setting an achievable schedule is crucial to a successful project. Crucial as well we learned is clearly assigned tasks that play to each respective member s strengths, and communication to discern those roles. We learned how to document our project in an organized, technical and professional manner, for others to be able to know and understand the engineering processes used to achieve our goals. Most importantly, every aspect of the design can, and should be, supported by a calculation of some sort. If a tested result does not match calculations we should re-assess the formula and variables used to understand 5.2 Optimizations The dish is more than capable in its current size of cooking even during the worst months of the year, so it would be practically overkill during ideal summer conditions. For this reason a smaller dish may be preferable. Just a six inch smaller diameter would make the entire system smaller, lighter, stiffer due to the lightness and shortened spine, more movable and packable, and save on time and cost of materials while still meeting minimum cooking times.

27

The motor shaft could be shorter. This was a limit of available materials and will be rectified in any production version. The adjustable leg, all things considered, should probably not be a powered feature. It can easily be manually adjusted and since it only affects the latitude angle after initial setup need not be altered again. Possibly not for days. This would simplify the system and decrease weight as well as manufacturing costs. Addition of temperature sensors: to better control the solar cooker we could add temperature sensors (such as thermostats) on the pot and have a temperature gauge connected to the micro-controller so the user can input the temperature they desire, and based on it, have the system adjust accordingly. An array of pot holder sizes, or even a universal pot holder would also be useful, and allow for a range of different sized pots and dishes to be utilized. Similarly the square portion of the gimbal should be lengthened along the spine. This would allow for more clearance of taller pots and a wider range of motion for all dishes without sacrificing much additional sunlight.

28

References
Motor Dynamics. Linear Actuator 200mm Stroke 40 mm Speed 150N. http://www.motiondynamics.com.au/linear-actuators/series-3/linear-actuator-200mm-stroke40mm-speed-150n.html Atlanta Robotics. Dual Hbridge Motor Drive. http://atlantarobotics.com/Dual_Hbridge_Motor_Drive.php Global Spec. CHM CHM-2401-1M. http://beta.globalspec.com/ds/2353/molon/51F2B8797A15-42DC-A487-EAC9C637F7AC One Block Off the Grid. Different Types of Solar Panels. http://howsolarworks.1bog.org/different-types-of-solar-panels/ Panasonic. Light Sensors. http://pewa.panasonic.com/components/built-in-sensors/lightsensors/napica/ Battery http://www.batteriesplus.com/product/40571-WKA12--2-dot9F-Battery/1000851/102629-SLA-Sealed-Lead-Acid-Batteries/102645-Werker/12V.aspx

29

Appendix:
All drawings, circuit diagrams, program codes, major spec sheet Motor Spec Sheet

Automotive Dual H Bridge DC Motor Driver Part number 120052


This dual motor driver is based off of the ST Microelectronics VNH2SP30-E integrated Hbridge motor driver chip. The VNH2SP30TR-E chip from ST Microelectronics is designed for the automotive industry and greatly used in 12 volt window motor control. 30 Amps max at 16 Volts. This board give you access to all the capabilities the chip offers. Click here for datasheet. The quick overview: 5V logic level compatible inputs Undervoltage and overvoltage shut-down (5.5V-16V) Overvoltage clamp Thermal shut down Cross-conduction protection Linear current limiter Very low stand-by power consumption PWM operation up to 20 kHz Protection against loss of ground and loss of VCC Current sense output proportional to motor current Reverse polarity hookup protection 30

Optional chip heatsink Brake to ground or brake to VCC Motor power supply is all that is required (<16 VDC). Board includes a 5 volt regulator and can provide up to 1A of 5 VDC power for attaching TTL peripherals.

Description (from STMicroelectronic's datasheet) The VNH2SP30-E is a full bridge motor driver intended for a wide range of applications. The device incorporates a dual monolithic high side driver and two low side switches. The high side driver switch is designed using STMicroelectronics well known and proven proprietary VIPower M0 technology which permits efficient integration on the same die of a true Power MOSFET with an intelligent signal/protection circuitry. The low side switches are vertical MOSFETs manufactured using STMicroelectronics proprietary EHD (STripFET) process. This package, specifically designed for the harsh automotive environment offers improved thermal performance thanks to exposed die pads. The input signals INA and INB can directly interface to the microcontroller to select the motor direction and the brake condition. The DIAGA/ENA or DIAGB/ENB, when connected to an external pull-up resistor, enable one leg of the bridge. They also provide a feedback digital diagnostic signal. The motor current can be monitored with the CS pin by delivering a current proportional to its value. The speed of the motor can be controlled in all possible conditions by the PWM up to 20 kHz. In all cases, a low level state on the PWM pin will turn off both the LSA and LSB switches. When PWM rises to a high level, LSA or LSB turn on again depending on the input pin state. Compare to SparkFun's "Monster Moto Shield" and Polulus Dual VNH5019 motor driver The PCB measures 3.3W by 2.5L . The onboard 7805 chip allows for 5V power utilization for peripheral support. The 5 volt regulator can be disabled by removing the jumper from JP1. This driver board gives you access to all the features that the chip has to offer. The green power LED indicates that there is 5V power and motor power available. The red and blue LEDs indicate that motor voltage is being pulsed out of the motor pins (motor should be moving when red or blue LEDs are lit). The Automotive Dual H Bridge DC Motor Driver consists of the following key components: Automotive fully integrated H-bridge motor driver (PN# VNH2SP30TR-E, ST Microelectronics) http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATUR E/DATASHEET/CD00043711.pdf MOSFT 30V 56A (PN# IRFR3707ZTRLPBF, International Rectifier) http://www.irf.com/product-info/datasheets/data/irfr3707.pdf Zener Diode (PN# BZT52H-C18,115 NXP Semiconductor) http://www.nxp.com/documents/data_sheet/BZT52H_SER.pdf DC/DC Switching Controllers 5V, 1A (PN# SP7805V2-L/TR) Exar http://www.exar.com/ Schematics and EagleCAD files are available for download at www.Atlanta-Robotics.com. Sample code for programming forward and reverse at different speeds on an Arduino microcontroller can also be downloaded at www.Atlanta-Robotics.com.

WKA12-2.9F Battery 12V Werker SLA Sealed Lead Acid Battery

Item number: WKA12-2.9F

31

Weight: 4.1300 lbs Voltage: 12V Capacity: 2.9AH

Linear Actuator 40mm/sec 200mm Stroke 150


Specifications: Speed: 40mm/Second Stroke: 200mm Input: 12V Max Current: 1.6A Load capacity: 150N at rated load (Push/Pull) Limit Switches: Internal (Not adjustable) Protection Class: IP65 Duty Cycle: 10% (2 minutes on/18 Minutes off) Gearing: Steel Cable Length: 70CM Weight: 1KG High quality unit. Very smooth operation. Alloy frame, steel shaft. One of the strongest and most durable on the Australian Market. Uses Include: Furniture, Appliances, Automotive, Satellite, Solar etc Download the PDF information page here!

32

33

Self-Lubricating Stamped Steel Base-Mounted Bronze Bearings Made of oil-impregnated bronze, these light-duty, low-cost bearings save you time by eliminating the need for routine maintenance. Use them for medium-speed, lowload applications. All include an oil cup (unless noted) for additional lubrication. Housing is stamped steel; bearing insert is SAE 841 bronze (Oilite), which is an alloy ofcopper, tin, and carbon. Bearing Material SAE 841 Temperature Range -40 to +240 F

P max V max PV max 2,000 1,200 50,000

A=9/16' B=2 5/16'' C=1 1/8' D=7/16" E=1 3/4" F= 17/64' 5/16" 34

Program Code /* "Dual Hbridge Motor Driver" www.Atlanta-Robotics.com date: 8/19/11 code by: Jebadiah Moulton based on Kirk Charles and Ben Axelrod's Centroid line following method Feel free to use this code however you'd like. Please improve upon it! Let me know how you've made it better. Some motor control snippets of code were based of the Sparkfun's Monster Moto Shield code Use the motorGo(uint8_t motor, uint8_t direct, uint8_t pwm) function to get motors going in either CW, CCW, BRAKEVCC, or BRAKEGND. Use motorOff(int motor) to turn a specific motor off. The motor variable in each function should be either a 0 or a 1. pwm in the motorGo function should be a value between 0 and 255. Depending on the speed and torque of your motors the code may need to be changed a little. If you uncomment the debug println statements, be sure to comment them out again as it will drastically slow down your code and this will be a problem for fast robots. This code was written for the "Dual Hbridge Motor Driver" and "OctoIR Line Follower" sensor board at www.Atlanta-Robotics.com */ #define TIMER_CLOCK_FREQ 2000000.0 // Definitions for motorGo function #define BRAKEVCC 0 #define FWD 1 #define REV 2 #define BRAKEGND 3 #define CS_THRESHOLD 100 /* VNH2SP30 pin definitions xxx[0] controls '1' outputs xxx[1] controls '2' outputs */ int INApin[2] = {3, 8}; int INBpin[2] = {4, 9}; int DiagA[2] = {5, 10}; int DiagB[2] = {6, 11}; int PWMpin[2] = {7, 12}; // 2MHz for /8 prescale from 16MHz

// INA: Clockwise input // INB: Counter-clockwise input // Write high to enable. Can be read in for diagnostics // Write high to enable. Can be read in for diagnostics // PWM input to motor driver

int ONBD_LED = 13; 35

// onboard LED is on pin 13

// Motor control variables uint8_t Leg_Motor_Speed = 0; the centroid line following calculation uint8_t Dish_Motor_Speed = 0; the centroid line following calculation int LEG = 1; int DISH = 0; void setup() { Serial.begin(9600);

// Value between 0-255 used for port motor speed during // Value between 0-255 used for stbd motor speed during

// define motor 0 as LEG (left) motor // define motor 1 as DISH (right)motor

// initialize the digital pins as in or out. pinMode(ONBD_LED, OUTPUT); // Pin 13 is the onboard LED // Atmega pins configured as OUTPUT can source (provide positive) or sink (provide negative current) up to 40 mA for (int i=0; i<2; i++) // loop to initialize both motor control pin sets for the VNH2SP30 motor drive chip { pinMode(INApin[i], OUTPUT); // INA: Clockwise input for VNH2SP30 pinMode(INBpin[i], OUTPUT); // INB: Counter-clockwise input for VNH2SP30 pinMode(PWMpin[i], OUTPUT); // Write high to enable. Can be read in for diagnostics pinMode(DiagA[i], OUTPUT); // Write high to enable. Can be read in for diagnostics pinMode(DiagB[i], OUTPUT); // PWM input to VNH2SP30 motor driver }

/*pinMode(cSENSEpin0, INPUT); pinMode(cSENSEpin1, INPUT); */

// Current sense of motor 1 // Current sense of motor 2

// Initialize braked for (int i=0; i<2; i++) // Brake both motors on start up { digitalWrite(INApin[i], LOW); // pulling both INA and INB pins low will brake to ground digitalWrite(INBpin[i], LOW); digitalWrite(DiagA[i], HIGH); // Writing the DiagA and DiagB pins high will enable the chip digitalWrite(DiagB[i], HIGH); } } //********************************************************************************* *********************************************************************************** *** //********************************************************************************* 36

*********************************************************************************** *** //-------------------------------------------------- Start Main code loop ---------------------------------------------------------------------------------------------//********************************************************************************* *********************************************************************************** *** //********************************************************************************* *********************************************************************************** *** void loop() { int Light1 = analogRead(A0); int Light2 = analogRead(A1); int Light3 = analogRead(A2); int Limit = analogRead(A3); float voltage1= Light1 * (5.0 / 1023.0); float voltage2= Light2 * (5.0 / 1023.0); float voltage3= Light3 * (5.0 / 1023.0); float limitVoltage = Limit * (5.0/1023);

while((((voltage3 - voltage2) > 1) || ((voltage2 - voltage3) > 1)) && (limitVoltage < 3)) // Set Jack Leg to sun angle using light sensors { if((voltage2 - voltage3) >1) { motorGo(LEG, FWD, 125); } else if((voltage3 - voltage2) > 1) { motorGo(LEG, REV, 125); } } while(1) { int Light1 = analogRead(A0); int Light2 = analogRead(A1); int Light3 = analogRead(A2); int Temp = analogRead(A3); float voltage1= Light1 * (5.0 / 1023.0); float voltage2= Light2 * (5.0 / 1023.0); 37 // Loop main sun tracking program

float voltage3= Light3 * (5.0 / 1023.0); float Tempv= Temp * (5.0 / 1023.0); Serial.println("L1"); Serial.println(voltage1); Serial.println("L2"); Serial.println(voltage2); Serial.println("L3"); Serial.println(voltage3); delay(5000); // Run Loop every 5 seconds

while((voltage1 - voltage2) > 1) { Serial.println("L1"); Serial.println(voltage1); Serial.println("L2"); Serial.println(voltage2); Light1 = analogRead(A0); Light2 = analogRead(A1); voltage1= Light1 * (5.0 / 1023.0); voltage2= Light2 * (5.0 / 1023.0);

motorGo(DISH, FWD, 255); }

// motor fwd. 0-255 is the range

while((voltage2 - voltage1) > 1) { Serial.println("L1"); Serial.println(voltage1); Serial.println("L2"); Serial.println(voltage2); Light1 = analogRead(A0); Light2 = analogRead(A1); voltage1= Light1 * (5.0 / 1023.0); voltage2= Light2 * (5.0 / 1023.0);

motorGo(DISH, REV, 255); } motorOff(DISH); } //Debugging Code /* while(1) 38

{ int Light1 = analogRead(A0); int Light2 = analogRead(A1); float voltage1= Light1 * (5.0 / 1023.0); float voltage2= Light2 * (5.0 / 1023.0); Serial.println(voltage1); if((voltage1 - voltage2) > 1) { motorGo(LEG, FWD, 255); motorGo(DISH, FWD, 255); delay(1000); } else { motorGo(LEG, REV, 255); motorGo(DISH, REV, 255); delay(1000); } motorGo(LEG, FWD, 255); motorGo(DISH, FWD, 255); delay(1000); motorGo(LEG, REV, 255); motorGo(DISH, REV, 255); delay(1000); */ //End Debugging Code } //********************************************************************************* *********************************************************************************** *** //********************************************************************************* *********************************************************************************** *** //-------------------------------------------------- end of main loop ---- functions here ----------------------------------------------------------------------------//********************************************************************************* *********************************************************************************** *** //********************************************************************************* *********************************************************************************** 39 // Right motor full speed FWD // motor fwd at 50 pwm. 0-255 is the range // motor fwd at 50 pwm. 0-255 is the range

*** void motorOff(int motor) { // Initialize braking of motor for (int i=0; i<2; i++) { digitalWrite(INApin[i], LOW); to ground digitalWrite(INBpin[i], LOW); } analogWrite(PWMpin[motor], 0); } //Brake Function

// pulling both INA and INB pins low will brake

/* motorGo() will set a motor going in a specific direction the motor will continue going in that direction, at that speed until told to do otherwise. motor: this should be either 0 or 1, will selet which of the two motors to be controlled direct: Should be between 0 and 3, with the following result 0: Brake to VCC 1: Clockwise 2: CounterClockwise 3: Brake to GND pwm: should be a value between ? and 255, higher the number, the faster it'll go */ void motorGo(uint8_t motor, uint8_t direct, uint8_t pwm) // motor control function for both left and right motors { if (motor <= 1) // Make sure it is motor 0=STBD or 1=PORT { if (direct <=4) // Make sure a valid direction BRAKEVCC=0, FWD=1,REV=2, BRAKEGND=3 { if (direct <=1) { /*if (motor = 1) Serial.print("stbd "); else Serial.print("port "); */ digitalWrite(INBpin[motor], HIGH); //Serial.print("fwd HIGH "); 40 // If FWD or BRAKEVCC Set inBpin[motor]

} else // Else REV or BRAKEGND, Reset inBpin[motor] { digitalWrite(INBpin[motor], LOW); //Serial.print("fwd LOW "); } if (direct >= 2) { /*if (motor = 1) Serial.print("stbd "); else Serial.print("port ");*/ digitalWrite(INApin[motor], HIGH); //Serial.print("rev HIGH "); } // If REV or BRAKEGND Set inApin[motor]

else // Else FWD or BRAKEVCC, Reset inApin[motor] { digitalWrite(INApin[motor], LOW); //Serial.print("rev LOW "); } analogWrite(PWMpin[motor], pwm); //Serial.println(pwm, DEC); } } }

41

S-ar putea să vă placă și