View unanswered posts | View active topics It is currently Thu Apr 17, 2014 10:06 am






Reply to topic  [ 6 posts ] 
Project: Color sorter with only ONE motor [code and video] 
Author Message
Rookie

Joined: Tue Sep 07, 2010 10:56 am
Posts: 43
Post Project: Color sorter with only ONE motor [code and video]
Hi,
Made this as a chalenge... i have seen color sorter with 2,3,4,5 and even 6 motor, but where is the one motor color sorter?
read more in my blog: techlego.blogspot.com

http://www.youtube.com/watch?v=KIY5oJYz ... r_embedded

The code is also a new thing, that adapts to the colors very easy, like a fusy algorithm.
Hope you enjoy!

The code:
Code:
#pragma config(Sensor, S1,     L,                   sensorLightActive)
#pragma config(Sensor, S4,     T,                   sensorTouch)
#pragma config(Motor,  motorA,          M1,            tmotorNormal, openLoop, encoder)

//Função: separador de cores com lego mindstorms nxt
//Código feito por Ivan Seidel
//http://techlego.blogspot.com/

//Peço que deixem meus créditos apenas!

#include "MV-lib.c"

#define SpeedNormal           56
#define DifMaxLight           50
#define RotateAngleFirst      200
#define RotateAngleMultiple   180
#define RotateAngleBack       150
#define RotateAngleAfterT     0
#define MaxColors             7

int ArrayLights[10];
int ColorsFound = 0;
int LightValue;

//Le o valor do sensor deluz, e checa se esta no range de algum valor do array
//Reads light sensor and checks if that value is in the range of somevalue in the array
int IsInRange(int CheckValue){
  int i=0,found=-1;
  while(i<ColorsFound){
    if(CheckValue<=ArrayLights[i]+DifMaxLight && CheckValue>=ArrayLights[i]-DifMaxLight && ArrayLights[i]!=0){
      found=i;
      break;
    }
    i++;
  }
  return found;
}

void InsertValue(int InsertValue){
  ArrayLights[ColorsFound]=InsertValue;
  ColorsFound++;
}

task main(){
  int KeepRuning=true;
  while(KeepRuning){

    //Reseta todos os valores e vai para o comeco
     //Resets position and all states to 0
     while(SensorValue[T]==0){
       motor[M1]=SpeedNormal;
     }
     MV_StopMotors();
     MV_Vira(-SpeedNormal,RotateAngleAfterT,M1);
     wait10Msec(50);
     //Inicia o programaprincial de separar as cores
     //Starts the main program of sorting coloros
    int samples=10,LightValue;
     for(int y=0;y<samples;y++){
       LightValue+=SensorRaw[L];
     }
     LightValue=LightValue/samples;
     MV_Vira(SpeedNormal/1.5,RotateAngleFirst,M1);
     bool looping=true;
     while(looping){
       int foundColorPosition=IsInRange(LightValue);
       if(foundColorPosition!=-1){
           for (int i=0;i < foundColorPosition+1;i++){
                  PlayTone(500,5);
                wait10Msec(10);
            }
            wait10Msec(50);
         MV_Vira(SpeedNormal,(foundColorPosition+1)*RotateAngleMultiple,M1);
         MV_Vira(-SpeedNormal*1.6,RotateAngleBack,M1);
         wait10Msec(50);
         looping=false;
        }else{
          InsertValue(LightValue);
        }
      }
  }
}

_________________
My creations: techlego.blogspot.com


Fri Jan 14, 2011 1:43 pm
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post Re: Project: Color sorter with only ONE motor [code and video]
Very nicely done B-)

I'm going to move this to the projects section for people to see

Scott B-)

_________________
Mmmm Legos B-)

My Robot Projects:
http://www.freewebs.com/robotprojects/


Mon Jan 17, 2011 6:04 pm
Profile WWW
Rookie

Joined: Tue Sep 07, 2010 10:56 am
Posts: 43
Post Re: Project: Color sorter with only ONE motor [code and video]
Tank you Scott =]

I forgot the MV-lib.c, the move library that i have made... it is very helpfull for many projects too!
Code:
//----------------------------------------------//
//----------------------------------------------//
//Library que possui as funcoes de mover motores//
//----------------------------------------------//
//----------------------------------------------//
#define MV_EMotor    motorA
#define MV_DMotor    motorC
#define MV_GarraMotor     motorB
#define MV_TimeLimit 70 //5 secs

void MV_StopMotors(){
   motor[MV_EMotor] = 0;
  motor[MV_DMotor] = 0;
  motor[MV_GarraMotor]  = 0;
}

void MV_Reto_Unlimited(int forca,int steering=0){
   motor[MV_EMotor]=forca+steering;
   motor[MV_DMotor]=forca-steering;
}
void MV_Spin_Unlimited(int forca){
   motor[MV_EMotor]=forca;
   motor[MV_DMotor]=-forca;
}

void MV_Vira(int forca, int degree,byte lado, int tempo=0){
   time100[T2]=0;
   if(degree>0){
      nMotorEncoder[lado]=0;
      while(nMotorEncoder[lado]<degree && nMotorEncoder[lado]>-degree && time100[T2]<MV_TimeLimit){
         motor[lado]=forca;
      }
      MV_StopMotors();
   }else if(tempo>0){
      time100[T1]=0;
      while(time100[T1]<tempo){
         motor[lado]=forca;
         motor[lado]=forca;
      }
      MV_StopMotors();
   }
}

void MV_Spin(int forca, int degree, int tempo=0){
   time100[T2]=0;
   nMotorEncoder[MV_EMotor]=0;
   nMotorEncoder[MV_DMotor]=0;
   if(degree>0){
      while(nMotorEncoder[MV_EMotor]<degree && nMotorEncoder[MV_EMotor]>-degree && time100[T2]<MV_TimeLimit){
         motor[MV_EMotor]=forca;
         motor[MV_DMotor]=-forca;
      }
      MV_StopMotors();
   }else if(tempo>0){
      time100[T1]=0;
      while(time100[T1]<tempo){
         motor[MV_EMotor]=forca;
         motor[MV_DMotor]=-forca;
      }
      MV_StopMotors();
   }
}

_________________
My creations: techlego.blogspot.com


Tue Jan 18, 2011 2:11 am
Profile WWW
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:44 am
Posts: 438
Location: Pittsburgh, PA
Post Re: Project: Color sorter with only ONE motor [code and video]
Wow, this is very impressive! I'm going to add it to the Cool Projects section of robotc.net.

_________________
Vu Nguyen
Software Training Development Team | Webmaster
Need more support? Use the ROBOTC Ticketing system

Robotc.net| Robomatter Store | Robotics Academy | CS2N


Tue Jan 18, 2011 9:23 am
Profile
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:44 am
Posts: 438
Location: Pittsburgh, PA
Post Re: Project: Color sorter with only ONE motor [code and video]
Alright, this is scheduled to appear on the Cool Projects blog tomorrow (1/19/11). Thanks!

_________________
Vu Nguyen
Software Training Development Team | Webmaster
Need more support? Use the ROBOTC Ticketing system

Robotc.net| Robomatter Store | Robotics Academy | CS2N


Tue Jan 18, 2011 9:42 am
Profile
Rookie

Joined: Tue Sep 07, 2010 10:56 am
Posts: 43
Post Re: Project: Color sorter with only ONE motor [code and video]
Tanks Nguyen!
I'm glad you liked!
Ivan

_________________
My creations: techlego.blogspot.com


Tue Jan 18, 2011 10:31 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


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.