Showing posts with label nxt. Show all posts
Showing posts with label nxt. Show all posts

Wednesday, December 23, 2009

A note to perl enthusiasts trying to get Lego::NXT installed on their machines

If you keep getting cpan errors trying to install Net::Bluetooth or LEGO::NXT...

You need to first install Device::SerialPort first.

Save you many headaches.

Sunday, October 11, 2009

Some Bad photography of mine, and my nxt stuff

Suffer?


I took a couple shots of my NXT face I made. Video with functionality soon.

Saturday, October 3, 2009

Prepping Fedora Core for NXT brick, and Arduino, to be used with pygame and mod_python, in a python environment

If you do a fresh install of Fedora 11, you just need to save this script and run it as root on your machine, once you have saved it with a .sh extenstion, open the terminal, use the command su to become root, then navigate to the directory you have saved it in. Change the permissions, before you try to run it, so it is executable. Run it by typing dot then slash the the script name: ./scriptname.sh

Before the script:
su
chmod 777 scriptname.sh


#! /bin/bash
yum -y install mod_python
mkdir -p /var/www/html/test
cat <<-EOF >/etc/httpd/conf.d/pythonTwo.conf
<Directory /var/www/html/test>
AddHandler python-program .py
PythonHandler mptest
PythonDebug On
</Directory>
EOF
cat <<-EOF >/var/www/html/test/mptest.py
#!/usr/bin/python
from mod_python import apache

def handler(req):
req.send_http_header()
req.write("Hello World!")
return apache.OK
EOF
yum -y install python-devel
yum -y install git
git clone http://github.com/lupeke/python-firmata.git
cd python-firmata
python setup.py install
yum -y install gcc
yum -y install pybluez
yum -y install nxt_python
yum -y install pygame
/usr/sbin/apachectl restart


**caveat**
Be careful where you save it, it will create a directory for the python-firmata in that directory. If you use this right when your machine boots, there is a possibility the yum updater will start using yum, if the script will pause until the updater is finished using yum then continue, or you can run it before you start the script.

Sunday, July 12, 2009

News in brief

This weekend was a total wash.I really thought I was going to master rails in a single sitting but it just wasn't in the cards for me. I don't know if rails is that complicated, or I am just dumb. Anyways I definetly have a much firmer grasp on rails now, and am just at a point where I can actually start hacking away at a web app. Yeah it took that long. I was going to impliment a pleasure/pain system in my nxt brick robot and have people be able to give it rewards based on what it was doing, through a rails application I thought it might be easier than perl simply because I knew that rails had a database abstraction layer.....Oh what I didn't know. Anyway, I rebuilt the next brick according to someone elses design as well, to get it more suited for such a task, however, the configuration I used couldn't turn left or right....DOH. So event that was a wash. I also came to the realization it's getting harder and harder for me to start popping out a simple perl script once or twice a week, without either repeating myself or not paying enough attention to the script or the writing. Normally what I produce on my blog posts are simple hacks you can do in a single sitting. It looks like that will be changing(though I am sure every now and then I will pop one out, just out of scratching my own itch). I will be concentrating more on ruby and still on perl as will with a minor in objective c and maybe just plain c from now on. That being said I am also going to start focusing more on computer security as well, as this was the original intention of the blog, the robotics stuff will still be there.
So Check out Leggor.de and in particular Herold's Truck, I will embed the video below. The video is very well produced and meticulous, if not a bit creepy at the same time.


Thanks to leggor.de, i found that there are indeed lego cad files, you can open them in a variety of programs, I have been using Lego digital designer and have found that that works best for me(Windows and Mac).

That being said I also revisted my strobe design on my arduino chip, and relized that, that post is badly written and the code is worse, so here is some corrected code, with the caveat of this design probably needs to be calibrated using the serial monitor based on the lighting in the room:


#define LED 13 // LED connected to digital pin 13

int val = 0;
void setup()
{
pinMode(LED, OUTPUT); // sets the digital pin as output
Serial.begin(9600);
}

