Having fun with Robosapien
It has been fun, fun, fun to play with Robosapien. WowWee RS Media is quite an impressive humanoid robot for a toy, and there has been a community around it. Now with the Java SDK first available at JavaOne (Note: It's an evaluation/beta copy has certain limitation.), you can program an MIDlet to control it.
If you have been to James' The Toy Show keynote or come to the booth at JavaOne, you may have seen it danced, it also made appearance on a few medias. Two clips are on YouTube as well.
And, Bernard, may I call you Mr. Roboto from now on? :-)
Anyway, I would like to see more dances in Java code, so here I would like to offer some help. If you have ever created a personality dance or compose some movement with WowWee's PC Editing Suite, the following Ruby script would help you convert it into a set of Java function calls. Although the generated code is not a complete program, but you will be able to embed it into your class pretty easy.
Talk about Ruby, you have to check out the NetBeans 6 with Ruby support, it's fantastic, and the script works well in JRuby as expected.
#! /usr/bin/ruby
$move_number = nil
$rxp_number = Regexp.new('movement group .*:(\d+)')
$rxp_motor = Regexp.new('/usr/bin/robot/scripts/MotorRel.sh ([[:xdigit:]]+) ([[:xdigit:]]+) ([[:xdigit:]]+)')
$rxp_wait = Regexp.new('/usr/bin/robot/scripts/wait_rtn.sh *(\d*)')
$rxp_delay = Regexp.new('/usr/bin/robot/scripts/time_delay.sh (\d+)')
$dance_body = "\nprotected void doDance(Humanoid robot) {\n"
$dance_body += " this.robot = robot;\n"
$servo_name = %w{ HEAD_UP_DN_SERVO HEAD_LR_SERVO SHOULDER_LEFT_SERVO SHOULDER_RIGHT_SERVO ARM_LEFT_SERVO ARM_RIGHT_SERVO
WAIST_UP_DN_SERVO WAIST_LR_SERVO WAIST_SLR_SERVO LEFT_LEG_SERVO RIGHT_LEG_SERVO HEAD_UPPER_BODY }
$servo_multiplier = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1 ]
def convert(l, f)
case l
when $rxp_number
f << "}\n" unless nil == $move_number
$move_number = $1.to_i
f << "\nprivate void move#{$move_number}() {\n"
$dance_body += " move#{$move_number}();\n";
return false
when $rxp_motor
motor_no = $1.to_i(16) - 1
pos = $2.to_i(16) / $servo_multiplier[motor_no]
speed = $3.to_i(16)
s = " robot.#{$servo_name[motor_no]}.moveToPosition(#{pos}, #{speed});\n"
when $rxp_wait
if $1 == "" then
s = " robot.waitUntilStop();\n"
else
s = " robot.waitUntilStop(#{$1.to_i});\n"
end
when $rxp_delay
s = " try {\n"
s += " Thread.sleep(#{$1.to_i});\n"
s += " } catch (InterruptedException ex) {\n"
s += " }\n"
else
return
end
if nil == $move_number
$dance_body += s
else
f << s
end
false
end
if ARGV.length != 2
puts "Usage: bcn2java <bcn filename> <java filename>"
end
java = File.open(ARGV[1], "w")
File.open(ARGV[0], "r") { |f|
f.each_line { |l|
convert(l, java)
}
}
java << "}\n" unless nil == $move_number
$dance_body += " this.robot = null;\n"
$dance_body += "}\n"
java << $dance_body
java.close