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;
Wednesday, February 18, 2009
Stabby MCstab stab, NXT Spike, programmed in perl, powered by twitter, he rocks your world
Tuesday, February 10, 2009
Spike attacks pillow, in a slow lame way, I blame lego, spike is powered by perl
Pay attention to the comments. Spike is powered by bluetooth/irc/a mac and a nxt brick. Yeah that's right, I have the world's most expensive remote control scorpion... what of it. Another video coming up soon...but until then, here's some code. Oh and the reason his attack lacked volitility, is because if you retract/plunge and you have left over ticks, the bot knows, so you have to even the odds, to get full power again. What I mean is say you give a motor a speed of 100 and 1000 ticks, but it only can go 50 ticks, because it runs into something, well it remembers there are 950 ticks owed, so until it gets to move those, it will have problems, trying to go the reverse way etc..
#put your dir to perl here
#with the exception of warnings and strict all of these pm's have to be installed
#I installed the MacBlueComm one seperately by dropping it in the appropriate dir
use Sys::Hostname;
use Net::IRC;
use strict;
use warnings;
use LEGO::NXT;
use LEGO::NXT::Constants qw(:DEFAULT);
use LEGO::NXT::MacBlueComm;
my $host = hostname();
my $capsule = int(rand(99));
my $hoster = 'nxtbot'.$capsule;
my $irc = new Net::IRC;
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 $tailMove = "tail";
my $tailRetract = "retract";
my $tailSpeed = 100;
my $tailBSpeed = -100;
my $conn = $irc->newconn(
#CHANGE THIS SERVER TO THE ONE YOU WANT TO USE
Server => shift || 'irc.malvager.com',
Port => shift || '6667',
Nick => $hoster,
Ircname => 'I like to greet!',
Username => 'fucker'
);
# We're going to add this to the conn hash so we know what channel we
# want to operate in.
#CHANGE THIS CHANNEL TO YOUR OWN
$conn->{channel} = shift || '#nxt';
sub on_connect {
# shift in our connection object that is passed automatically
my $conn = shift;
# when we connect, join our channel and greet it
$conn->join($conn->{channel});
$conn->privmsg($conn->{channel}, 'Hello everyone!');
$conn->{connected} = 1;
}
sub on_join {
# get our connection object and the event object, which is passed
# with this event automatically
my ($conn, $event) = @_;
# this is the nick that just joined
my $nick = $event->{nick};
# say hello to the nick in public
$conn->privmsg($conn->{channel}, "Fuck You, $nick!");
}
sub on_part {
# pretty much the same as above
my ($conn, $event) = @_;
my $nick = $event->{nick};
$conn->privmsg($conn->{channel}, "Such a dick, $nick!");
}
sub on_msg {
my ($conn, $event) = @_;
my $text = $event->{args}[0];
#If tail is said, move tail, if retract is said move tail back, anything else move robot forward
if($text eq $tailMove){
$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($text eq $tailRetract)
{
$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
{
$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);
}
}
sub on_public {
# $event->{to}[0] is the channel where this was said
}
$conn->add_handler('public', \&on_public);
$conn->add_handler('msg', \&on_msg);
$conn->add_handler('join', \&on_join);
$conn->add_handler('part', \&on_part);
# The end of MOTD (message of the day), numbered 376 signifies we've connect
$conn->add_handler('376', \&on_connect);
$irc->start();
Monday, February 9, 2009
Spike IRC NXT Mindstorm Video, using perl bot
So this video doesn't really show much, but whatevs. I will hopefully have the cleaned up code with a few new functions posted tomorrow.
Friday, February 6, 2009
The Weekend, WOOT! Lego Mindstorm perl bot thing
Yes I am aware of how the comments in the code make no sense on the lego nxt mindstorm post. I am going to clean all of that up this weekend as well as addressing shortcomings in the code and adding some more features. I will probably have a video of the robot doing it's thing this weekend as well as, a new song on goblin majick. So rock on guys.
Thursday, February 5, 2009
Lego Mindstorm NXT controlled via a perl bot ie LEGO::NXT
Ok so I have connected the NXT brick to my mac via bluetooth using these instructions:
http://juju.org/articles/2006/10/22/bluetooth-serial-port-to-nxt-in-osx
Yes Yes I know there for ruby...fuck it.
Ok so after that I have this script running on my computer in perl using lego::nxt and some other modules that you may or may not already have installed. Install all those modules. Now the next thing you need to do is change some of the variables, this bot connects to irc.malvager.com in room #malvager, with a name of nxtbot and a random number appended.
**I'll write a much more thorough and interesting post later about all of this but I am very busy tonight, and just wanted to get some content out.**
If you private message the bot his motor runs.
Here's the script:
use Sys::Hostname;
use Net::IRC;
use strict;
use warnings;
use LEGO::NXT;
use LEGO::NXT::Constants qw(:DEFAULT);
use LEGO::NXT::MacBlueComm;
#This is a wait, so that if the user isn't connected to a network
#it will wait 45 seconds giving them plenty of times to get connected
my $host = hostname();
my $capsule = int(rand(99));
my $hoster = 'nxtbot'.$capsule;
my $irc = new Net::IRC;
my $dev = new LEGO::NXT::MacBlueComm('/dev/tty.NXT-DevB-1');
my $bt = new LEGO::NXT( $dev );
my $speed = 100;
my $tachoticks = 1000;
my $conn = $irc->newconn(
Server => shift || 'irc.malvager.com',
Port => shift || '6667',
Nick => $hoster,
Ircname => 'I like to greet!',
Username => 'fucker'
);
# We're going to add this to the conn hash so we know what channel we
# want to operate in.
$conn->{channel} = shift || '#malvager';
sub on_connect {
# shift in our connection object that is passed automatically
my $conn = shift;
# when we connect, join our channel and greet it
$conn->join($conn->{channel});
$conn->privmsg($conn->{channel}, 'Hello everyone!');
$conn->{connected} = 1;
}
sub on_join {
# get our connection object and the event object, which is passed
# with this event automatically
my ($conn, $event) = @_;
# this is the nick that just joined
my $nick = $event->{nick};
# say hello to the nick in public
$conn->privmsg($conn->{channel}, "Fuck You, $nick!");
}
sub on_part {
# pretty much the same as above
my ($conn, $event) = @_;
my $nick = $event->{nick};
$conn->privmsg($conn->{channel}, "Such a dick, $nick!");
}
sub on_msg {
my ($conn, $event) = @_;
my $text = $event->{args}[0];
$bt->set_output_state( $NXT_NORET, $NXT_MOTOR_A, $speed, $NXT_MOTOR_ON|$NXT_REGULATED, $NXT_REGULATION_MODE_MOTOR_SPEED, 0, $NXT_MOTOR_RUN_STATE_RUNNING, $tachoticks );
}
sub on_public {
# on an event, we get connection object and event hash
# regex the text to see if it begins with clip
# $event->{to}[0] is the channel where this was said
}
$conn->add_handler('public', \&on_public);
$conn->add_handler('msg', \&on_msg);
# add event handlers for join and part events
$conn->add_handler('join', \&on_join);
$conn->add_handler('part', \&on_part);
# The end of MOTD (message of the day), numbered 376 signifies we've connect
$conn->add_handler('376', \&on_connect);
#ccgenerator
$irc->start();