Friday, September 24, 2010

Public and Pinball

I wonder if I should make this blog public.
Anyway, I built a pinball machine a while ago, before my NXT Offroader or my latest dragon. It was inspired by this pinball machine on NXTlog (this links to the secondary project for my inspiration project, for some reason, the main one is gone). It took a long time but turned out really well. Pictures are worth a thousand words, so here's an image of it. Its features included manual flippers, lost ball detector, ball launcher, two scoring methods and lights. I decided to try putting Lego brick elements on their sides to make the playing field. I used many Duplo elements for the board, and the originally liked to break because they didn't connect firmly enough. I put a brace on the bottom of the machine and that worked very well to hold the part of the machine where the ball rolls together. See it in the second picture here. However, the top of the machine, the "walls" nearer to the NXT Intelligent Brick, were very weak and often fell apart. Its first scoring mechanism was the touch sensor and bumper at the top-right of the machine, and the second was the light sensor "box" on the left side of the machine. When one of the sensors that detect scoring was detected, the NXT sent messages to the Power Functions battery box to flash the lights near the corresponding scoring zone. The sensor that detected the ball falling down past the flippers was a RCX light sensor, the idea for which I took from a Robotics Invention System book. I programmed this machine in Not eXactly C...It took hours, but it ended up working pretty well. The program will be at the bottom of this post. Bye!






/* Not eXactly C Code for NXT Ultra Pinball Machine III.

Idea for putting this NXC program in the NXT-G information box from m1n1f1g. Thanks.

Coded by NatoNX. ><> */

#define lights1on HTPFSingleOutputPWM(S4, PF_CHANNEL_1, PF_OUT_A, PF_PWM_FWD7) //define macros
#define lights1off HTPFSingleOutputPWM(S4, PF_CHANNEL_1, PF_OUT_A, PF_PWM_FLOAT)
#define lights2on HTPFSingleOutputPWM(S4, PF_CHANNEL_1, PF_OUT_B, PF_PWM_FWD7)
#define lights2off HTPFSingleOutputPWM(S4, PF_CHANNEL_1, PF_OUT_B, PF_PWM_FLOAT)

int balls; //initiate variables
int score;
int threshold1;
int threshold2;
string display;

task main ()
{
SetSensorTouch(IN_1); //set sensors
SetSensorType(IN_2, IN_TYPE_REFLECTION);
SetSensorLight(IN_3);
SetSensorLowspeed(IN_4);
while (true)
{
OnFwd(OUT_BC, 100); //light up lights powered off of NXT
ClearScreen();
TextOut(20, LCD_LINE2, "NXT Ultra"); //beginning screen
TextOut(5, LCD_LINE3, "Pinball Machine");
TextOut(36, LCD_LINE4, "III");
TextOut(15, LCD_LINE6, "Press Orange");
TextOut(24, LCD_LINE7, "to Start");
while (ButtonPressed(BTNCENTER, true) == TRUE) //wait for orange button to be pressed...
{
}
while (ButtonPressed(BTNCENTER, true) == FALSE) //...and released
{
}
ClearScreen();
TextOut(0, LCD_LINE1, "Use the flippers"); //instructions
TextOut(0, LCD_LINE2, "to get the ball");
TextOut(0, LCD_LINE3, "to hit the black");
TextOut(0, LCD_LINE4, "part at the top");
TextOut(0, LCD_LINE5, "and into the box");
TextOut(0, LCD_LINE6, "on the left. You");
TextOut(0, LCD_LINE7, "have 3 launches.");
TextOut(0, LCD_LINE8, "Press orange.....");
while (ButtonPressed(BTNCENTER, true) == TRUE) //wait for orange button to be pressed...
{
}
while (ButtonPressed(BTNCENTER, true) == FALSE) //...and released
{
}
ClearScreen();
threshold1 = Sensor(IN_3) + 3; //sets thresholds for light sensors
threshold2 = Sensor(IN_2) - 50;
balls = 2;
score = 0;
while (balls > -1)
{
display = "Score: "; //score and ball display
strcat(display, NumToStr(score));
TextOut(0, LCD_LINE2, display);
display = "Balls Left: ";
strcat(display, NumToStr(balls));
TextOut(0, LCD_LINE5, display);
if (Sensor(IN_1)) //if bumper is pressed, add to score...
{
score += 100;
PlayTone(440, 500);
lights1on; //...and flash touch sensor lights
Wait(200);
lights1off;
}
if (Sensor(IN_3) > threshold1) //if score light sensor detects something, add to score...
{
score += 500;
PlayTone(640, 500);
lights2on; //...and flash light sensor lights
Wait(200);
lights2off;
}
if (Sensor(IN_2) < threshold2) //if drain light sensor detects something...
{
balls -= 1; //subtracts from ball count...
PlayFile("! Attention.rso"); //...and plays a sound
Wait(1000);
}
}
ClearScreen(); //if ball count reaches -1, the the game ends. Screen clears
PlayFile("! Startup.rso"); //ending display and sequence
TextOut(17, LCD_LINE2, "Final Score");
TextOut(0, LCD_LINE4, NumToStr(score));
TextOut(23, LCD_LINE6, "Thanks for");
TextOut(0, LCD_LINE7, "playing! Please");
TextOut(12, LCD_LINE8, "press orange.");
while (ButtonPressed(BTNCENTER, true) == FALSE)
{
}
}
}