void loop()
{
val = analogRead(0);
Serial.print(val);
Serial.print('\r');
if(val < 13) {
digitalWrite(13, HIGH);
delay(100);
digitalWrite(13, LOW);
delay(100);
digitalWrite(13, HIGH);
} else {
digitalWrite(13, LOW);
}
}


That being said, my hubris has raised the chance of a real technical post for this weekend to about 99 percent fail, I am still going to try and crank something out but who knows.

Old Arduino Strobe post

PS

I built alpharex wrong, I'm sorry.

Saturday, July 4, 2009

Alpha-Rex, Ruby-nxt fail, out takes of my robot with a microkorg voice



***EDIT Appparently I built him wrong as at LEAST 200 hundred people have let me know END EDIT July 12th 2009***

Alpha Rex is a horrible design, but only partially my fault. He was designed by lego and is the flagship robot for the nxt design series. I had to improvise a lot of the building because I just didn't have the parts. And yeah I may have lost a lego or two, but not that many honestly for the amount of improvisation involved. On top of that I could tell just by the design that his "legs" were just a hack. He doesn't really walk, in fact much more similar to spike, he "land swims". With the program I wrote for him I pretty much just wanted to get him to walk by alternating the motors. Oh woah is me. Just watch the video to see what ensuses. So just wanting a robot platform to put intelligence into I sit and I wait and I hope, eyes gazing towards the Nao robots.

Sunday, June 7, 2009

Motion Detecting Lego NXT mindstorm arm written in ruby




The building instructions for this arm can be found here:
http://www.nxtprograms.com/robot_arm/steps.html

I added the Ultra sensor to it, and you will notice some of the funtions in the code aren't used at all, because I plan on doing more with this.

If you liked this you might also like
My NXT tagged posts.
My Arduino tagged posts.
or
How to make a contact MIC.


require "rubygems"
require "serialport"
require "nxt_comm"

$DEBUG = false

@nxt = NXTComm.new('/dev/tty.NXT-DevB-1')
def sleeper
sleep(0.5)
end

@nxt = NXTComm.new("/dev/tty.NXT-DevB-1")


def do_motor_a
a = Commands::Motor.new(@nxt)
a.port = :a
a.duration = {:rotations => 0.25}
a.control_power = true
a.start
puts "Run State: #{a.run_state}"
end

def do_motor_b
b = Commands::Motor.new(@nxt)
b.port = :b
b.duration = {:rotations => 0.25}
b.control_power = true
b.start
end

def do_motor_c
c = Commands::Motor.new(@nxt)
c.port = :c
c.duration = {:rotations => 0.25}
c.control_power = true
c.start
puts "Run State: #{c.run_state}"
end

def do_motorb_a
a = Commands::Motor.new(@nxt)
a.port = :a
a.duration = {:rotations => 0.25}
a.control_power = true
a.direction = :backward
a.start
puts "Run State: #{a.run_state}"
end

def do_motorb_b
b = Commands::Motor.new(@nxt)
b.port = :b
b.direction = :backward
b.duration = {:rotations => 0.25}
b.control_power = true
b.start
end

def do_motorb_c
c = Commands::Motor.new(@nxt)
c.port = :c
c.direction = :backward
c.duration = {:rotations => 0.25}
c.control_power = true
c.start
puts "Run State: #{c.run_state}"
end

def inputs_2
s = @nxt.get_input_values(NXTComm::SENSOR_2)
puts s[:value_raw]
if s[:value_raw] > 1005
@nxt.play_tone(659,500)
do_motorb_a
do_motorb_b
sleep 1
do_motor_a
do_motor_b
sleep 1
end
end

def inputs_1
sm = @nxt.get_input_values(NXTComm::SENSOR_1)
puts sm.inspect
sleep 1
end

loop {
inputs_2
}

Tuesday, February 24, 2009

Poor man's obstacle avoiding spike via python and lego nxt mindstorms

