Chauncey Lau
Published

Small Solar Follower Version 1.0

Using the TI-RSLK Max, I created a solar follower that avoids shade and follows the sun throughout the day.

IntermediateFull instructions provided543
Small Solar Follower Version 1.0

Things used in this project

Hardware components

TI Robotics System Learning Kit TI-RSLK
Texas Instruments TI Robotics System Learning Kit TI-RSLK
×1
BOOSTXL-BATPAKMKII Fuel Tank MKII Li-Po Battery BoosterPack
Texas Instruments BOOSTXL-BATPAKMKII Fuel Tank MKII Li-Po Battery BoosterPack
×1
6V 1.5W Solar Panel
×1
HS-311 Servo
×1
Photo resistor
Photo resistor
×3
Resistor 10k ohm
Resistor 10k ohm
×3

Software apps and online services

Energia
Texas Instruments Energia

Story

Read more

Code

Solar Follower Code

C/C++
#include <Servo.h>
#include "SimpleRSLK.h"
int pos = 0;
int mode = 0;
int wheelSpeed = 15;
int initial = 0;

Servo myservo;  // create servo object to control a servo
// a maximum of eight servo objects can be created


bool WithinRange(int X, int Y) {//helper function to be used in RemoveShade
  int Z = (abs(X - Y));

  return (Z <= 150);
}



void RemoveShade() {//reads values from photoresistors and then tells the robot which way to move to get out of shade
  int frontlight;
  int backlight;
  frontlight = analogRead(P4_1);
  backlight = analogRead(P6_0);
  while(!(WithinRange(frontlight, backlight)))
  {
    if (frontlight < backlight) {
      resetLeftEncoderCnt();
      resetRightEncoderCnt();
      /* Cause the robot to drive forward */
      setMotorDirection(BOTH_MOTORS, MOTOR_DIR_FORWARD);
      /* "Turn on" the motor */
      enableMotor(BOTH_MOTORS);
      /* Set motor speed */
      setMotorSpeed(BOTH_MOTORS, wheelSpeed);

    }
    else {
      resetLeftEncoderCnt();
      resetRightEncoderCnt();

      /* Cause the robot to drive backward */
      setMotorDirection(BOTH_MOTORS, MOTOR_DIR_BACKWARD);

      /* "Turn on" the motor */
      enableMotor(BOTH_MOTORS);

      /* Set motor speed */
      setMotorSpeed(BOTH_MOTORS, wheelSpeed);

    }

    frontlight = analogRead(P6_0);
    backlight = analogRead(P4_1);
  }
  {

    disableMotor(BOTH_MOTORS);
    frontlight = analogRead(P6_0);
    backlight = analogRead(P4_1);
  }

}



int FindInitialPos( ) { //cycles through servo position, and finds the position with the brightest light
  int initial = 0  ;
  int references = 0;
  {
    for (int test = -40; test < 180 ; test += 1) {
      myservo.write(test);
      delay (80);
      int current = analogRead(P6_1);
      if (current > references) {
        references = current;
        initial = test;
      }
    }
  }
  return initial;
}

int FindMode (){//Finds what the weather is like- values can be changed
  int mode = analogRead(P6_1);
  int sunny = 700;
  int modes;
  int cloudy = 450;
  int nighttime = 0;
  int maximumbrightness=0;
  for (int test = -30; test < 180 ; test += 1) {
    mode = analogRead(P6_1);
    myservo.write(test);
    delay(80);
    if (mode> maximumbrightness){
      maximumbrightness=mode;
      }
  }
      if (maximumbrightness > sunny ) {
      modes = sunny;
    }
    else if (maximumbrightness >= cloudy) {
      modes = cloudy;
    }
    else {
      modes = nighttime;
    }
  return modes;
}


int OptimalAngle(int weather, int startpos) {//This function is what allows the robot to change it's position throughout the day
  int current = analogRead(P6_1);
  while (current < weather) {
    startpos += 1;
    if (startpos >= 180) {
      weather = FindMode();
      startpos=0;
    }
    current = analogRead(P6_1);
    myservo.write(startpos);

    delay(80);
  }
  return startpos;
}

void setup() {
  setupRSLK();
  Serial.begin(9600);
  myservo.attach(P3_2);
  delay(50);
  pos = FindInitialPos();
  delay(50);
  mode = FindMode();
}


void loop() {
  // put your main code here, to run repeatedly:
  RemoveShade();
  pos = OptimalAngle(mode, pos);
}

Credits

Chauncey Lau

Chauncey Lau

1 project • 0 followers

Comments