Lojic Technologies

Archive for the ‘technology’ Category

Precision Quadrotor Flying

leave a comment »

Wow – pretty amazing! HT Michael Hale via RT 🙂

Written by Brian Adkins

May 28, 2010 at 11:09 am

Posted in amazing, robotics, science, technology, video

Tagged with ,

Daniel Weinreb re: Lisp use at ITA

with one comment

Some random notes:

  • 650 KLOC plus 150 KLOC of open source code
  • 100 people on the team, 70 programmers
  • SBCL for the QPX product
  • Clozure CL for the reservations product
  • Availability requirement: four 9’s => less than 53 minutes downtime per year
  • Latency agreement

    • 90% of requests w/in 300 ms
    • 5% of requests w/in 600 ms
    • 5% of requests w/in 1,200 ms
  • Java presentation layer, Common Lisp stateless business layer, Oracle data layer
  • Daniel is very positive about Clojure
  • Some links from the talk:

Written by Brian Adkins

August 29, 2009 at 1:31 pm

Posted in business, programming, technology, video

Tagged with

Use Ruby to parse NMEA sentences from your GPS

with one comment

I recently obtained a mobile broadband device that has a built in GPS receiver and can emit NMEA sentences. My old Garmin portable GPS can emit NMEA also, but it’s a pain to hookup to the laptop. Combining a GPS unit in a mobile broadband device is a great idea.

Update: it appears that the accuracy radius of the wireless card is quite a bit larger than my old Garmin unit. The Garmin is usually between 15 and 30 feet, but the Sierra Wireless 598U ranges from 100 to 1,000 feet or more.

After installing the ruby-serialport gem, I was able to write a simple Ruby program to read GPS information from the device and update a remote file on my web server to allow real time location tracking.

Add a simple server side script to read the file and update an iframed Google Map and you’re all set.

The code is also in the Ruby section of my sample code repository on Github.

sudo gem install ruby-serialport
#!/usr/local/bin/ruby
# Author: Brian Adkins
# Date:   2009/04/08
# Copyright 2009 Brian Adkins - All Rights Reserved
#
# Ruby program to retrieve and parse GPS information (via NMEA sentences)
# from a Sprint Sierra Wireless 598U device.
#
# ruby gps-nmea.rb                # prints latititude/longitude info
# ruby gps-nmea.rb update-remote  # scp a file of location info to a remote server
#
# This program depends on the ruby-serialport gem:
# sudo gem install ruby-serialport
#
# From: http://www.gpsinformation.org/dale/nmea.htm#GGA
#  $GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47
# Where:
#      GGA          Global Positioning System Fix Data
#      123519       Fix taken at 12:35:19 UTC
#      4807.038,N   Latitude 48 deg 07.038' N
#      01131.000,E  Longitude 11 deg 31.000' E
#      1            Fix quality: 0 = invalid
#                                1 = GPS fix (SPS)
#                                2 = DGPS fix
#                                3 = PPS fix
#              4 = Real Time Kinematic
#              5 = Float RTK
#                                6 = estimated (dead reckoning) (2.3 feature)
#              7 = Manual input mode
#              8 = Simulation mode
#      08           Number of satellites being tracked
#      0.9          Horizontal dilution of position
#      545.4,M      Altitude, Meters, above mean sea level
#      46.9,M       Height of geoid (mean sea level) above WGS84
#                       ellipsoid
#      (empty field) time in seconds since last DGPS update
#      (empty field) DGPS station ID number
#      *47          the checksum data, always begins with *

require 'rubygems'
require 'serialport'

# Emacs macro to reset user modified values (highlight, then: M-x eval-region )
# ((lambda (&optional arg) "Keyboard macro." (interactive "p") (kmacro-exec-ring-item (quote ("USERNAME
"
372"HOSTNAME
"
372"REMOTE_DIR
"
372"" 0 "%d")) arg)))

# --- MODIFY THESE -- #
USERNAME   = ""  # Username for remote host
HOSTNAME   = ""  # Remote host name e.g. foo.com
REMOTE_DIR = ""  # Remote directory e.g. /var/www/bar
# --- MODIFY THESE -- #

port_str  = '/dev/cu.sierra05'
baud_rate = 9600
data_bits = 8
stop_bits = 1
parity    = SerialPort::NONE

sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)

# lat is of the form 4807.038 where the first 2 digits are degrees and
#   the remainder is minutes.
# dir is either 'N' or 'S'
def convert_lat lat, dir
  degrees = lat[0,2].to_f + (lat[2,lat.length-2].to_f / 60.0)
  dir == 'N' ? degrees : -degrees
end