Ok so this script is a python script for the nxt brick, and in particular for the spike configuration. What it does is, looks for obstacles in kind of a cheap way. It checks the ultrasonic sensor and if it's less than 255 then it starts to only use one side to move...IE it turns. So it's kind of a pathetic script but I threw it together last night, mainly because I don't see any custom python code on the net for nxt python. There's some code for the tail commented out btw.

Ok so a caveat for mac users, you need to do this to get it to nxt_python to work:
http://www.cs.wlu.edu/~levy/software/nxt_lightblue_glue/

PC users should be fine assuming the appropriate modules are installed.


#!/usr/bin/env python
import time
import nxt.locator
from nxt.motor import *
from nxt.sensor import *
sock = nxt.locator.find_one_brick()
def moveit(brick):
#m_camera = Motor(brick, PORT_A)
#m_camera.power = 100 # 100% power
#m_camera.mode = MODE_MOTOR_ON
#m_camera.run_state = RUN_STATE_RUNNING
#m_camera.tacho_limit = 80
#m_camera.set_output_state()

m_camerc = Motor(brick, PORT_C)
m_camerc.power = 100 # 100% power
m_camerc.mode = MODE_MOTOR_ON
m_camerc.run_state = RUN_STATE_RUNNING
m_camerc.tacho_limit = 1000
m_camerc.set_output_state()

m_camerb = Motor(brick, PORT_B)
m_camerb.power = 100 # 100% power
m_camerb.mode = MODE_MOTOR_ON
m_camerb.run_state = RUN_STATE_RUNNING
m_camerb.tacho_limit = 1000
m_camerb.set_output_state()

def moveitback(brick):
m_camera = Motor(brick, PORT_A)
m_camera.power = -100 # 100% power
m_camera.mode = MODE_MOTOR_ON
m_camera.run_state = RUN_STATE_RUNNING
m_camera.tacho_limit = 80
m_camera.set_output_state()
def moveitleft(brick):
#m_camera = Motor(brick, PORT_A)
#m_camera.power = 100 # 100% power
#m_camera.mode = MODE_MOTOR_ON
#m_camera.run_state = RUN_STATE_RUNNING
#m_camera.tacho_limit = 80
#m_camera.set_output_state()

m_camerc = Motor(brick, PORT_C)
m_camerc.power = 100 # 100% power
m_camerc.mode = MODE_MOTOR_ON
m_camerc.run_state = RUN_STATE_RUNNING
m_camerc.tacho_limit = 1000
m_camerc.set_output_state()
def test_sensors(b):
print 'Touch:',
if TouchSensor(b, PORT_1).get_sample():
print 'yes'
else:
print 'no'
print 'Sound:', SoundSensor(b, PORT_2).get_sample()
print 'Ultrasonic:', UltrasonicSensor(b, PORT_3).get_sample()
sock = nxt.locator.find_one_brick(host='00:16:53:09:F4:4A', name='NXT')
if sock:
b = sock.connect()
terd = 1
while terd<= 30:
objectd = UltrasonicSensor(b, PORT_3).get_sample()
print objectd
if objectd == 255:
print '255'
moveit(b)
time.sleep(1)
else:
moveitleft(b)
time.sleep(1)
sock.close()
else:
print 'No NXT bricks found'

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.

Sunday, February 8, 2009

Lego::NXT this weekend, perl, nerdcore muzak

Ok so I was ill all weekend and could get nearly any of the stuff I wanted to, sorry guys. But I should be able to crank some videos out during the week. Mostly when I wasn't feeling bad I was working on some more nerdcore. I also built the "Spike" chassis for my lego NXT. And got a little more testing done with adding stuff to the perl script, to make spike move along. In the upcoming NXT post I will address, mac connection issues with bluetooth, as well as try to help with connecting a Windows machine via bluetooth. So far the time I have put into the perl NXT stuff has been pretty fruitful. So hopefuly I'll pop out a new post in the week and a video sometime soon.

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();