CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Sun tracking robot

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
gregoryg



Joined: 21 May 2009
Posts: 14

View user's profile Send private message

Sun tracking robot
PostPosted: Mon May 25, 2009 6:32 pm     Reply with quote

Hello, I am working on a sun tracking robot. It moves on a certain path with 3 servo motors and at the same time 2 other servo motors adjust the solar panel in 2-D according to the data from 2 pairs of sensors .

This is a code for the wheels and the panel motors:
compiler 4.057
pic 16f877a
Code:
#include <16F877A.h>
#fuses HS, NOLVP
#use delay(clock = 20000000)

#define PWM_PIN1  PIN_B1   //wheel 1
#define PWM_PIN2  PIN_B2   //wheel 2
#define PWM_PIN3  PIN_B4   //wheel 3
#define PWM_PIN4  PIN_B3   //motor x
#define PWM_PIN5  PIN_B5   //motor y
#define LOOPCNT 390

static int16 width1,width2,width3,width4,width5;       
static int16 loop = LOOPCNT;
static int16 pulse1,pulse2,pulse3,pulse4,pulse5;

//-------------------------------
#INT_RTCC
void tick_interrupt(void);

//==========================================

 void main()
{
   width1=20;                  // move left
   width2=30;                 // dont move
   width3=40;                // move right
   setup_counters(RTCC_INTERNAL | RTCC_8_BIT, RTCC_DIV_1);   // (20MHz / (256*4*1)) = 20KHz
   enable_interrupts(INT_RTCC);                             // equals 0.05ms per interrupt
   enable_interrupts(GLOBAL);                              // 0.05ms*390 = 19.5ms(almost 20ms)
   delay_ms(30000); // move for 30 sec
  //-----------------------------------------------------------
  width1=40;
  width2=20;
  width3=30;
  delay_ms(30000);
   //-----------------------------------------------------------
   width1=30;
   width2=40;
   width3=20;   
   delay_ms(30000);
}
//====================================
#INT_RTCC
void tick_interrupt(void)
{
static int16 loop = LOOPCNT;
static int16 pulse1,pulse2,pulse3;

 if(--loop == 0 )                 
   {
    loop = LOOPCNT;
    pulse1=width1;
    pulse2=width2;
    pulse3=width3;
    pulse4=width4;
    pulse5=width5;
   }
 if(pulse1)
     {
    output_high(PWM_PIN1);
    pulse1--;
     }
else
   {
  output_low(PWM_PIN1);
  }
if(pulse2)
   {
  output_high(PWM_PIN2);
  pulse2--;
     }
 else
     {
    output_low(PWM_PIN2);
     }
     if(pulse3)
     {
    output_high(PWM_PIN3);
    pulse3--;
     }
  else
     {
    output_low(PWM_PIN3);
     }
     if(pulse4)
     {
    output_high(PWM_PIN4);
    pulse4--;
     }
  else
     {
    output_low(PWM_PIN4);
     }
     if(pulse5)
     {
    output_high(PWM_PIN5);
    pulse5--;
     }
  else
     {
    output_low(PWM_PIN5);
     }
   }
   

I want the panel to move every 2 seconds to the more lighted side.
I don't want to start writing a code that is not possible, so I wanted to make sure I am in the right direction.
Is it possible to run the A2D code inside second interrupt (TIMER1) every 2 sec and from there to set the direction of the motors?

Thank you.
P.S If you any comments on the code above , please let me know.
Ttelmah
Guest







PostPosted: Wed May 27, 2009 9:46 am     Reply with quote

Realistically, I'd reconsider this approach. The problem is that if (for example), shadows cross the system, you risk the unit moving off alignment, and then not being able to get back...

Instead, model the Sun's motion, with effectively a clock. For a single day, this is a simple sidereal motion. Have your detector, allowed to 'tweak' the clock motion by a small amount only (perhaps 1%), and at the end of the day, the average 'tweak' used during the whole day, is applied to the clock carried forwards. This then will slowly adjust the clock, to prevent it drifting from the real motion. Similarly, the azimuth, should only be tweaked by a small amount, 'day on day', but the correction carried forwards, so that the system will self correct for the seasons. Then have an overall intensity detector, or IR cloud detector, and if the intensity falls below a particular level (or cloud above a similar threshold), ignore the readings from the tracker completely, but just move with the sideral prediction.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group