Friday Night Robotics – Portable… Fish.. Tank… Robot… ???

Posted by Erin, the RobotGrrl on Sunday, November 15th, 2009

This FNR I continued work on the blinky blink NXT LED fish! I added wheels to it, sensors, and the NXT brick. Basically, this now makes it a ‘portable fish tank robot’!

Portable Fish Tank Robot

The idea stemmed from the want to make a robot that can drive around on a table but not fall off. In particular, the table would be the table for the Autonomous Robotics Club at the admissions open house activity fair ^_^

Ultrasonic sensors are usually the best for this, since it depends on distance. Though, one could easily make a mechanism to trigger a touch sensor… or one could use a light sensor, but there is more possibility for error with a light sensor.

Portable Fish Tank Robot

The design right now has the ultrasonic sensor sticking out more that that, since it wasn’t far enough out… this means that sometimes the NXT couldn’t tell the motors to stop in time, and it would fall off the table.

The motors are geared to be fast, since I want it to be fast like a fish!

Portable Fish Tank Robot

The screen displays the ‘water level’ for the LED fish. In the picture, it used a method of drawing the level line by line, but I later refined it so that it uses a rectangle, and increments 3 pixels more so that it’s noticable when one presses the button.

Portable Fish Tank Robot

The robot can zip around pretty quickly, which produces some interesting artsy stuff:

Portable Fish Tank Robot

The LED fish are on the back of the robot, and the speed of their blinks is determined by how much ‘food’ they have. The more food, the more fast it is, the less food, the slower it is. When you press the button to feed the fish, it makes a bloop sound :P

Portable Fish Tank Robot

The LED fish is what makes this project. No one can resist the power of super-cute LED fish. They’re just so happy! :)

Here’s a video of the robot in action. It’s running the old program, but it’s all pretty much the same thing :)