# lon is of the form 01131.000 where the first 3 digits are degrees and
#   the remainder is minutes.
# dir is either 'E', or 'W'
def convert_lon lon, dir
  degrees = lon[0,3].to_f + (lon[3,lon.length-2].to_f / 60.0)
  dir == 'E' ? degrees : -degrees
end

TEMP_PATH = '/tmp'
TEMP_FILE = 'location.txt'

def update_remote_info lat, lon
  File.open("#{TEMP_PATH}/#{TEMP_FILE}", 'w') do |tf|
    tf.puts Time.now.to_s
    tf.puts "#{lat},#{lon}"
  end
  puts 'Updating remote location info'
  `scp #{TEMP_PATH}/#{TEMP_FILE} #{USERNAME}@#{HOSTNAME}:#{REMOTE_DIR}/#{TEMP_FILE}`
  File.delete("#{TEMP_PATH}/#{TEMP_FILE}")
end

# 99 requests should be sufficient to find a $GPGGA sentence
99.times do
  if (str = sp.gets) =~ /^$GPGGA/
    fix = str.split(',')
    if fix[6] == '1'
      lat = convert_lat(fix[2], fix[3])
      lon = convert_lon(fix[4], fix[5])
      if ARGV[0] == 'update-remote'
        update_remote_info(lat,lon)
      elsif
        puts "#{lat}, #{lon}"
      end
      exit 0
    end
  end
end

puts "Invalid data - GPS coordinates not found"

Written by Brian Adkins

April 8, 2009 at 11:07 am

Posted in programming, technology

Tagged with , , ,

Retrieve Sunrise, Sunset & Twilight Info in Ruby

with 5 comments

Sunrise, Sunset & Twilight

TwilightI was curious about the exact time of sunrise & sunset at my location, so I found this US Naval Observatory site. In the process, I learned a more precise definition of twilight. I wanted to be able to automate the process of retrieving the information, so my first attempt was to simply put the query parameters used in the form in the URL as an HTTP GET request, but the server wouldn’t accept that, so I needed to issue an HTTP POST request.

Ruby Code

Ruby is a great language for this sort of task, so I put together the following simple program:

require 'net/http'

YOUR_ID    = ''    # A unique ID per comment above
YOUR_CITY  = ''    # The name of your city
YOUR_STATE = ''    # Two letter state abbreviation

now   = Time.now
month = now.month
day   = now.day + 1 # Tomorrow
year  = now.year

Net::HTTP.start('aa.usno.navy.mil') do |query|
  response = query.post('/cgi-bin/aa_pap.pl',
    "FFX=1&ID=#{YOUR_ID}&xxy=#{year}&xxm=#{month}&xxd=#{day}&st=#{YOUR_STATE}&place=#{YOUR_CITY}&ZZZ=END")
  if response.body =~ /Begin civil twilight[^0-9]*(d+:d{2} [ap].m.).*Sunrise[^0-9]*(d+:d{2} [ap].m.).*Sunset[^0-9]*(d+:d{2} [ap].m.).*End civil twilight[^0-9]*(d+:d{2} [ap].m.)/m
    puts "#{month}/#{day}/#{year}"
    puts "Begin Twilight: #{$1}"
    puts "Sunrise       : #{$2}"
    puts "Sunset        : #{$3}"
    puts "End Twilight  : #{$4}"
  end
end

You just need to edit the three constants that begin with YOUR_. The id used on the Navy web form is ‘AA’, but they have a comment in the HTML that requests you use a unique id of your own up to 8 characters to help them with tracking. You can find a more complete version of the code in my github profile.

Emacs Goodness

After writing the above Ruby script, I made it executable, ‘chmod +x sunrise.rb’, and placed it in my path so I could write a simple Emacs function to invoke it.

(defun bja-sunrise ()
  "Display sunrise, sunset & twilight information."
  (interactive)
  (shell-command "sunrise.rb"))

Imagine my surprise when I invoked the Emacs apropos help ‘C-h a’ to see my newly defined function and discovered that Emacs, naturally, already has several commands to display sunrise/sunset information!

calendar-mouse-sunrise/sunset
Show sunrise/sunset times for mouse-selected date.
calendar-sunrise-sunset
Local time of sunrise and sunset for date under cursor.
sunrise-sunset
Local time of sunrise and sunset for today. Accurate to a few seconds.

It doesn’t, however, display twilight information, so my simple function still has a purpose in life. Emacs is awesome 🙂

Written by Brian Adkins

March 11, 2009 at 12:41 am

Big Dog Robot

leave a comment »

Very impressive balance and mobility. A robot from Boston Dynamics.

Written by Brian Adkins

March 20, 2008 at 4:45 pm

Posted in amazing, technology, video

Tagged with

Beware of LEGO Mindstorms NXT on Mac OSX

with 10 comments

