View unanswered posts | View active topics It is currently Tue Dec 23, 2014 1:17 am






Reply to topic  [ 3 posts ] 
Sorting - yet another version 
Author Message
Rookie

Joined: Mon Feb 04, 2013 11:53 am
Posts: 1
Post Sorting - yet another version
As first own projet I built a sorting machine that sorts balls according to their color. NXT 2.0 parts did need supplements from Lego 9395 and odds and ends found at home. Here are some fotos, link to a video and listing of my code:

Image

Image

Image

Image

Image

Image

Link to the video: http://youtu.be/Ks86PhH8G1E

Code:
Code:
#pragma config(Sensor, S1,     LEFTS,          sensorTouch)
#pragma config(Sensor, S3,     RIGHTS,         sensorTouch)
#pragma config(Sensor, S4,     COLOR,          sensorCOLORFULL)
#pragma config(Motor,  motorB,          CARRIAGE,    tmotorNXT, PIDControl, encoder)
#pragma config(Motor,  motorA,          PUSHER,      tmotorNXT, PIDControl, encoder)
#pragma config(Motor,  motorC,          BALLS,       tmotorNXT, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

// Sorts colored balls
// UK 2.2.2013

// global variables
int VaunuVali;
int VaunuLukema;
int vauhti = 20;
string teksti;
bool jatkuu = false;
int vari;

void liikkuu(int nopeus)
{
  motor[CARRIAGE] = nopeus;
}

void seis()
{
  motor[CARRIAGE] = 0;
}

task main()
{
  wait10Msec(100);
  // texts on startup
  teksti = "";
  for(int i = 0; i <= 4; i++)
  {
    nxtDisplayTextLine(i, "%s", teksti);
  }
  teksti = "left <- pusher";
  nxtDisplayTextLine(1, "%s", teksti);
  teksti = "right -> ball";
  nxtDisplayTextLine(2, "%s", teksti);
  teksti = "orange -> start";
  nxtDisplayTextLine(3, "%s", teksti);
  // setting ball feeder and pusher in right positions
  while (jatkuu != true) {
    while (nNxtButtonPressed == 1) {
      motor[BALLS] = -10;
    }
    motor[BALLS] = 0;
    while (nNxtButtonPressed == 2) {
      motor[PUSHER] = 10;
    }
    motor[PUSHER] = 0;
    if (nNxtButtonPressed == 3) {
       jatkuu = true;
    }
  }

  // measure the distance between touch sensors (VaunuVali)
  // go first to the left then to the right
  liikkuu(vauhti);
  while (SensorValue(LEFTS) == 0)  {  }
  seis();
  VaunuVali = 0;
  nMotorEncoder[CARRIAGE] = 0;
  liikkuu(-vauhti);
  while (SensorValue(RIGHTS) == 0)  {  }
  seis();
  VaunuVali = abs(nMotorEncoder[CARRIAGE]);

  jatkuu = false;
  while (jatkuu != true) {

    // drop one ball to the pusher
    nMotorEncoder[BALLS] = 0;
    nMotorEncoderTarget[BALLS] = 180;
    motor[BALLS] = -5;
    while (nMotorRunState[BALLS] != runStateIdle) {  }
    motor[BALLS] = 0;
    nMotorEncoder[BALLS] = 0;
    nMotorEncoderTarget[BALLS] = 180;
    motor[BALLS] = 10;
    while (nMotorRunState[BALLS] != runStateIdle) {  }
    motor[BALLS] = 0;

    // carriage to left and push ball slightly forward
    liikkuu(vauhti);
    while (SensorValue(LEFTS) == 0)  {  }
    seis();
    nMotorEncoder[PUSHER] = 0;
    nMotorEncoderTarget[PUSHER] = 70;  // slightly forward
    motor[PUSHER] = 10;
    while (nMotorRunState[PUSHER] != runStateIdle) {  }
    motor[PUSHER] = 0;

    // find the color and go to the right box
    vari = SensorValue(COLOR);

    switch (vari) {
      case BLACKCOLOR:  // black means no ball
          jatkuu = true;  // end sorting
          VaunuLukema = VaunuVali / 2;
          break;
      case BLUECOLOR:
          VaunuLukema = 0;  // blue in first box from left
          break;
      case GREENCOLOR:
          VaunuLukema = VaunuVali / 4;  // green to second box
          break;
      case YELLOWCOLOR:
          VaunuLukema = (VaunuVali * 3) / 4;  // yellow to third box
          break;
      case REDCOLOR:
          VaunuLukema = VaunuVali;  // red to the last box
          break;
      default:
          VaunuLukema = VaunuVali;  // unknown color also to last box
    }

    nMotorEncoder[CARRIAGE] = 0;
    nMotorEncoderTarget[CARRIAGE] = VaunuLukema;
    if (VaunuLukema > 0) {
      liikkuu(-vauhti);
      while (nMotorRunState[CARRIAGE] != runStateIdle) {  }
      seis();
    }

    // drop the ball
    if (jatkuu == false) {
      nMotorEncoder[PUSHER] = 0;
      nMotorEncoderTarget[PUSHER] = 290;
      motor[PUSHER] = 10;
      while (nMotorRunState[PUSHER] != runStateIdle) {  }
      motor[PUSHER] = 0;
      wait10Msec(20);
      liikkuu(-vauhti);
      while (SensorValue(RIGHTS) == 0)  {  }
      seis();
    }
  }

  // exit the program
  PlaySound(soundBeepBeep);
  StopAllTasks();
}


Last edited by ForFun on Wed Feb 06, 2013 4:34 am, edited 1 time in total.



Mon Feb 04, 2013 1:01 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3297
Location: Rotterdam, The Netherlands
Post Re: Sorting - yet another version
Hey there,

It looks like a very nice project. I fixed the code in your post a bit by putting [ code] [/ code] (without the spaces) around it to make it a bit more readable. Do you think you could post your video on YouTube or some place like that? Makes it much easier to watch.

Regards,
Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Tue Feb 05, 2013 3:27 am
Profile WWW
Rookie
User avatar

Joined: Tue Aug 11, 2009 11:49 pm
Posts: 38
Location: Tasmania, the Land Down Under, the Land Downunder!
Post Re: Sorting - yet another version
I really like what you have done here. And it's nicely thought out mechanically too. I look forward to seeing your next effort.

I've been working on a 'Monster Sorter' myself over the last 6+ weeks.

Image

_________________
regards

Sparra Mc


Image


Mon Feb 11, 2013 4:18 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 3 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.