View unanswered posts | View active topics It is currently Thu Jul 24, 2014 4:06 pm






Reply to topic  [ 9 posts ] 
Coding Non-Sequentially 
Author Message
Rookie

Joined: Tue Mar 05, 2013 11:44 pm
Posts: 4
Post Coding Non-Sequentially
Hi there. I'm in a PLTW run course that utilizes the vex cortex along with the metal vex kits. I was wondering if it were possible to code non-sequentially. I've been tasked to design an elevator that uses three bump switches as call signals to make a motor move a platform up and down. When I code it, even after putting each function in it's own while loop with different sensor values, it still wants me to press each button in sequence. Here's an example of one of the codes for a single floor.

//Elevator is on floor 3//

while(sensorvalue(sonar)>18)
{
untiltouch(floor2);
startmotor(elevator, -127);
untilsonargreaterthan(12,sonar);
stopmotor(elevator);
}

while(sensorvalue(limit)==1)
{
untiltouch(floor1);
startmotor(elevator,-60);
untilsonarlessthan(8,sonar);
stopmotor(elevator);
}

For above, I would have to hit floor two, wait for it to reach floor two, and then manually reset the elevator to floor 3 to then press the floor one button to get it to work. Is it even possible to change this?


Tue Mar 05, 2013 11:54 pm
Profile
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post Re: Coding Non-Sequentially
Could you post your entire code please? Thanks.

_________________
I'm not a robot! I'm british! ~ quote from an asparagus
I am not a robot! I am a unicorn! ~ quote from a robot


Wed Mar 06, 2013 9:14 am
Profile
Rookie

Joined: Tue Mar 05, 2013 11:44 pm
Posts: 4
Post Re: Coding Non-Sequentially
Sure. Here's everything I wrote before I figured out the problem.

#pragma config(Sensor, dgtl1, red, sensorLEDtoVCC)
#pragma config(Sensor, dgtl2, yellow, sensorLEDtoVCC)
#pragma config(Sensor, dgtl3, green, sensorLEDtoVCC)
#pragma config(Sensor, dgtl4, floor3, sensorTouch)
#pragma config(Sensor, dgtl5, floor2, sensorTouch)
#pragma config(Sensor, dgtl6, floor1, sensorTouch)
#pragma config(Sensor, dgtl7, limit, sensorTouch)
#pragma config(Sensor, dgtl8, sonar, sensorSONAR_cm)
#pragma config(Sensor, dgtl11, quad, sensorQuadEncoder)
#pragma config(Motor, port2, elevator, tmotorVex269, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main()
{
while(1==1)
{
//Elevator on Floor 3//
while(SensorValue(limit)==1)
{
untilTouch(floor1);
startMotor(elevator,-60);
untilSonarLessThan(8,sonar);
stopMotor(elevator);
}
while(SensorValue(sonar)>18)
{
untilTouch(floor2);
startMotor(elevator,-60);
untilSonarLessThan(16,sonar);
stopMotor(elevator);
}
//Elevator on Floor 1//
while(SensorValue(quad)<299)
{
untilTouch(floor3);
startMotor(elevator,127);
untilTouch(limit);
stopMotor(elevator);
}
while(SensorValue(sonar)<12)
{
untilTouch(floor2);
startMotor(elevator,127);
untilSonarGreaterThan(12,sonar);
stopMotor(elevator);
}


}
}



And also, i've attached a few build pictures.


Attachments:
IMG_1149.JPG
IMG_1149.JPG [ 1.92 MiB | Viewed 3694 times ]
IMG_1148.JPG
IMG_1148.JPG [ 2.5 MiB | Viewed 3694 times ]
Wed Mar 06, 2013 7:34 pm
Profile
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post Re: Coding Non-Sequentially
Code:
task main()
{
  while(1==1)
  {
    //Elevator on Floor 3//
    while(SensorValue(limit)==1)
    {
      untilTouch(floor1);
      startMotor(elevator,-60);
      untilSonarLessThan(8,sonar);
      stopMotor(elevator);
    }
    while(SensorValue(sonar)>18)
    {
      untilTouch(floor2);
      startMotor(elevator,-60);
      untilSonarLessThan(16,sonar);
      stopMotor(elevator);
    }
    //Elevator on Floor 1//
    while(SensorValue(quad)<299)
    {
      untilTouch(floor3);
      startMotor(elevator,127);
      untilTouch(limit);
      stopMotor(elevator);
    }
    while(SensorValue(sonar)<12)
    {
      untilTouch(floor2);
      startMotor(elevator,127);
      untilSonarGreaterThan(12,sonar);
      stopMotor(elevator);
    }
  }
}



