Wednesday, February 18, 2009

Stabby MCstab stab, NXT Spike, programmed in perl, powered by twitter, he rocks your world


I couldn't just do, an "I love twitter" post, or twitter is so awesome it's my new favorite form of communication. No I have to show it's awesomeness.And that's why I made a robot that can knife people over twitter. That's right, I strapped a knife to spike, and you can control him over twitter. I am going to get stickam going so you can watch and control the robot over twitter, but only for the next few hours. To extend the tail send an @twitrnxtbot tail to retract the tail send a @twitrnxtbot retract. To get him to move forward send a @twitrnxtbot anythinggoeshere. Watch him. Control him.

So just to sum this up, if you ever had one of those moments when you wanted to stab someone on the other end of the computer...you can now.

As for some NXT resources, I know that all of you read english, and about half of you can read another language as well. You might need a translator on this one but it's a good resource: http://compilamasnaoroda.blogspot.com/ .

As for spike, I am thinking of adding features that let him communicate with the world, such as, the ability to tweet, that he is stuck, or he has attacked something of his own volition.

I modified the twitter code, that was originally made to display growl messages from here.

use Sys::Hostname;
use strict;
use warnings;
use LEGO::NXT;
use LEGO::NXT::Constants qw(:DEFAULT);
use LEGO::NXT::MacBlueComm;
use Mac::Growl ':all';
use Net::Twitter;
use Date::Format;
my $capsule = int(rand(99));
my $dev = new LEGO::NXT::MacBlueComm('/dev/tty.NXT-DevB-1');
my $bt = new LEGO::NXT( $dev );
my $speed = 100;
my $tachoticks = 1000;
my $tailFtac = 1000;
my $tailBtac = 1000;
my $tailSpeed = 100;
my $tailBSpeed = -100;
my $backSpeed = -100;
my $app = 'Growl/Twitter';
my @names = ('New Tweet');
my $bob = "test";
my $tail = "tail";
my $retract = "retract";
RegisterNotifications($app, \@names, [$names[0]]);

my $tweet = Net::Twitter->new( username=>'twitrnxtbot', password=>'password' );

my $last_id = undef;
my $switch = 0;

while(1)
{
my @tt = ();

if($last_id)
{
@tt = $tweet->friends_timeline({count => 5, since_id => $last_id });
}
else
{
@tt = $tweet->friends_timeline({count => 5 });
}

foreach my $t (@{$tt[0]})
{
my $target = $t->{text};
if($target =~ m/$tail/i){
$bt->set_output_state( $NXT_NORET, $NXT_MOTOR_A, $tailSpeed, $NXT_MOTOR_ON|$NXT_REGULATED, $NXT_REGULATION_MODE_MOTOR_SPEED, 0, $NXT_MOTOR_RUN_STATE_RUNNING, $tailFtac );
}elsif($target =~ m/$retract/i) {
$bt->set_output_state( $NXT_NORET, $NXT_MOTOR_A, $tailBSpeed, $NXT_MOTOR_ON|$NXT_REGULATED, $NXT_REGULATION_MODE_MOTOR_SPEED, 0, $NXT_MOTOR_RUN_STATE_RUNNING, $tailBtac );
}
else
{
print $target;
$bt->set_output_state( $NXT_NORET, $NXT_MOTOR_B, $speed, $NXT_MOTOR_ON|$NXT_REGULATED, $NXT_REGULATION_MODE_MOTOR_SPEED, 0, $NXT_MOTOR_RUN_STATE_RUNNING, $tachoticks );
$bt->set_output_state( $NXT_NORET, $NXT_MOTOR_C, $speed, $NXT_MOTOR_ON|$NXT_REGULATED, $NXT_REGULATION_MODE_MOTOR_SPEED, 0, $NXT_MOTOR_RUN_STATE_RUNNING, $tachoticks );
$bt->keep_alive($NXT_NORET);
}
PostNotification($app, $names[0], $t->{user}{screen_name}, $t->{text});

printf("%s: %s\n", $t->{user}{screen_name}, $t->{text});
print "sleep 4\n";

sleep(4);
}

$switch = 0;
print "sleep 4\n";
sleep(4);
}

exit;

4 comments:

COMPILA MAS NAO RODA said...

Thank´s a lot...
I´ll write some topic´s in English too.

Vendetta said...

Cool. Not that I understand much of it, lol.

smassey said...

You have got to be the most hardcore geek i've ever seen :) Keep your project alive, i'd love to stab you through IRC one day XD

Anonymous said...

I'd like to rent your robot to kill the rodent in my attic...