Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Errors #15

Open
AndyLindsay opened this issue Jan 31, 2019 · 2 comments
Open

Memory Errors #15

AndyLindsay opened this issue Jan 31, 2019 · 2 comments
Labels
ready for testing draft code complete, needs to be verified by additional team members

Comments

@AndyLindsay
Copy link
Collaborator

Library modules through 0.3.4 do not leave enough room to add subsystems to existing apps. For example, adding frequency_out to the IR remote example below causes a memory error, as does adding breadboard LED control to Roaming with Whiskers (also below).

  1. Use Mu and parallax.py module
  2. Remove the # from bot(22).frequency_out... and flash.
  3. Click REPL and then press CTRL+D to enter restart with serial debugging.
  4. REPL displays "Traceback (most recent call last): File "main", line 6 (or 3), in MemoryError:"
# IR_Remote_Control_Expanded.py

from parallax import *

# Adding this made the code too large.
# bot(22).frequency_out(300, 2000)

while True:
    num = bot(2).tv_remote()
    # Forward on button press 1
    if num == 1:
        bot(18).servo_speed(0)
        bot(19).servo_speed(-75)
        display.show(Image.ARROW_SE)
    elif num == 2:
        bot(18).servo_speed(75)
        bot(19).servo_speed(-75)
        display.show(Image.ARROW_S)
    elif num == 3:
        bot(18).servo_speed(75)
        bot(19).servo_speed(0)
        display.show(Image.ARROW_SW)
    elif num == 4:
        bot(18).servo_speed(-75)
        bot(19).servo_speed(-75)
        display.show(Image.ARROW_E)
    elif num == 5:
        bot(18).servo_speed(0)
        bot(19).servo_speed(0)
        display.show(Image.HAPPY)
    elif num == 6:
        bot(18).servo_speed(75)
        bot(19).servo_speed(75)
        display.show(Image.ARROW_W)
    elif num == 7:
        bot(18).servo_speed(0)
        bot(19).servo_speed(75)
        display.show(Image.ARROW_NE)
    elif num == 8:
        bot(18).servo_speed(-75)
        bot(19).servo_speed(75)
        display.show(Image.ARROW_N)
    elif num == 9:
        bot(18).servo_speed(-75)
        bot(19).servo_speed(0)
        display.show(Image.ARROW_NW)

# Whiskers_Roam_Expanded.py

from parallax import *

bot(22).frequency_out(300, 2000)

while True:
    left = bot(7).digital_read()
    right = bot(9).digital_read()

    if left == 1 and right == 1: #Go forward
        bot(18).servo_speed(75)
        bot(19).servo_speed(-75)
        display.show(Image.ARROW_S)
        bot(15).write_digital(0)
        bot(0).write_digital(0)
    elif left == 1 and right == 0: #Obstacle on right
        bot(18).servo_speed(-75)    #back up for 1s, turn left
        bot(19).servo_speed(75)
        display.show(Image.ARROW_N)
        bot(15).write_digital(0)
        bot(0).write_digital(1)
        sleep(1000)
        bot(18).servo_speed(-75)
        bot(19).servo_speed(-75)
        display.show(Image.ARROW_E)
        sleep(600)
    elif left == 0 and right ==1:  #Obstacle on left
        bot(18).servo_speed(-75)    #backup for 1s, turn right
        bot(19).servo_speed(75)
        display.show(Image.ARROW_N)
        bot(15).write_digital(1)
        bot(0).write_digital(0)
        sleep(1000)
        bot(18).servo_speed(75)
        bot(19).servo_speed(75)
        display.show(Image.ARROW_W)
        sleep(600)
    elif left == 0 and right == 0: #Obstacle on left + right
        bot(18).servo_speed(-75)    #backup for 1s, turn
        bot(19).servo_speed(75)
        display.show(Image.ARROW_N)
        bot(15).write_digital(1)
        bot(0).write_digital(1)
        sleep(1000)
        bot(18).servo_speed(75)
        bot(19).servo_speed(75)
        display.show(Image.ARROW_W)
        sleep(1000)

@AndyLindsay
Copy link
Collaborator Author

Addressed in cyberbot-0.3.7. See branch and zipped code.

@AndyLindsay AndyLindsay added the ready for testing draft code complete, needs to be verified by additional team members label Jan 31, 2019
@AndyLindsay
Copy link
Collaborator Author

AndyLindsay commented Jan 31, 2019

The difference appears to be significant. I was able to add 23 frequency_out calls to IR_Remote_Control_Expanded.py. Also, the max number of maneuvers in Navitate_Routine_Long.py increased from 35 to 95. (Correction: 37 to 95.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for testing draft code complete, needs to be verified by additional team members
Projects
None yet
Development

No branches or pull requests

1 participant