View unanswered posts | View active topics It is currently Sun Jun 07, 2020 6:14 am

 Page 1 of 1 [ 7 posts ]
 Print view Previous topic | Next topic
Taking balls in the order of the image in robotc for nxt
Author Message
Rookie

Joined: Sat Jan 10, 2009 6:26 pm
Posts: 14
Taking balls in the order of the image in robotc for nxt
My robot takes the balls to 1 and puts at 2, corresponding to the following image:

I am using the following robot:

With motors and sensors in the following ports:

Motor A and B corresponds with the two wheels.
Motor C corresponds to the claws.

Last edited by lololol on Sat Jan 31, 2009 11:11 am, edited 5 times in total.

Wed Jan 14, 2009 7:30 am
Rookie

Joined: Sat Jan 10, 2009 6:26 pm
Posts: 14
Re: Taking balls in the order of the image in robotc for nxt
I already have solved the ball nº 1, now is taking all the balls from 1 to 2.
If you see some words you don´t understand, is because they are in portuguese.

Next i will present some rules for the game:
- the ball 1 and ball 2 goes to margin 2
- the ball 1 must to margin 1
- the ball 1 and ball 3 goes to margin 2
- the ball 1 and ball 2 must return to margin 1
- the ball 4 and ball 5 must to margin 2
- the ball 4 and ball 6 must return to margin 2
- the ball 4 and ball 6 goes to margin 2
- the ball 6 goes to margin 1
- the ball 6 and ball 7 must go to margin 2
- the ball 1 and ball 2 goes to margin 1
- the ball 1 and ball 8 goes to margin 2
- the ball 1 and ball 2 goes to margin 2

End of game

Last edited by lololol on Fri Jan 30, 2009 7:52 pm, edited 4 times in total.

Wed Jan 14, 2009 7:56 am
Rookie

Joined: Sat Jan 10, 2009 6:26 pm
Posts: 14
Re: Taking ball number 1
////////////////////////////////////////////////////////////////////
///////// move forward /////////
///////////////////////////////////////////////////////////////////
void moveFrente()
{
ClearTimer(T1);

while(time1[T1] < 3000)//the cicle is made in 1/3000=3 seconds
{
motor[motorA]=60;
motor[motorB]=60;
}
motor[motorA]=0;
motor[motorB]=0;
}

////////////////////////////////////////////////////////////////////
///////// move backward /////////
///////////////////////////////////////////////////////////////////
void moveTras()
{
ClearTimer(T1);

while(time1[T1] < 1000) //the cicle is made in 1/1000=1 second
{
motor[motorA]=-60;
motor[motorB]=-60;
}
motor[motorA]=0;
motor[motorB]=0;
}

//////////////////////////////////////////////////////////////////////
///////// turn left ////////////
//////////////////////////////////////////////////////////////////////
void viraEsquerda()
{

nMotorEncoder[motorA]=0;
while(nMotorEncoder[motorA]<810) //motor[A] gives a 180 degree
{
motor[motorA]=50;
}
motor[motorA]=0;
}

/////////////////////////////////////////////////////////////
///////// close claw /////////
/////////////////////////////////////////////////////////////
void fechaGarra()
{
motor[motorC]=-25;
}

/////////////////////////////////////////////////////////////
///////// open claw /////////
/////////////////////////////////////////////////////////////
void abreGarra()
{
motor[motorC]=25;
}

/////////////////////////////////////////////////////////////
///////// main /////////
/////////////////////////////////////////////////////////////
{
moveFrente();
fechaGarra();
wait1Msec(1000);
moveTras();
viraEsquerda();
moveFrente();
abreGarra();
wait1Msec(750);
PlaySound(soundUpwardTones);//listen a sound in the end
wait1Msec(1000);
}

Fri Jan 16, 2009 1:19 pm
Rookie

Joined: Sat Jan 10, 2009 6:26 pm
Posts: 14
Taking ball nº1 with sincronized motors
////////////////////////////////////////////////////////////////////
///////// move forward /////////
///////////////////////////////////////////////////////////////////
void moveFrente()
{
ClearTimer(T1);

while(time1[T1] < 3000)//the cicle is made in 1/3000=3 seconds
{
nSyncedMotors = synchAB;//sintonize motors
motor[motorA]=50;
}
motor[motorA]=0;
}

////////////////////////////////////////////////////////////////////
///////// move backward /////////
///////////////////////////////////////////////////////////////////
void moveTras()
{
ClearTimer(T1);

while(time1[T1] < 1000) //the cicle is made in 1/1000=1 second
{
nSyncedMotors = synchAB;//sintonize motors
motor[motorA]=-50;
}
motor[motorA]=0;
}

//////////////////////////////////////////////////////////////////////
///////// turn left ////////////
//////////////////////////////////////////////////////////////////////
void viraEsquerda()
{
nSyncedTurnRatio = -5; // Rotate in place

nMotorEncoder[motorA]=0;
while(nMotorEncoder[motorA]<810) //motor[A] gives a 180 degree
{
motor[motorA]=50;
}
motor[motorA]=0;
}