The code for this is pretty cool. The NXT can handle up to 10 different simultaneous tasks! I use this to check the sensors for food and water, drive the robot, and blink the LED fish at the same time. Now, I’m still experimenting with the code, which is why there are bugs, random functions, and no comments in it.

  1. #pragma config(Sensor, S1,     HTPB,                sensorI2CCustom9V)
  2. #pragma config(Sensor, S2,     sonicSensor,         sensorSONAR)
  3. #pragma config(Sensor, S3,     touchSensor1,         sensorTouch)
  4. #pragma config(Sensor, S4,     touchSensor2,         sensorTouch)
  5. //*!!Code automatically generated by ‘ROBOTC’ configuration wizard               !!*//
  6.  
  7. /*
  8.   Crazy LEDs!
  9.   Erin K
  10.   Oct. 9th, 2009
  11. */
  12.  
  13. #include "drivers/common.h"
  14. #include "drivers/HTPB-driver.h"
  15.  
  16. byte theLEDs[] = { 0×01, 0×02, 0×04, 0×08, 0×10, 0×20 };
  17. int theTime = 50;
  18. int theWaterLevel = 32;
  19. int foodButton = 0;
  20. int waterButton = 0;
  21. int averageTouch1Level = 0;
  22. int averageTouch2Level = 0;
  23.  
  24. void fishTank(int theTime);
  25. void drawWaterLevel();
  26. void doSomething();
  27.  
  28. task blinkFish() {
  29.   while(true) {
  30.     fishTank(theTime);
  31.   }
  32. }
  33.  
  34. task checkFoodSensor() {
  35.  
  36.   while(true) {
  37.  
  38.     if(SensorValue(touchSensor1) == 1) {
  39.       theTime-=10; // Make fish faster
  40.       PlaySoundFile("bloop4.rso");
  41.       wait1Msec(1000);
  42.     }
  43.  
  44.   }
  45.  
  46. }
  47.  
  48. task checkWaterSensor() {
  49.  
  50.   while(true) {
  51.  
  52.     if(SensorValue(touchSensor2) == 1) {
  53.       theWaterLevel+=3; // Add water
  54.       PlaySoundFile("waterSPLASH.rso");
  55.       wait1Msec(1000);
  56.     }
  57.  
  58.   }
  59.  
  60. }
  61.  
  62. task drainWaterAndFood() {
  63.  
  64.   while(true) {
  65.  
  66.     wait1Msec(5000); // Wait 10 seconds
  67.     theTime += 10; // Make fish slower
  68.     theWaterLevel -= 2; // Drain water
  69.  
  70.   }
  71.  
  72. }
  73.  
  74. void drawWaterLevel() {
  75.   eraseDisplay();
  76.   nxtFillRect(0, theWaterLevel, 99, 0);
  77. }
  78.  
  79. task main() {
  80.  
  81.   // Setup all the digital IO ports as outputs (0xFF)
  82.   if (!HTPBsetupIO(HTPB, 0xFF)) StopAllTasks();
  83.   wait1Msec(200);
  84.  
  85.   eraseDisplay();
  86.   drawWaterLevel();
  87.  
  88.   float averageSonicLevel = 0;
  89.  
  90.   for(int i=0; i<5; i++) {
  91.    averageSonicLevel += SensorValue(sonicSensor);
  92.    wait1Msec(500);
  93.   }
  94.  
  95.   averageSonicLevel /= 5;
  96.  
  97.   StartTask(blinkFish);
  98.   StartTask(checkFoodSensor);
  99.   StartTask(checkWaterSensor);
  100.   StartTask(drainWaterAndFood);
  101.  
  102.   float sonicThresh = 10.0;
  103.  
  104.   bool driveMotors = false;
  105.  
  106.   while(true) {
  107.  
  108.     if((SensorValue(sonicSensor) > (averageSonicLevel-sonicThresh) || SensorValue(sonicSensor) < (averageSonicLevel+sonicThresh))) {
  109.  
  110.     doSomething();
  111.  
  112.     } else {
  113.      motor[motorB] = -40;
  114.      motor[motorC] = -40;
  115.      wait1Msec(1000);
  116.     }
  117.  
  118.     drawWaterLevel();
  119.     alive();
  120.  
  121.   }
  122.  
  123. }
  124.  
  125.  
  126. int doSomethingIterations = 0;
  127.  
  128. void doSomething() {
  129.  
  130.   doSomethingIterations++;
  131.  
  132.   motor[motorB] = 40;
  133.   motor[motorC] = 40;
  134.  
  135.   wait1Msec(100);
  136.  
  137. }
  138.  
  139.  
  140. void fishTank(int theTime) {
  141.  
  142.     // LEDs going up
  143.     for(int i=0; i<6; i++) {
  144.       if (!HTPBwriteIO(HTPB, theLEDs[i])) nxtDisplayTextLine(5, "ERR WRITE");
  145.       wait1Msec(theTime);
  146.     }
  147.  
  148.     // LEDs going down
  149.     for(int i=5; i>=0; i) {
  150.       if (!HTPBwriteIO(HTPB, theLEDs[i])) nxtDisplayTextLine(5, "ERR WRITE");
  151.       wait1Msec(theTime);
  152.     }
  153.  
  154. }

Eventually, I want to have the robot able to drive around in a square (a big square) autonomously. The square is around one of the dorm buildings, so there’s brick walls, stairs, fences, and people to avoid. I think it would be cool because the square is just so confusing at first. You can walk around it 5 times, and still think that you have gone somewhere.

Since a lot of smart people do this, if a robot does it we could imply that it is smart! Bahaha! Logic prevails!

I mentioned that this was originally intended for the activities fair. I also had MANOI there, doing its handshake routine! It went really good. We had a good 15 people show interest, which is surprisingly more than the orchestra, and the tables adjacent to ARC.

But, the table got hit by a frisbee. (Yes, my robot got hit by a frisbee) So, thanks to the jerks at the frisbee club, they messed up MANOI’s other knee (the good one– or what was the good one). So now MANOI has two bad knees, and can’t walk. The goal that I just obtained got wrecked. By a frisbee. Frisbee sucks, really bad.

(so, don’t join frisbee club, they’re morons)

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Posted in: Art, Programming, Projects, Robot.
Tags: , , , , , , , , , , , , , , , ,

One Response to “Friday Night Robotics – Portable… Fish.. Tank… Robot… ???”

  1. Lucy Says:

    Great effort to put them altogether.

Leave a Reply