ROBOTC.net Blog  

ROBOTC News

Archive for the ‘Cool projects’ Category

NXT Robot: PID Line Follower

with one comment

DiMastero is at it again…

This time he has created a robot that does some very fast line following.

Watch it in action


YouTube Direct Link 

Hardware

This line follower is equipped with three sensors: one light (port 3), one magnetic field (port 2) and one IR link, the last of which are by HiTechnic. The light sensor is used for the robot’s main purpose: line following, while the magnetic field sensor detects whether the robot needs to pause or keep going. The IR Link doesn’t have any function; it’s just there to keep the whole thing symmetrical.

rear view

Zoom on the magnet and magnetic field sensorside view

The robot moves using two independently moving motors connected to ports B and C. They form the follower’s back and sides. At the front, next to the light sensor is a caster wheel.

Detail of caster and light sensor

Programming

The robot was programmed in RobotC and runs on PID control.The motors’ built-in PID is off. When the code starts, it takes the black (line) and white (background) light values and averages them to get an offset. It then sets the bias of the HiTechnic magnetic field sensor to 0, while the magnet is in front of it. That way, the sensor’s value will change when the magnet is (re)moved.

Magnet is out of sensor's reach

Next, after a short wait, it starts driving around the NXT test paper, guided by the PID. It keeps on doing so until the magnet is removed, in which case it pauses the program and turns off the motors. Once the magnet is back in place, the robot keeps going, even if it’s been moved to somewhere else on the line. If the magnet stays away for too long (more than four seconds), the program shuts down.

You can download the latest version of the code on the downloads page or download version 2.1 (which was the latest version when this page was last updated) below.

Setup and Performance

To start the robot, place it above the middle of the black line you want to follow right after starting the program on the NXT. Then, when it bleeps, move the robot to the left of the line. Make sure you neither touch nor move the magnet.

After a split second, the robot will start to follow the line. To pause it, lift the “tail”, moving the magnet. To get it back on line, let go of the tail. To abort the entire program, hold the tail for four seconds, or until you see the light sensor turn off (it’s in active mode, so the LED will be on all the time when it’s operative).

The robot follows the black line pretty quickly and smoothly.

Written by Vu Nguyen

March 18th, 2011 at 12:03 pm

Posted in Cool projects,NXT

Dancing VEX robot: Bear Bot [Team 4542]

with 2 comments

Thanks to magiccode from the forums for posting this!

Overview

Our robotics team made a semi-humanoid dancing VEX robot with a holonomic drive in place of legs. It has full range of motion in both arms and two planes of motion in its head. It can bend at the waist, and strafe or turn in any direction.

It dances. plays the piano and beats little kids up. He is an all around entertainer. We only had about a day to program him, so bear with us… pun intended”

Video


YouTube Direct Link 

Description

There were 3 “cool” things that were done with ROBOTC:

  1. The robot mimics the movements of a human arm which is holding the VexNet joystick or Vex accelerometer. This will not work in all directions if the joytick is being used because the joystick lacks a z-axis, but it will work in all directions if the accelerometer is being used.
  2. There were too many motors to be controlled by one cortex, so we linked two together by running a male to male pwm wire from the digital output port of one to the digital input port of the other.
  3. Programming was made easier by writing a function called moveServo(). The function would accept 3 parameters: the servo to move, the position to which it should move, and the amount of time it should take (does not take into account changes in battery power)

Code:

moveServo(tMotor servoName, int posToMove, int timeToTake);

How it works


YouTube Direct Link 

Written by Vu Nguyen

March 1st, 2011 at 10:18 am

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

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

Communicating with the Magnetic Field Sensor

without comments

DiMastero, one of the new forum regulars has come up with a very novel way to use the new HiTechnic Magnetic Field Sensor; to relay messages by varying an NXT motor’s magnetic field. One position is set as a binary 0 and the opposite position is a 1.  The user can set the angle of the reference motor to 0-255 degrees (8 bits). The angle is then sent to the sensor using a “communication” motor and read by the sensor.  The NXT then copies the relayed angle to the other motor.  It’s a pretty cool way to use this sensor!

Check out the video below.


YouTube Direct Link 

The code for this project is available at the original article: [LINK].

Written by Xander Soldaat

December 30th, 2010 at 1:53 am

NXT Gyroscope Experiment

without comments

Thanks to DiMastero again for the project submission!

Here we have a Gyroscope using an NXT and programmed with ROBOTC. The wheel will automatically correct itself and keep it level no matter how you move and rotate the platform. Take a look at the video:


YouTube Direct Link 

How it works (From DiMastero)

In order to get some feedback, it’s programmed to show the motor’s speed (increased by ten percent every touch sensor click) and predict/ display the RPM the gyro is turning at, up to a maximum of 2500. The gyro is more or less stable from a motor speed of 20 onwards, but vibrations only stop after about 60. The gyro starts to straighten more quickly after about 80.

Photos

Gyroscope

Gyroscope 2

Gyroscope 3

Written by Vu Nguyen

December 21st, 2010 at 1:50 pm

Apollo, The Littlest LineLeader

with one comment

[Click to enlarge]This is Apollo, the smallest NXT based line follower I’ve ever made.  It’s loosely based on A-Maze-Ing, which I designed and built quite a while ago.

Apollo is equipped some pretty cool stuff:

The program in this robot is based on the same one I wrote for the Mean Lean Line Leading Machine. I made some improvements, of which includes the ability to enter the PID and speed parameters with the Numpad, rather than going through them with the NXT’s arrow keys.  You can also navigate the menu using the “2” and “8” keys for up and down and use “#” to make a selection.

I made a video of Apollo to try and show how the menu and Numpad sensor work but it’s a bit hard to really do it properly with Windows Live Movie Maker.  That’s my excuse for the quality of this video and I’m sticking to it!


YouTube Direct Link 

The source code for this robot will be part of the next release of the ROBOTC Driver Suite.

Original post here: [LINK].

Written by Xander Soldaat

November 29th, 2010 at 9:58 am

Posted in Cool projects

Avoider/Climber robot

without comments

Thanks DiMastero for posting this!

For those of us who have encountered obstacles with our robots that always seem to derail our current path, you will appreciate this robot.

DiMastero has figured out a way to solve our woes dealing with unleveled ground.

Presenting… the Avoider/Climber robot…

Side View

Wheels

Side view 2

Sensors

Bottom

Backside

It’s programmed to first drive forwards, until one of the bumpers is pressed. It then stops the wheel at that sensor’s side, and spins the other one until it’s pressed too, making sure it’s at a 90° angle from whatever is in front of it. The next thing it does is check the US sensor. If the distance to the object is less than 9 cm, it knows the obstacle is too high to climb, goes backwards and turns approximately 90°. When the sonar sensor’s value is below 9 cm, though, the middle motor, with the claw, turns a full turn, to hop the bot onto the platform. The avoider/ climber can do all of that in any order, enabling it to survive in a labyrinth with different floor levels, for example. The programming was done on RobotC.

Below is a video of it doing it’s thing:


YouTube Direct Link 

I’m open to any questions or suggestions for improvement.

[Source: http://dimastero.wordpress.com/2010/11/11/smart-climber-and-avoider-robot/]

Written by Vu Nguyen

November 24th, 2010 at 10:16 am

Posted in Cool projects