In the future, use the code tabs to make your code easier to understand. I'll try to work this out!

_________________
I'm not a robot! I'm british! ~ quote from an asparagus
I am not a robot! I am a unicorn! ~ quote from a robot


Thu Mar 07, 2013 6:37 pm
Profile
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post Re: Coding Non-Sequentially
Could you tell me the expected sensor values for each floor?

_________________
I'm not a robot! I'm british! ~ quote from an asparagus
I am not a robot! I am a unicorn! ~ quote from a robot


Thu Mar 07, 2013 6:43 pm
Profile
Rookie

Joined: Tue Mar 05, 2013 11:44 pm
Posts: 4
Post Re: Coding Non-Sequentially
Sure.

Floor one is precisely eight centimeters.

Floor two is about twelve to fourteen given the coasting on the elevator. (I had to replace a track because of a physical catch that would stop the elevator even at 127 motor power. With the new track it runs muuch smoother.)

Floor three is above nineteen centimeters.

I should be able to fiddle with these if they aren't quite on point. Thanks!


Thu Mar 07, 2013 6:54 pm
Profile
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post Re: Coding Non-Sequentially
What about limit and quad?

Also, do you want to be able to move to any floor from any other floor?

Sorry, but the more questions I ask, the more likely it is I will be able to help you.

_________________
I'm not a robot! I'm british! ~ quote from an asparagus
I am not a robot! I am a unicorn! ~ quote from a robot


Thu Mar 07, 2013 7:44 pm
Profile
Rookie

Joined: Tue Mar 05, 2013 11:44 pm
Posts: 4
Post Re: Coding Non-Sequentially
No problem! I'm the same way with questions. I haven't actually figured out how to use the quad, and i'm not sure it's necessary to use it anyway. The limit switch is on floor three. And yes, the objective is to be able to move from any floor to any floor. Please fill me in on what you do so I can learn to do it myself :D


Thu Mar 07, 2013 11:02 pm
Profile
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post Re: Coding Non-Sequentially
All right, here is some psuedo-code:

Code:
task main()
{
  short currentfloor = floor your elevator always starts on, presumably floor one;
  while(true)
  {
    switch(currentfloor)
    {
    case floor1:

      while(floor2button is not pressed and floor3button is not pressed){DO NOTHING}

      if(floor2button is pressed)
        go_to_floor2from1();
      else
        go_to_floor3from1();

      break;

    case floor2:

      while(floor1button is not pressed and floor3button is not pressed){DO NOTHING}
      if(floor1button is pressed)
        go_to_floor1from2();
      else
        go_to_floor3from2();

      break;

    case floor3;

      while(floor1button is not pressed and floor2button is not pressed){DO NOTHING}
      if(floor1button is pressed)
        go_to_floor1from3();
      else
        go_to_floor2from3();

      break;
    }
  }
}




You need to fill in the go_to_floorxfromx() functions with the commands that work. Also, these commands should write the new currentfloor value to it, so that when the switch runs again, it enters the correct block.

The reason this code works is that the switch enters the block for the current floor and waits for a button on another floor to be pressed, then goes to that floor and exits the switch to loop again.

I changed the 1==1 in the loop to true, as this just saves a compiler step and is easier to understand. Any always true statement works.


Finally, note that I used no multitasking, as it was not needed, and adding it would only cause confusion.

Tell me if this helps!

_________________
I'm not a robot! I'm british! ~ quote from an asparagus
I am not a robot! I am a unicorn! ~ quote from a robot


Fri Mar 08, 2013 1:52 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 9 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


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 post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.