Showing posts with label ruby. Show all posts
Showing posts with label ruby. Show all posts

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
}

Monday, April 13, 2009

Watch people as they die...or I love twitter...Ruby RSS tutorial




This is a tutorial to get ruby working with rss...in style. So I decide I wanted to have one of my LCD monitors to constantly scroll people's names as they died...but how would I achieve this feat? Well with a simple script that called several twitter feeds. At first I tried perl but as I was installing one of the modules I had a really HORRIBLE time trying to get it to work. So what I ended up doing is switching to ruby.* So there are three twitter feeds I choose to use...One was just the feed for #obits, I also wanted to use mydeathspace and the LA Times Obituary account. You can accummulate these feeds by going to search.twitter.com then, searching for something, then clickiing the, "I want the feed for this query" or something like that.

This tutorial assumes you have ruby and gems installed.
So the first thing I had to do was install the module...err gem for rss, for ruby, which is simple enough:

gem install simple-rss

Then I wrote this code I ripped off of about:


#!/usr/bin/env ruby
require 'rubygems'
require 'simple-rss'
require 'open-uri'

rss = SimpleRSS.parse(
open('http://search.twitter.com/search.atom?q=%23obit').read
)

rss.items.each do|i|
puts "Title: #{i.title}"
puts "Link: #{i.link}"
puts "=" * 80
end


Obviously I wasn't happy with that, for one I wanted a slow scroll and I wanted multiple feeds and I wanted it to loop so that it would always be outputting. So I added some sleeps and a loop like so:


#!/usr/bin/env ruby
require 'rubygems'
require 'simple-rss'
require 'open-uri'

loop {
rss = SimpleRSS.parse(
open('http://search.twitter.com/search.atom?q=%23obit').read
)

rss.items.each do|i|
puts "Title: #{i.title}"
puts "Link: #{i.link}"
puts "=" * 80
sleep 1
end
sleep 1

rssTwo = SimpleRSS.parse(
open('http://search.twitter.com/search.atom?q=+from%3Amydeathspace').read
)

rssTwo.items.each do|i|
puts "Title: #{i.title}"
puts "Link: #{i.link}"
puts "=" * 80
sleep 1
end
sleep 1

rssThree = SimpleRSS.parse(
open('http://search.twitter.com/search.atom?q=+from%3Alatimesobits').read
)

rssThree.items.each do|i|
puts "Title: #{i.title}"
puts "Link: #{i.link}"
puts "=" * 80
sleep 1
end
sleep 1
}



And there you go, now I have a monitor that basically let's me watch people die.....I am so happy.

*BTW if you are a perl guru and know how I can fix my UserAgent stuff, with a parse_head error, it would be awesomely cool if you could help me out.