30 de novembro de 2011

Vídeo de funcionamento.

Vídeo FINAL
http://www.youtube.com/watch?v=X-7HRqlC6bQ

Programação final

#include "NXCDefs.h"

int sentido_1=2, sentido_2=1, canal_1=1, canal_2=0, mudar_sentido_1=1, mudar_sentido_2=1, i=0;
//RECEBER INBOX 2
//ENVIAR OUTOBOX 5

task canal(){
while(true){
//ReceiveRemoteNumber(1,true,canal_1);
ReceiveRemoteNumber(2,true,canal_2);
}
}

void limpar_lcd(){
TextOut(10,LCD_LINE4," ");
TextOut(10,LCD_LINE5," ");
TextOut(10,LCD_LINE6," ");
TextOut(10,LCD_LINE7," ");
TextOut(10,LCD_LINE8," ");
}

task acao(){
while(true){
if(mudar_sentido_1==0 && mudar_sentido_2==0){
if(canal_1==1 && sentido_1==1 && sentido_2==2){
limpar_lcd();
TextOut(10,LCD_LINE4,"Recebendo");
TextOut(10,LCD_LINE5,"bolinhas");
TextOut(10,LCD_LINE6,"Enviando 1");
TextOut(10,LCD_LINE7,"para esteira");
for(i=0;i<10;i++){
SendRemoteNumber(1,5,1);
Wait(50);
}
Wait(2000);
mudar_sentido_1=1;
mudar_sentido_2=1;
limpar_lcd();
TextOut(10,LCD_LINE6,"Enviando 1");
TextOut(10,LCD_LINE7,"para carrinho");
for(i=0;i<10;i++){
SendRemoteNumber(2,4,1);
Wait(50);
}
limpar_lcd();
//canal_1=0;
}
if(canal_2==1 && sentido_1==2 && sentido_2==1){
limpar_lcd();
TextOut(10,LCD_LINE4,"Soltando");
TextOut(10,LCD_LINE5,"bolinhas");
OnFwd(OUT_C,40);
Wait(400);
Off(OUT_C);
Wait(1500);
OnRev(OUT_C,40);
Wait(350);
Off(OUT_C);
Wait(2000);
limpar_lcd();
TextOut(10,LCD_LINE6,"Enviando 1");
TextOut(10,LCD_LINE7,"para carrinho");
for(i=0;i<10;i++){
SendRemoteNumber(2,4,1);
Wait(50);
}
mudar_sentido_1=1;
mudar_sentido_2=1;
limpar_lcd();
canal_2=0;
}
if(canal_1==0 || canal_2==0){
TextOut(10,LCD_LINE8,"Aguardando..");
}
}
}
}

sub BTCheck(int x){
if(!BluetoothStatus(x)==NO_ERR){
switch(x){
case 1:{
TextOut(5,LCD_LINE2,"Erro na conexao");
TextOut(5,LCD_LINE3,"da esteira");
Wait(2000);
Stop(true);
break;
}
case 2:{
TextOut(5,LCD_LINE2,"Erro na conexao");
TextOut(5,LCD_LINE3,"do carrinho");
Wait(2000);
Stop(true);
break;
}
default:{
}
}
}
}

task motor_1(){
while(true){
if(mudar_sentido_1){
switch(sentido_1){
case 1:{
OnFwd(OUT_A,50);
until(SENSOR_2==1);
Off(OUT_A);
sentido_1=2;
break;
}
case 2:{
OnRev(OUT_A,50);
until(SENSOR_3==1);
Off(OUT_A);
sentido_1=1;
break;
}
default:{
}
}
mudar_sentido_1=0;
}
}
}

task motor_2(){
while(true){
if(mudar_sentido_2){
switch(sentido_2){
case 1:{
OnFwd(OUT_B,40);
until(SENSOR_1==1);
Off(OUT_B);
sentido_2=2;
break;
}
case 2:{
OnRev(OUT_B,40);
until(SENSOR_4==1);
Off(OUT_B);
sentido_2=1;
break;
}
default:{
break;
}
}
mudar_sentido_2=0;
}
}
}

task main(){
SetSensor(IN_1,SENSOR_TOUCH);
SetSensor(IN_2,SENSOR_TOUCH);
SetSensor(IN_3,SENSOR_TOUCH);
SetSensor(IN_4,SENSOR_TOUCH);
//BTCheck(1);
BTCheck(2);
TextOut(10,LCD_LINE1," Master");
TextOut(10,LCD_LINE2," Funcionando");
Precedes(motor_1,motor_2,canal,acao);
//SendRemoteNumber(BT_CONN,OUTBOX,i);
//ReceiveRemoteNumber(INBOX,true,ack);
}

23 de novembro de 2011

Programa

#include "NXCDefs.h"

int sentido_1=1, sentido_2=1, canal_1, canal_2, mudar_sentido=1;

task canal(){
ReceiveRemoteNumber(1,true,canal_1);
ReceiveRemoteNumber(2,true,canal_2);
}

task acao(){
if(canal_1==1 && sentido_1==2 && sentido_2==2){
SendRemoteNumber(1,5,0);
}
if(canal_1==1 && sentido_1==1 && sentido_2==1){
SendRemoteNumber(1,5,1);
Wait(2000);
mudar_sentido=1;
SendRemoteNumber(2,5,1);
}
if(canal_2==1 && sentido_2==2 && sentido_2==2){
OnFwd(OUT_C,40);
Wait(400);
Off(OUT_C);
Wait(1500);
OnRev(OUT_C,40);
Wait(350);
Off(OUT_C);
Wait(2000);
SendRemoteNumber(2,5,1);
mudar_sentido=1;
}
}

sub BTCheck(int x){
if(!BluetoothStatus(x)==NO_ERR){
if(x==1){
TextOut(5,LCD_LINE2,"Erro na conexao");
TextOut(5,LCD_LINE3,"da esteira");
Wait(2000);
Stop(true);
}
else{
TextOut(5,LCD_LINE2,"Erro na conexao");
TextOut(5,LCD_LINE3,"do carrinho");
Wait(2000);
Stop(true);
}
}
}

task motor_1(){
while(true){
if(mudar_sentido){
switch(sentido_1){
case 1:{
OnFwd(OUT_A,100);
until(SENSOR_1==1);
Off(OUT_A);
sentido_1=2;
break;
}
case 2:{
OnRev(OUT_A,100);
until(SENSOR_2==1);
Off(OUT_A);
sentido_1=1;
break;
}
default:{
}
}
mudar_sentido=0;
}
}
}

task motor_2(){
while(true){
if(mudar_sentido){
switch(sentido_2){
case 1:{
OnFwd(OUT_B,100);
until(SENSOR_3==1);
Off(OUT_B);
sentido_2=2;
break;
}
case 2:{
OnRev(OUT_B,100);
until(SENSOR_4==1);
Off(OUT_B);
sentido_2=1;
break;
}
default:{
}
}
mudar_sentido=0;
}
}
}

task main(){
SetSensor(IN_1,SENSOR_TOUCH);
SetSensor(IN_2,SENSOR_TOUCH);
SetSensor(IN_3,SENSOR_TOUCH);
SetSensor(IN_4,SENSOR_TOUCH);
BTCheck(1);
//BTCheck(2);
while(true){
TextOut(10,LCD_LINE1,"Master Funcionando!");
Precedes(motor_1,motor_2,canal,acao);
//SendRemoteNumber(BT_CONN,OUTBOX,i);
//ReceiveRemoteNumber(INBOX,true,ack);
}
}

12 de novembro de 2011

Com o bluetooth

#include "NXCDefs.h"
int aux=0;
int comando=0;
int x;
task main(){
SetSensor(IN_1,SENSOR_TOUCH); //x1
SetSensor(IN_2,SENSOR_TOUCH); //x2
SetSensor(IN_3,SENSOR_TOUCH); //y1
SetSensor(IN_4,SENSOR_TOUCH); //y2
x=BluetoothStatus(1);
/*
SendRemoteString(1,1,"ligar");
ReceiveRemoteString(2,true,comando);
*/
if(x!= NO_ERR){
TextOut(5,LCD_LINE3,"Nao conseguir conectar");
Wait(1000);
Stop(true);
}
else{
while(true){

//tempo pata chegar as bolinhas
Wait(5000);
// chegou as bolinhas

// 1 thread x
OnFwd(OUT_A, 60);
until (SENSOR_1 == 1);
Off(OUT_A);
Wait(100);

// 2 thread y
OnFwd(OUT_B, 60);// 2 thread
until (SENSOR_3 == 1);
Off(OUT_B);
Wait(100);

// 3 thread garra
//comunicação bluetooth
while(comando!=1){
SendRemoteString(1,1,"1");
ReceiveRemoteString(2,true,comando);
}
//comunicação bluetooth - chegou carrinho
if(comando==1){//o carrinho chegou
OnFwd(OUT_C, 60);
Wait(400);
Off(OUT_C);
Wait(100);
OnRev(OUT_C, 60);
Wait(400);
Off(OUT_C);
comando=0;
aux=1;
}
// 1 thread x - depois dar as bolinhas p o carrinho
if(aux==1){
OnRev(OUT_A, 60);
until (SENSOR_2 == 1);
Off(OUT_A);
Wait(100);

// 2 thread y - depois dar as bolinhas p o carrinho
OnRev(OUT_B, 60);// 2 thread
until (SENSOR_4 == 1);
Off(OUT_B);
Wait(100);
aux=0;
}
}
}
}

Inicio da programação

#include "NXCDefs.h"

task main(){
SetSensor(IN_1,SENSOR_TOUCH); //x1
SetSensor(IN_2,SENSOR_TOUCH); //x2
SetSensor(IN_3,SENSOR_TOUCH); //y1
SetSensor(IN_4,SENSOR_TOUCH); //y2
while(true){

//tempo pata chegar as bolinhas
Wait(5000);
// chegou as bolinhas

// 1 thread x
OnFwd(OUT_A, 60);
until (SENSOR_1 == 1);
Off(OUT_A);
Wait(100);

// 2 thread y
OnFwd(OUT_B, 60);// 2 thread
until (SENSOR_3 == 1);
Off(OUT_B);
Wait(100);

// 3 thread garra
//comunicação bluetooth - chegou carrinho
OnFwd(OUT_C, 60);
Wait(400);
Off(OUT_C);
Wait(100);
OnRev(OUT_C, 60);
Wait(400);
Off(OUT_C);

// 1 thread x - depois dar as bolinhas p o carrinho
OnRev(OUT_A, 60);
until (SENSOR_2 == 1);
Off(OUT_A);
Wait(100);

// 2 thread y - depois dar as bolinhas p o carrinho
OnRev(OUT_B, 60);// 2 thread
until (SENSOR_4 == 1);
Off(OUT_B);
Wait(100);

//Retoma o processo
}
}