|
Page 1 of 1
|
[ 6 posts ] |
|
Project: Color sorter with only ONE motor [code and video]
Author |
Message |
ivanseidel
Rookie
Joined: Tue Sep 07, 2010 10:56 am Posts: 43
|
 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_embeddedThe 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 |
|
 |
starwarslegokid
Moderator
Joined: Wed Jan 31, 2007 3:39 am Posts: 299 Location: San Diego, California. USA
|
 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 |
|
 |
ivanseidel
Rookie
Joined: Tue Sep 07, 2010 10:56 am Posts: 43
|
 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!
_________________ My creations: techlego.blogspot.com
|
Tue Jan 18, 2011 2:11 am |
|
 |
vnguyen
Site Admin
Joined: Wed Jan 24, 2007 10:44 am Posts: 442 Location: Pittsburgh, PA
|
 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 | WebmasterNeed more support? Email ROBOTC Support at support@robotc.net to put in a support ticket Robotc.net| Robomatter Store | Robotics Academy | CS2N
|
Tue Jan 18, 2011 9:23 am |
|
 |
vnguyen
Site Admin
Joined: Wed Jan 24, 2007 10:44 am Posts: 442 Location: Pittsburgh, PA
|
 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 | WebmasterNeed more support? Email ROBOTC Support at support@robotc.net to put in a support ticket Robotc.net| Robomatter Store | Robotics Academy | CS2N
|
Tue Jan 18, 2011 9:42 am |
|
 |
ivanseidel
Rookie
Joined: Tue Sep 07, 2010 10:56 am Posts: 43
|
 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 |
|
|
|
Page 1 of 1
|
[ 6 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
|
|