I recently installed the software that came with a LEGO Mindstorms NXT kit onto a Mac Mini running OSX 10.4. I was somewhat concerned when the install program prompted me for an admin password, so I attempted to install the software into a directory in my home directory instead of the main Applications directory, but it still prompted for an admin password. Since LEGO is a large reputable company, I gave them the benefit of the doubt and figured the admin password may have been necessary to install Bluetooth drivers or some other feature. I should’ve learned a lesson from the Sony root kit debacle with respect to blindly trusting large corporations. In the Sony case, maliciousness was involved, in the LEGO Mindstorms case, I think only incompetence is to blame.

After installing the LEGO Mindstorms NXT software, I noticed that the OSX Activity Monitor failed to start which was puzzling. I also noticed that my Missing Sync program (used to synchronize data on my Treo 650 with the Mac) was failing as well – probably related to Bluetooth misconfiguration. I discovered later that, independently of the software issue, the LEGO Mindstorms NXT kit was malfunctioning (some attachments worked, but the motors couldn’t be activated), so we sent it back for an exchange.

I thought that uninstalling the LEGO Mindstorms NXT software might return my Mac OSX system to normal, so I found the uninstall shell script in the Applications directory. With many OSX applications, it’s sufficient to simply delete the directory associated with the particular application from the Applications directory, but since Bluetooth drivers (and possibly other stuff) was installed, I figured the uninstall script would remove anything that was installed. I viewed the contents of the script briefly, but I was in a particular hurry at the time, so I double-clicked the icon for the uninstall script before I thoroughly reviewed it. It took longer to execute than I expected, and to my great dismay I shortly discovered why.

The LEGO Mindstorms NXT uninstall script removed the entire Applications directory from my Mac OSX system!

I’ve contacted technical support at LEGO Mindstorms mainly to try and determine how this happened. One of the reps did admit that this has happened before. I’m not sure what they could do to resolve this to my satisfaction other than pay me for the time I’ve lost in trying to get the Mac back to normal. I’ve been able to get the bundled applications reinstalled with some effort, but I still have a fair amount of work to do to reinstall many open source apps.

If LEGO Mindstorms comes up with a creative solution to resolve this to my satisfaction, I’ll be elated to post an update, but I expect that to be unlikely to say the least. Hopefully this blog post can save at least one person from losing an entire day to a similar problem.

When the replacement LEGO Mindstorms NXT kit arrives I’m either going to install the software on an old Windows PC, or create a new virtual machine for that purpose, but I don’t think I can trust LEGO Mindstorms enough to install it on an important computer at this point. Regardless, I’m going to be much more careful (paranoid?) when installing software that requires root access in the future.

Update 1/18/2008: It’s been ten days since I originally called LEGO Mindstorms NXT technical support, and I haven’t received a call from a supervisor or level 2 person as was promised. I just called them again and talked to the same person who opened the ticket originally. He still refuses to allow me to talk with his supervisor (actually, he states he doesn’t have a supervisor, and that level 2 is his “supervisor”) and simply repeats the same mantra about how my issue has “been escalated several levels”. I can’t recall a tech support experience that has been quite this bad.

Update 1/18/2008 13:00: I just received the following email response a few minutes ago (probably because I communicated the situation to LEGO corporate headquarters).

Hello,

Your issue has been escalated to the developers in Denmark.
They will get back to you, but we have no control over when that will happen.

In the meantime the only solutions we can offer to you are to repair user permissions and to do an archive reinstall of your Operating System.

Update 1/24/2008 14:10: Just spoke with David C. from LEGO Mindstorms NXT QA (he was referred to me by a LEGO consumer specialist I had spoken to a couple days ago), and he explained the situation to me. This was a known issue (deleting all your apps on Mac OSX) that has apparently been fixed in the current release of the software. He apologized and will send me a free LEGO Mindstorms NXT kit. It doesn’t match the monetary loss in time, but it’s a nice gesture and I appreciate it. I expect it’s more than many companies would do to remedy the situation.

As to the communication issues with the first line technical support, out of respect for David I won’t go into detail, but suffice it to say that they are aware of issues with their front line support and are endeavoring to correct them.

Written by Brian Adkins

January 8, 2008 at 6:19 pm

Posted in programming, technology

Tagged with , ,

Bug Labs

leave a comment »

This is one of the coolest ideas I’ve seen in a while. Bug Labs is developing some technology that should be very interesting to any geek. Another great find by Robert Scoble. The video quality isn’t high because they were recorded on his cell phone, but I’m glad he had a video capable cell phone with him when he bumped into Peter.

Part One
Part Two
Part Three

bug_lab.gif

Written by Brian Adkins

December 1, 2007 at 1:16 pm

Posted in technology, video

Tagged with ,