Arduino

The basic design of our arduino code was a timed finite state machine. The flow diagram is shown below.

This code can be improved with the addition of limit switches and a stepper motor. Limit switches would primarily serve as a safety feature, protecting the mechanism from overextending and breaking itself. The addition of limit switches would also enable the user to safely and freely control the arm's  movements. A stepper motor would benefit our design as well because of it's discrete and refined positioning. This enables us to more accurately set and adjust the height of feeding. 


Full code available on: https://github.com/SouLeo/RobotMechanismDesign/blob/master/FinalProject/FinalProjectRMD.ino

Arduino Code
#include "DualMC33926MotorShield.h"

DualMC33926MotorShield md;

int motor_speed = 200;
int motor_direction = 0;

int control_switch = 6;
int control_switch_current_status = LOW;
int control_switch_past_status = LOW;

void stopIfFault()
{
  if (md.getFault())
  {
    Serial.println("fault");
    while(1);
  }
}

void setup()
{
  Serial.begin(115200);
  Serial.println("Dual MC33926 Motor Shield");
  pinMode(control_switch, INPUT);  
  md.init();
}

void loop()
{
  control_switch_current_status = digitalRead(control_switch);
  if (control_switch_current_status == HIGH) {
    Serial.println("Switch Hit");
    Serial.println("Stopping!");
    md.setM1Speed(0);
    delay(100);
    Serial.println("UP");
    md.setM1Speed(motor_speed);
    delay(3000);
    Serial.println("Stopping!");
    delay(1000);
    Serial.println("DOWN");
    md.setM1Speed(-10);
    delay(3000);    
  }
}