/////////////////////////////////////////////////////////////
///////// close claw /////////
/////////////////////////////////////////////////////////////
void fechaGarra()
{
motor[motorC]=-25;
}

/////////////////////////////////////////////////////////////
///////// open claw /////////
/////////////////////////////////////////////////////////////
void abreGarra()
{
motor[motorC]=25;
}

/////////////////////////////////////////////////////////////
///////// main /////////
/////////////////////////////////////////////////////////////
{
moveFrente();
wait1Msec(1000);
fechaGarra();
wait1Msec(1000);
moveTras();
wait1Msec(1000);
viraEsquerda();
wait1Msec(1000);
moveFrente();
wait1Msec(1000);
abreGarra();
wait1Msec(750);
PlaySound(soundUpwardTones);//listen a sound in the end
wait1Msec(1000);
}

Thu Jan 22, 2009 7:37 pm
Rookie

Joined: Sat Jan 10, 2009 6:26 pm
Posts: 14
Check if the ball is in the section 1
//*!!Sensor, S1, touchSensor, sensorTouch, , !!*//
const tSensors touchSensor = (tSensors) S1; //sensorTouch

//////////////////////////////////////////////////////////////////////
///////// program to verefy if ball is in the place ////////
//////////////////////////////////////////////////////////////////////

//see if touch sensor have been pressed //
{
while(true) //the condition of this cycle will always be checked
{
if(SensorValue(touchSensor) == 1)
{
motor[motorC]=-30;
}
else
{
motor[motorC]=30;
}

}

}

/////////////////////////////////////////////////////////////
///////// close claw /////////
/////////////////////////////////////////////////////////////
void fechaGarra()
{
motor[motorC]=-25;
}

/////////////////////////////////////////////////////////////
///////// main /////////
/////////////////////////////////////////////////////////////
{
fechaGarra();
wait1Msec(1000);
}

Thu Jan 22, 2009 7:43 pm
Rookie

Joined: Sat Jan 10, 2009 6:26 pm
Posts: 14
Cheking and Taking the ball nº1
//*!!Sensor, S1, touchSensor, sensorTouch, , !!*//
const tSensors touchSensor = (tSensors) S1; //sensorTouch

////////////////////////////////////////////////////////////////////
///////// move forward/////////
////////////////////////////////////////////////////////////////////
void moveInicio()
{
ClearTimer(T1);

while(time1[T1] < 2000)
{
nSyncedMotors = synchAB;
motor[motorA]=55;
}
motor[motorA]=0;
}

////////////////////////////////////////////////////////////////////
///////// move forward /////////
////////////////////////////////////////////////////////////////////

void moveFim()
{
ClearTimer(T1);

while(time1[T1] < 2000)
{
nSyncedMotors = synchAB;
motor[motorA]=50;
}
motor[motorA]=0;
}

////////////////////////////////////////////////////////////////////
///////// move backward/////////
////////////////////////////////////////////////////////////////////

void moveTras1casa()
{
ClearTimer(T1);

while(time1[T1] < 1000)
{
nSyncedMotors = synchAB;
motor[motorA]=-50;
}
motor[motorA]=0;
}

void move2casasTras()
{
ClearTimer(T1);

while(time1[T1] < 2000)
{
nSyncedMotors = synchAB;
motor[motorA]=-50;
}
motor[motorA]=0;
}

///////////////////////////////////////////////////////////////////////////
///////// Turn////////////
///////////////////////////////////////////////////////////////////////////
void viraEsquerda180()
{
nSyncedTurnRatio = -5; // Rotate in place

nMotorEncoder[motorA]=0;
while(nMotorEncoder[motorA]<810)
{
motor[motorA]=50;
}
motor[motorA]=0;

}

///////////////////////////////////////////////////////////////////////
////////turn///////////
///////////////////////////////////////////////////////////////////////
void viraEsquerda90()
{
nSyncedTurnRatio = -5; // Rotate in place

nMotorEncoder[motorA]=0;
while(nMotorEncoder[motorA]<400)
{
motor[motorA]=50;
}
motor[motorA]=0;
}

////////////////////////////////////////////////////////////////////
///////// Turn/////////
////////////////////////////////////////////////////////////////////
void move1casa()
{
ClearTimer(T1);

while(time1[T1] < 1000)
{
nSyncedMotors = synchAB;
motor[motorA]=55;
}
motor[motorA]=0;
}

/////////////////////////////////////////////////////////////
///////// close claw /////////
/////////////////////////////////////////////////////////////
void fechaGarra()
{
motor[motorC]=-25;
}

/////////////////////////////////////////////////////////////
///////// open claw /////////
/////////////////////////////////////////////////////////////
void abreGarra()
{
motor[motorC]=25;
}

