NXShield Code Looping Issues
 Arduino   Started by LegoRobots   2015-09-16 02:48:27 -04:00   Comments: 2    Viewed: 1139

  1. LegoRobots
    LegoRobots Member Mowbray
    Hi,

    I am currently working on converting my Vertical-lift-span Railway Bridge from NXT Controlled too NXShield (Mega) Control.

    Virticle-Lift-Span Railway Bridge

    I am trying to figure out why the following CODE Loops through the first time o.k., but all subsequent loops fail to operate the motor when the "Start Button" is depressed.

    From the Debug Stream, it appears that all routines are called, but the motor is not activated...

    /******************************************************************************************    Computer Controlled LEGO Technic Vertical-Lift-Span Railway Bridge******************************************************************************************/#include <Wire.h>#include <NXShield.h>#include <NXTTouch.h>//  Declare shield variables for this programNXShield    nxshield;bool start_status;bool up_status;bool down_status;bool last_status;char str[50];int buttonState = 0;  // variable for reading the pushbutton status//  Declare Sensors for use in this programNXTTouch    topLimit;NXTTouch    bottomLimit;NXTTouch    startButton;/******************************************************************************************    Setup Vertical-Lift-Span Railway Bridge******************************************************************************************/void setup(){  char str[50];  Serial.begin(115200); // start serial for output  delay(500);           // wait, allowing time to activate the serial monitor  Serial.println ("Starting Bridge Contorl Program");  Serial.println ("");// initialize the shield i2c interface.  nxshield.init( SH_SoftwareI2C );// Flash NXShield LEDs  nxshield.ledSetRGB(5, 0, 0);  delay(250);  nxshield.ledSetRGB(0, 5, 0);  delay(250);  nxshield.ledSetRGB(0, 0, 5);  delay(250);  nxshield.ledSetRGB(0, 0, 0);  delay(250);  nxshield.ledSetRGB(5, 0, 0);//  initialize the touch sensor, and tell where it is connected.  startButton.init( &nxshield, SH_BAS1 );  bottomLimit.init( &nxshield, SH_BBS1 );  topLimit.init( &nxshield, SH_BBS2 );// reset motors.  nxshield.bank_a.motorReset();  nxshield.bank_b.motorReset();  Serial.println("setup done");}/******************************************************************************************    Control Loop for Vertical-Lift-Span Railway Bridge******************************************************************************************/void loop(){  Serial.println("Press Start to Operate Bridge");  while (true) {    // see if the sensor is pressed.    start_status = startButton.isPressed();    sprintf (str, "Start Button Depressed : %s", start_status ? "true" : "false");    Serial.println(str);    if (start_status != last_status) {      if (start_status == true) {        nxshield.ledSetRGB(5, 0, 0);        liftBridge();        lowerBridge();        nxshield.ledSetRGB(0, 5, 0);      } else {        nxshield.bank_a.motorStop(SH_Motor_1, SH_Next_Action_Brake);      }    }    last_status = start_status;  }}/******************************************************************************************    Lift Up the Bridge Deck******************************************************************************************/void liftBridge() {  Serial.println ("Lifting the Bridge");  while ( !up_status ) {    nxshield.bank_a.motorRunUnlimited(SH_Motor_1, SH_Direction_Forward, 100);    up_status = topLimit.isPressed();  }  Serial.println ("Bridge Lifted");  nxshield.bank_a.motorStop(SH_Motor_1, SH_Next_Action_Brake);}/******************************************************************************************    Lower Down the Bridge Deck******************************************************************************************/void lowerBridge() {  Serial.println ("Lowering the Bridge");  while ( !down_status ) {    nxshield.bank_a.motorRunUnlimited(SH_Motor_1, SH_Direction_Reverse, 100);    down_status = bottomLimit.isPressed();  }  Serial.println ("Bridge Lowed");  nxshield.bank_a.motorStop(SH_Motor_1, SH_Next_Action_Float);}



    As I have been pulling out what little hair of mine remains over many hours attempting to solve the issue, any help would be greatly appreaciated.

    cheers

    Ray
    LegoRobots, 2015-09-16 02:48:27 -04:00
  2. LegoRobots
    LegoRobots Member Mowbray
    Solved!

    /******************************************************************************************
        Lift Up the Bridge Deck
    ******************************************************************************************/

    void liftBridge() {
      Serial.println ("Lifting the Bridge");
      up_status = topLimit.isPressed();
      while ( !up_status ) {
        nxshield.bank_a.motorRunUnlimited(SH_Motor_1, SH_Direction_Forward, 100);
        up_status = topLimit.isPressed();
      }
      Serial.println ("Bridge Lifted");
      nxshield.bank_a.motorStop(SH_Motor_1, SH_Next_Action_Float);
    }



    /******************************************************************************************
        Lower Down the Bridge Deck
    ******************************************************************************************/

    void lowerBridge() {
      Serial.println ("Lowering the Bridge");
      down_status = bottomLimit.isPressed();
      while ( !down_status ) {
        nxshield.bank_a.motorRunUnlimited(SH_Motor_1, SH_Direction_Reverse, 100);
        down_status = bottomLimit.isPressed();
      }
      Serial.println ("Bridge Lowed");
      nxshield.bank_a.motorStop(SH_Motor_1, SH_Next_Action_Float);
    }
    LegoRobots, 2015-09-16 03:09:56 -04:00
  3. ( Locked)

Log in | Sign up
Tems & Conditions!
Help!