Need help with basic code

1 view
Skip to first unread message

Bob B

unread,
Sep 22, 2009, 2:06:19 AM9/22/09
to Ruby Arduino Development
Hi everyone, I am just getting started with RAD and I'm coming across
a problem I can't seem to figure out... I am sure it's because I am
misunderstanding something! :)

I have the basic flying_robot_blimpduino sketch loaded on my
blimpduino.

I figured make a throttle test - spin a motor up to speed and then
down in one direction (forward) and then the other (reverse) would be
a good first pass... My code is below. But when it loads I get this
error and the right motor spins at fill speed. Not sure how I should
be doing this...

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x3800
0x6f != 0x0c
avrdude: verification error; content mismatch

avrdude: safemode: Fuses OK

avrdude done. Thank you.

make: *** [upload] Error 1
rake aborted!
Command failed with status (2): [cd /Users/rburbach/rad/
flying_robot_blimpd...]


(The code works fine if I have only one of the blocks of code in
throttle test that call run_motor. With both blocks of code (two calls
to run motor) then the error happens...

Thanks!
Bob

# 1 is increasing, 0 is decreasing
@motor_speed_direction = "1, byte"

def throttle_test
serial_println "Starting Throttle Test"

serial_println "Left Motor Forward"
@left_direction = @forward
speed = 10
motor = 1
@motor_speed_direction = 1
run_motor(motor, speed)

serial_println "Left Motor Reverse"
@left_direction = @reverse
speed = 10
motor = 1
@motor_speed_direction = 1
run_motor(motor, speed)

serial_println "Throttle Test Ended"
end

def run_motor(mtr, spd)
motor = mtr
speed = spd
while speed != 0 do
if motor == 1
@left_motor_speed = speed
end
activate_thrusters
delay(100)
if @motor_speed_direction == 1
speed = speed + 2
elsif @motor_speed_direction == 0
speed = speed - 2
end
if speed == 80
@motor_speed_direction = 0
end
serial_println speed
end
end

Ron Evans

unread,
Oct 4, 2009, 7:01:07 PM10/4/09
to ruby-arduino...@googlegroups.com
Well, two things: you probably want to define your variables using the
RAD syntax like this:

@left_direction = "1, byte"
@right_direction = "1, byte"
@left_motor_speed = "0, long"
@right_motor_speed = "0, long"


However, in general, what you are doing with flying_robot would be
best implemented as an autopilot routine. Here is a tiny example of
how to modify the flying_robot_blimpduino sketch to do what it looks
like you wanted from your test routine:

First modify the autopilot method as follows:

def autopilot
if current_command_autopilot == '0'
# autopilot cancel, so we should shutoff motors
throttle_speed = 0
set_thrusters
serial_println "Autopilot Is Off"
end

if current_command_autopilot == '1'
# follow motor pattern
autopilot_on
serial_println "Autopilot 1 On"
end
end

Next, modify the handle_autopilot_update method like this:

def handle_autopilot_update
if is_autopilot_on && millis() - @last_autopilot_update >
@autopilot_update_frequency
if current_command_autopilot == '1'
navigate_using_motor_pattern
end
@last_autopilot_update = millis()
end
end

Last, add a method called navigate_using_motor_pattern like this:

def navigate_using_motor_pattern
if @left_direction == @forward
@left_motor_speed = @left_motor_speed + 2
if @left_motor_speed > MAX_SPEED / AUTOPILOT_THRUST_FACTOR
@left_direction = @reverse
@left_motor_speed = 0
end
end

if @left_direction == @reverse
@left_motor_speed = @left_motor_speed + 2
if @left_motor_speed > MAX_SPEED / AUTOPILOT_THRUST_FACTOR
@left_direction = @forward
@left_motor_speed = 0
end
end

activate_thrusters
end

Hopefully you find this example helpful. Please let me know if can be
of further assistance.

Regards,
Ron
--
Ron Evans
310-597-1013
ron....@gmail.com
Reply all
Reply to author
Forward
0 new messages