ROBOTC.net Blog  

ROBOTC News

Archive for January, 2011

Classic game, Pong, on the NXT

with 4 comments

DiMastero, our recently discovered ROBOTC master, has done it again. He has re-created the classic game Pong on the NXT.

See it in action:


YouTube Direct Link 

How it works:

From DiMastero:

It uses my previous bouncing ball program, combined with a player-controlled bat, different levels, random difficulty increase and point display. The ball starts off at a random position within the playing field, to avoid patterns, after which it bounces off every wall (or bat) it meets, at a 90° angle. The bat is controlled by turning the wheel connected to motor A, and its stopped whenever it tries to exit the allowed area. Once the ball gets one pixel away from the bat, it compares its own position to the bat’s, and bounces away when it’s acceptable, increasing your point-count with one for each hit. In case it’s not, the game freezes and the famous “you lose” appears on the display, after which the program is aborted.

The game has different levels, too; the level you’re playing at is increased by one whenever your points are above 150% of the last level you passed (if the last level was ten, you’d need to get above 15, then 23, then 35, etc.), so it takes longer as you get better. Each time the level increases, the NXT randomly picks one of the following to make your life more difficult:

  • Increasing the ball’s speed, by decreasing the waiting time at the end of the main loop
  • Decreasing the bat’s speed, by increasing the amount of encoder ticks it takes to move one pixel
  • Making the bat smaller, by four pixels

Photos:

Pong Screenshot

Increased Difficulty

Written by Vu Nguyen

January 21st, 2011 at 8:44 am

Posted in Cool projects,NXT

NXT Color sorter using only ONE motor

without comments

All credit goes to ivanseidel of our ROBOTC forums. Great job!

ivanseidel noticed a few projects that used 2, 3, 4, 5, or even 6 motor assemblies that sorted LEGOs into separate containers. He then wondered, “where are the one motor sorters?”. So he went to work.

Below you will find a video of ivanseidel’s amazing creation, the one motor color sorter:


YouTube Direct Link 

On the actual coding algorithm, ivanseidel says, “The code is also a new thing, that adapts to the colors very easy, like a fusy algorithm.”

Code:

Below is the code for the main program:

#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);
 }
 }
 }
}

Below is the code for MV-lib.c:

//----------------------------------------------//
//----------------------------------------------//
//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();
 }
}

Written by Vu Nguyen

January 19th, 2011 at 8:33 am

Posted in Cool projects,NXT

New VEX Cortex Video Trainer Lessons – Writing Functions

without comments

The ROBOTC team is proud to announce four new tutorial videos in the VEX Cortex Video Trainer! The new videos how to turn a robot behavior (moving straight using encoder feedback) first into a basic function, and then a more advanced function with a parameter.

The videos can be found in the Sensing section under “Behaviors and Functions” in the VEX Cortex Video Trainer.

Written by Jesse Flot

January 14th, 2011 at 4:08 pm

Posted in Cortex,VEX

Using the VEX Motor Controller 29

with 3 comments

The VEX Motor Controler 29 allows you to connect the powerful VEX 2-wire Motors to any of the standard 3-wire ports on the VEX PIC and VEX Cortex.

1. To use the VEX Motor Controller 29, plug the 3-wire end into one of the MOTOR ports on your VEX PIC or VEX Cortex Microcontroller.

2. Connect the other end of the VEX Motor Controller to the 2-wire Motor. Be sure to align the black and red wires as shown.

3. Motors connected to your robot using the VEX Motor Controllers are programmed using the same commands and power levels as the 3-wire motors.

#pragma config(Motor, port2, rightMotor, tmotorNormal, openLoop, reversed)
#pragma config(Motor, port3, leftMotor, tmotorNormal, openLoop)
//*!!Code automatically generated by ‘ROBOTC’ configuration wizard !!*//
task main()
{
//Move forward at full speed for 2 seconds
motor[rightMotor] = 127; //Turn on the right motor at full power
motor[leftMotor] = 127; //Turn on the left motor at full power
wait1Msec(2000); //Wait here for 2000 milliseconds
//Stop for 1 second
motor[rightMotor] = 0; //Turn off the right motor
motor[leftMotor] = 0; //Turn off the left motor
wait1Msec(1000); //Wait here for 1000 milliseconds
//Move in reverse at half speed for 2 seconds
motor[rightMotor] = -63; //Reverse the right motor at half power
motor[leftMotor] = -63; //Reverse the left motor at half power
wait1Msec(2000); //Wait here for 2000 milliseconds
}

Building Tip:
To prevent the 2-wire Motor and Motor Controller wires from accidentally separating while the robot is running, use the supplied wire tie to secure the two ends, along with any excess wire.

For more help using your VEX Cortex, check out the VEX Cortex Video Trainer.

Written by Jesse Flot

January 7th, 2011 at 4:51 pm

CORTEX-Controlled Roomba robot

without comments

All credit goes to Paul Bouchier for creating this amazing robot!

Roomba Robot

I’m sure you’ve already heard about Roomba robots. You know, those great household vacuum-replacing cleaning robots that autonomously go around your house terrorizing your pets sucking up all of the dirt on your carpets, and even your non-carpeted floors too!

Paul was able to use a Cortex to create a Roomba that he could control on his own. He was able to achieve this with, ahem, ROBOTC!!!! (of course).

You can take a look at the video below to learn more about Paul’s creation:


YouTube Direct Link 

Photos

RoombaVEX

RoombaVEX 2

Written by Vu Nguyen

January 7th, 2011 at 9:44 am

Dexter Industries dGPS Sensor with Google Maps and ROBOTC

with 3 comments

Ever wanted to plot your path on a roadtrip or walk through the woods? Wanted to see where your robots went while you were asleep?

Dexter Industries has just made it super easy to do this and even more with ROBOTC using their dGPS sensor for the LEGO Mindstorms NXT!

The dGPS Sensor is $105.00 and is available from Dexter Industries.
Note: ROBOTC users can save 10% by typing in “robotcdgps” (without quotes)  in the coupon code area at checkout and receive 10% off the price of the dGPS until March 1st, 2011!

Using ROBOTC, the NXT and the dGPS sensor, you can download the included sample program program, drag it all over the earth, and then snap! open the file in Google Earth and see where you went.  In five easy steps:

  1. Download and send the sample program to your NXT.
  2. Attach the dGPS sensor to sensor port #1 and wait until it gets a signal.
  3. Start the program and proceed to wander around.
  4. Stop roaming. Connect your NXT back to your computer and using the NXT’s File Management dialog  (Robot – NXT Brick – File Management), download the file “Path.txt” to your desktop.
  5. Rename the file to “Path.kml”.  Double click the file to open with Google Earth and…  Voila.

Here’s a short video produced by the guys over at Dexter Industries showing off the cool new technology:

Written by Tim Friez

January 4th, 2011 at 4:51 pm

Project N.O.M.A.D.

with 2 comments

Project N.O.M.A.D stands for NXT Optimal Movement and Autonomous Drive and is the creation of Eric Smalls, one of the forums’ new users.

The robot, which is named S6, does more than just back up and spin around.  When an object is detected ahead, it will use the motor attached to the Ultrasound sensor to look around and turn to the side with the most space.  This goes a long way to preventing it from getting stuck in a corner.  Pretty clever.

Eric’s written up a few articles aboutS6, which you can read about [HERE], [HERE] and [HERE]. He also made a short video, which shows the robot doing its thing.


YouTube Direct Link 

Written by Xander Soldaat

January 1st, 2011 at 2:07 am

Posted in General News,NXT