/////////////////////////////////////////////////////////////
///////// main /////////
/////////////////////////////////////////////////////////////
{
moveInicio();//move forward
fechaGarra();
wait1Msec(1000);

///------------------------verefy ball-------------------------------///

while(true)
{
if(SensorValue(touchSensor) == 1)
{
//if catch ball is true

motor[motorC]=-30;//
//--------------------------------
moveTras1casa();
wait1Msec(750);
viraEsquerda180();
wait1Msec(750);
//-------------------
moveFim();
wait1Msec(750);
abreGarra();
wait1Msec(750);
PlaySound(soundBeepBeep);
wait1Msec(750);
//-------------------put's ready to the next ball
move2casasTras();
wait1Msec(750);
viraEsquerda90();
wait1Msec(750);

move1casa();
wait1Msec(750);
viraEsquerda90();
wait1Msec(750);
//--
move1casa();
wait1Msec(750);
}
else
{
//

motor[motorC]=30;//
}
}
///---------------------------------------------------------------///
}

Mon Jan 26, 2009 1:55 pm
Rookie

Joined: Sat Jan 10, 2009 6:26 pm
Posts: 14
Taking ball number 1 following lines.
Now i will do something more difficult, follow a red line and stop at a black line, joining together with the code already done:

//*!!Sensor, S1, touchSensor, sensorTouch, , !!*//
//*!!Sensor, S3, lightSensor, sensorLightActive, , !!*//

const tSensors touchSensor = (tSensors) S1; //sensorTouch

const tSensors lightSensor = (tSensors) S3; //sensorLightActive //*!!!!*//

///////////////////////////////////////////////////////////////////
///////// //////////
///////////////////////////////////////////////////////////////////

void moveFim()//
{

time1(T1) = 0;

while(time1(T1) < 10000)//10 seconds
{
nxtDisplayTextLine(2, "Value is %d", SensorValue[lightSensor]);

if(SensorValue(lightSensor) > 48 && SensorValue(lightSensor) < 57) //red
{
motor[motorA] = 50; //motor A is run at a 75 power level
motor[motorB] = 0; //motor B is run at a 0 power level
}

else
{
if(SensorValue(lightSensor) >= 57)//white
{
motor[motorA] = 0; //motor A is run at a 0 power level
motor[motorB] = 50; //motor A is run at a 75 power level
}

else//black
{
motor[motorA] = 0;
motor[motorB] = 0;
}
}

}
motor[motorA] = 0;
motor[motorB] = 0;
}

void fechaGarra()
{
motor[motorC]=-35;
}

void abreGarra()
{
motor[motorC]=20;
}

void andaTras1casa()
{
ClearTimer(T1);
while(time1[T1] < 1000)
{
motor[motorA]=-50;
motor[motorB]=-50;
}
motor[motorA]=0;
motor[motorB]=0;
}

void viraEsquerda90()
{
nMotorEncoder[motorA]=0;
while(nMotorEncoder[motorA]<135)
{
motor[motorA]=30;
motor[motorB]=-30;
}
motor[motorA]=0;
motor[motorB]=0;
}
/*void viraEsquerda180()
{
nMotorEncoder[motorA]=0;
while(nMotorEncoder[motorA]<270)
{
motor[motorA]=30;
motor[motorB]=-30;
}
motor[motorA]=0;
motor[motorB]=0;
}*/

{
nMotorEncoder[motorB]=0;
while(nMotorEncoder[motorB]<270)
{
motor[motorB]=30;
motor[motorA]=-30;
}
motor[motorB]=0;
motor[motorA]=0;
}

void move1casa()
{
ClearTimer(T1);

while(time1[T1] < 1600)
{
motor[motorA]=50;
motor[motorB]=50;
}
motor[motorA]=0;
motor[motorB]=0;
}
/////////////////////////////////////////////////////////////
///////// main /////////
/////////////////////////////////////////////////////////////
{
moveFim();//
wait1Msec(1000);
fechaGarra();
wait1Msec(1000);
///------------------------verefy ball-------------------------------///
while(true)
{
if(SensorValue(touchSensor) == 1)
{
//

motor[motorC]=-30;//

nxtDisplayCenteredTextLine(0,"Policia margem 2");//print a message
wait1Msec(2000);

//--------------------------------
andaTras1casa();
wait1Msec(1000);
wait1Msec(1000);
moveFim();
wait1Msec(1000);
abreGarra();
wait1Msec(1000);
PlaySound(soundBeepBeep);
wait1Msec(750);
//-------------------puts ready to the next ball
andaTras1casa();
wait1Msec(1000);
viraEsquerda90();
wait1Msec(1000);
move1casa();
wait1Msec(1000);
viraEsquerda90();
wait1Msec(1000);
}

else
{
//

motor[motorC]=30;
nxtDisplayCenteredTextLine(0,"Nao tem ninguem");
wait1Msec(2000);
}
}
}

From here you can do the rest to all the balls, following the rules. But be careful, this is not Arfificial Inteligence.
In Arfificial Inteligence you have to have a robot reconizing you´re environement. To do that you have to create an Algorithm or something else, example:
- Table Agent in a array
- A* Algorithm
- DepthFirstSearch
- DepthLimitedSearch
- ...

Sat Jan 31, 2009 11:18 am
Display posts from previous:  Sort by
 Page 1 of 1 [ 7 posts ]

#### Who is online

Users browsing this forum: No registered users and 2 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning