ROVer is online | last fetch at :: | status:

Live Camera Feed

ROVer Robot: Programming for Semi-Autonomous Operation. Building Logic for Future Capabilities

It’s a big programming episode today. If ROVer is to be autonomous, even semi-autonomous, he needs a big upgrade to his code/logic to support that, and that’s what we’re giving him today.

It started with a big upgrade to his Relay Manager – the board through which we run various wires from other boards so that we can programmatically turn on and off various components within ROVer’s design to conserve power. This now also gives us the ability to evaluate what is on and off at any give time while previously, with the simpler implementation that I had, it was a bit of a flying-blind situation.

Next, we tackle the task of making Programs, sets of commands, dynamic rather than hard-coded within ROVer’s Command Center programming. This became necessary as it the next step, programming for Events & Actions, would use the same type of dynamic creation and editing so we might as well get 2 birds with one proverbial stone, as it were.

Finally, we get to what we’re after, creating the logic that will permit us to create “rules” around which ROVer will operate based on events that he logs with the web server (aka Cloud / Command Center). Using the same programming that we built for handling his Programs, we devise a way to establish dynamic sets of commands that correspond to events, such as encountering an obstacle, for example.

Reference for Programmatically Restarting ROVer’s Android App (Brain):

http://stackoverflow.com/questions/6609414/how-to-programatically-restart-android-app

Reference for ROVer’s Relay Manager & Arduino Sketch:

https://whatjaysaid.wordpress.com/2014/10/13/arduino-bit-shifting-from-an-array/

// For Relay Management
const int latchPin = 4;
const int clockPin = 7;
const int dataPin = 5;

boolean sendCommands = false;

int relays[8] = {0,0,0,0,0,0,0,0};

void setup() //initializing serial communication baud rate

{

  flipRelays(relays);
  
  //For Relays
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);  
  pinMode(clockPin, OUTPUT);


   Serial.begin(9600); //sets the baud rate at 9600 to match the one set on the SSC-32 board
}

void loop() 

{

  char cmd = Serial.read();
  if (cmd >= '0' && cmd <= '7') {
    
    Serial.print("command sent: ");
    Serial.println(cmd);
    
    if(cmd == '0') {
      relays[0] = 1;
    } else if(cmd == '1') {
      relays[1] = 1;
    } else if(cmd == '2') {
      relays[2] = 1;
    } else if(cmd == '3') {
      relays[3] = 1;
    } else if(cmd == '4') {
      relays[4] = 1;
    } else if(cmd == '5') {
      relays[5] = 1;
    } else {
      relays[0] = 0;
    }

    flipRelays(relays);
  }

}

void flipRelays(int data[])
{
  long int toSend = 0;
 
  for(int i=15; i>=0; i--)
  {
    toSend |= data[i];
    if(i > 0)
    {
      toSend <<= 1;
    }
  }
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, (toSend >> 8));
  shiftOut(dataPin, clockPin, MSBFIRST, toSend);
  digitalWrite(latchPin, HIGH);
  return;
}

Leave a comment