Monday, September 6, 2010

NXT 4X4 Offroader

First of all, I'm sorry that things have been so slow around here. Literally, one post every few months? Oh, well...

Anyway, a few months ago, I got this one great old Lego set....number 8466, the 4x4 Offroader. You can see it's original box's cover in the first picture (I hope that is is not illigal to take picture of Lego's boxes and put them online). Before I got it, I had already determined that I would try to "NXTize" it - Put NXT Motors and the NXT Intelligent Brick into it to make it mobile. This led me onto three attempts.

When I first built the set, I was disappointed - the drive train was very weak. I tried motorizing it anyway, and I put a Power Functions M motor on a worm and 24 tooth gear gear block. I put the whole thing on the pre-built drive train, and it moved, but with extremely low power and my Lego nemesis, gear slippage. So, I tried modifying the drive train. That didn't work either. Unfortunately, I don't have any picture of that first version, but it was a failure.

The second attempt consisted of me building my own chassis, and putting some 4X4 Offroader parts on top of it. When I built the chassis, I had in mind that I didn't want any gear slippage, so I built it with those four tooth knob gears to transfer power ninety degrees to the front and rear differentials. I also put in a transmission. Then, I put 4X4 Offroader parts on top of it. However, I modified them to make them wider. When I tested it, something went wrong. If I tried to move it forward and steer for too long, it stopped driving - some pressure got too high, and the transmission would slip. If I moved it backwards and then steer after that, it would go just fine - but then the transmission would slip again. Also, the steering arms rubbed against the inside of the wheels when it steered too much. This version was also a failure. You can see it in the second picture.

And now, the third version! This one is really recent, and is still standing now. This time, I simply built the motors almost directly driving the differentials - no drive axle or transmission this time! I wanted to make it so that each differential would be driven by two eight tooth gears for the "slow" original model, the 4x4 Offroader, and one 24 tooth gear for the "fast" alternative model, the 4X4 Race Buggy. I managed to get the steering wheel to turn with the front wheels, and I tried to make the decoration "engine" pistons spin as well, and I rigged up a cool mechanism to do so, but it's gears slipped and it fell off. When I built the third version, I had to lengthen the wheel sets apart to to fit the drive motors, and therefore gives the finished model a kind of "stretched" look, but it's not too bad. After it was basically done, I tried it using the eight-tooth gears, but it slipped, so I replaced them with one 24 tooth gear. After that, it worked well, but I have not tested it fully. See it here in the last picture.

Hopefully I'll get back here before too many months pass.

Nato