Go Down

Topic: Algorithm (Read 1 time) previous topic - next topic

saifallah

Hey every one

i have this code i want to know the algorithm for it , can anyone help me with it please.'



#include // include Servo library
// 180 horizontal MAX
Servo horizontal; // horizontal servo
int servoh = 180; // 90; // stand horizontal servo
int servohLimitHigh = 180;
int servohLimitLow = 65;
// 65 degrees MAX
Servo vertical; // vertical servo
int servov = 45; // 90; // stand vertical servo
int servovLimitHigh = 80;
int servovLimitLow = 15;
// LDR pin connections
// name = analogpin;
int ldrlt = 0; //LDR top left - BOTTOM LEFT <--- BDG
int ldrrt = 1; //LDR top rigt - BOTTOM RIGHT
int ldrld = 2; //LDR down left - TOP LEFT
int ldrrd = 3; //ldr down rigt - TOP RIGHT
void setup()
{ Serial.begin(9600);
// servo connections
// name.attacht(pin);
horizontal.attach(9);
vertical.attach(10);
horizontal.write(180);
vertical.write(45);
delay(3000);
}
void loop()
{ int lt = analogRead(ldrlt); // top left
int rt = analogRead(ldrrt); // top right
int ld = analogRead(ldrld); // down left

int rd = analogRead(ldrrd); // down right
// int dtime = analogRead(4)/20; // read potentiometers
// int tol = analogRead(5)/4;
int dtime = 10; int tol = 50;
int avt = (lt + rt) / 2; // average value top
int avd = (ld + rd) / 2; // average value down
int avl = (lt + ld) / 2; // average value left
int avr = (rt + rd) / 2; // average value right
int dvert = avt - avd; // check the diffirence of up and down
int dhoriz = avl - avr;// check the diffirence og left and rigt
Serial.print(avt);
Serial.print(" ");
Serial.print(avd);
Serial.print(" ");
Serial.print(avl);
Serial.print(" ");
Serial.print(avr);
Serial.print(" ");
Serial.print(dtime);
Serial.print(" ");
Serial.print(tol);
Serial.println(" ");
if (-1*tol > dvert || dvert > tol) // check if the diffirence is in the tolerance else change vertical angle
{
if (avt > avd)
{
servov = ++servov;
if (servov > servovLimitHigh)
{
servov = servovLimitHigh;
}
}
else if (avt < avd)
{
servov= --servov;
if (servov < servovLimitLow)
{
servov = servovLimitLow;
}
}
vertical.write(servov);
}
if (-1*tol > dhoriz || dhoriz > tol) // check if the diffirence is in the tolerance else change horizontal angle
{
if (avl > avr)

{
servoh = --servoh;
if (servoh < servohLimitLow)
{
servoh = servohLimitLow;
}
}
else if (avl < avr)
{
servoh = ++servoh;
if (servoh > servohLimitHigh)
{
servoh = servohLimitHigh;
}
}
else if (avl = avr)
{
// nothing
}
horizontal.write(servoh);
}
delay(dtime);
}

jack wp

Is this your school project?

What do you think the code is intended to do? Is it to water the garden on dry days?

saifallah

no its not a school project , its a code for a dual axis solar tracker developed by Browngadgets.com and it is open source.
i want the algorithm for it because I want to use the code but in a different way.
I have tried contacting the developer of this code but he didn't reply.
 

jack wp

#3
Sep 28, 2015, 06:59 pm Last Edit: Sep 28, 2015, 06:59 pm by jack wp
If you want to track solar, I would just assume that you want to position an array of solar panels.

Rather than trying to reverse engineer a script to an algorithm, that you want to modify anyway, it would be better if you provide an algorithm of what you want.

What do you want to do?
What equipment (hardware) do you already have for the project, and what will be needed?

It could be a rewarding project.

ferhatdogus

Merhaba yeni bir code buldum sorunsuz çalışıyor gerçi aradan konu açalı 3 sene olmuş umarım doğru kodu bulmuşsunuzdur

Go Up