Light Tracking with Servos (Propeller C)
Nomadic0
Posts: 21
in Propeller 1
Hello all,
Trying to create a dual axis solar tracker with the Propeller Kit! Needed some pointers or references for the servo control commands. So far, I have seen 1 and it doesn't seem to increase intensity, only angle.
I've noticed that if I comment out the pauses under the servo commands, the program keeps looping (like it's supposed to) and the logic (variable "math") checks out.
Thank you
So far, I have this (the program stops after about 5 loops messing with shadows):
#include "simpletools.h" // Include simple tools
#include "servo.h"
int main() // main function
{
while(1) // Endless loop
{
int rf,lf,rb,lb,tilt,spin,frontsum,backsum,leftsum,rightsum=0;
high(4); // Set P4 high
pause(1); // Wait for circuit to charge
rf = rc_time(4, 1); // Measure decay time on P4
print("rf = %d\n", rf); // Display decay time
//pause(100);
high(5); // Set P5 high
pause(1); // Wait for circuit to charge
lf = rc_time(5, 1); // Measure decay time on P5
print("lf = %d\n", lf); // Display decay time
//pause(100);
high(8); // Set P8 high
pause(1); // Wait for circuit to charge
rb = rc_time(8, 1); // Measure decay time on P8
print("rb = %d\n", rb); // Display decay time
//pause(100);
high(9); // Set P9 high
pause(1); // Wait for circuit to charge
lb = rc_time(9, 1); // Measure decay time on P9
print("lb = %d\n", lb); // Display decay time
//pause(100);
frontsum=lf+rf;
printf("FRONTSUM %d\n", frontsum);
backsum=rb+lb;
printf("BACKSUM %d\n", backsum);
leftsum=lf+lb;
printf("LEFTSUM %d\n", leftsum);
rightsum=rf+rb;
printf("RIGHTSUM %d\n", rightsum);
spin=leftsum-rightsum;
printf("SPIN %d\n", spin);
tilt=frontsum-backsum;
printf("TILT %d\n", tilt);
//I then compare each labeled section to determine where the servose should move the panels (X and Y axis)
if(tilt<-30000)
{
servo_angle(25, 900); // P26 servo to 90 degrees
pause(20);
servo_stop();
printf("Clockwise tilt\n");
}
else if (tilt>30000)
{
servo_angle(25, 1800); // P26 servo to 180 degrees
pause(20);
servo_stop();
printf("CounterClockwise tilt\n");
}
if(spin<-30000)
{
servo_angle(26, 900); // P26 servo to 90 degrees
pause(20);
servo_stop();
printf("Clockwise\n");
} else if (spin>30000)
{
servo_angle(26, 1800); // P26 servo to 180 degrees
pause(20);
servo_stop();
printf("CounterClockwise\n");
}
pause(5000);
}
}
Trying to create a dual axis solar tracker with the Propeller Kit! Needed some pointers or references for the servo control commands. So far, I have seen 1 and it doesn't seem to increase intensity, only angle.
I've noticed that if I comment out the pauses under the servo commands, the program keeps looping (like it's supposed to) and the logic (variable "math") checks out.
Thank you
So far, I have this (the program stops after about 5 loops messing with shadows):
#include "simpletools.h" // Include simple tools
#include "servo.h"
int main() // main function
{
while(1) // Endless loop
{
int rf,lf,rb,lb,tilt,spin,frontsum,backsum,leftsum,rightsum=0;
high(4); // Set P4 high
pause(1); // Wait for circuit to charge
rf = rc_time(4, 1); // Measure decay time on P4
print("rf = %d\n", rf); // Display decay time
//pause(100);
high(5); // Set P5 high
pause(1); // Wait for circuit to charge
lf = rc_time(5, 1); // Measure decay time on P5
print("lf = %d\n", lf); // Display decay time
//pause(100);
high(8); // Set P8 high
pause(1); // Wait for circuit to charge
rb = rc_time(8, 1); // Measure decay time on P8
print("rb = %d\n", rb); // Display decay time
//pause(100);
high(9); // Set P9 high
pause(1); // Wait for circuit to charge
lb = rc_time(9, 1); // Measure decay time on P9
print("lb = %d\n", lb); // Display decay time
//pause(100);
frontsum=lf+rf;
printf("FRONTSUM %d\n", frontsum);
backsum=rb+lb;
printf("BACKSUM %d\n", backsum);
leftsum=lf+lb;
printf("LEFTSUM %d\n", leftsum);
rightsum=rf+rb;
printf("RIGHTSUM %d\n", rightsum);
spin=leftsum-rightsum;
printf("SPIN %d\n", spin);
tilt=frontsum-backsum;
printf("TILT %d\n", tilt);
//I then compare each labeled section to determine where the servose should move the panels (X and Y axis)
if(tilt<-30000)
{
servo_angle(25, 900); // P26 servo to 90 degrees
pause(20);
servo_stop();
printf("Clockwise tilt\n");
}
else if (tilt>30000)
{
servo_angle(25, 1800); // P26 servo to 180 degrees
pause(20);
servo_stop();
printf("CounterClockwise tilt\n");
}
if(spin<-30000)
{
servo_angle(26, 900); // P26 servo to 90 degrees
pause(20);
servo_stop();
printf("Clockwise\n");
} else if (spin>30000)
{
servo_angle(26, 1800); // P26 servo to 180 degrees
pause(20);
servo_stop();
printf("CounterClockwise\n");
}
pause(5000);
}
}
Comments
Have you had a chance to search this forum for similar projects?
Hope that helps for a start.