pioneers / dawn-v0

(archived; now in PiECentral) Dawn is a cross-platform frontend for the Pioneers in Engineering robotics control system.
https://pioneers.berkeley.edu
4 stars 33 forks source link

Runtime crashes when a non-existent servo is accessed from student code #259

Closed karthik-shanmugam closed 8 years ago

karthik-shanmugam commented 8 years ago

Runtime output:

ubuntu@arm:~$ sudo tail -f /var/log/upstart/runtime.log 
Bad UID
Bad UID
Bad UID
Bad UID
Traceback (most recent call last):
  File "runtime.py", line 548, in <module>
    send_peripheral_data(all_sensor_data)
  File "runtime.py", line 495, in send_peripheral_data
    'peripheralType':h.getDeviceName(uid_to_type[device_id_to_uid(device_id)]),
KeyError: 33072568380790936465924L

Student code in question:

ubuntu@arm:~/daemon/runtime/student_code$ cat student_code.py 
from api.Gamepads import *
from api.Robot import *
import time

while True:
    #Change to correct gamepad_index if necessary
    gamepad_index = 0
    toggle_light("Color",True)

    #Get the joystick values of the left y-axis and right y-axis
    #joystick_1_value = get_axis(gamepad_index, Joystick.LEFT_Y)
    #joystick_2_value = get_axis(gamepad_index, Joystick.RIGHT_Y)
    #brake1 = get_button(gamepad_index,6)
    # brake1 = True
    # if brake1:
    #     set_motor('motor0', 0.1 * joystick_1_value)
    #     set_motor('motor1', 0.1 * -joystick_2_value)
    # else:
    #     #Drives the robot at 75% of its poewr, based off of the joystick values.
    #     set_motor('motor0', 0.75 * joystick_1_value)
    #     set_motor('motor1', 0.75 * -joystick_2_value)

    set_servo('servo1', 150)
    set_servo('servo2', 150)
    set_servo('servo3', 150)
    set_servo('servo4', 150)

    time.sleep(.05)

CustomID.txt

330611632100507683634312 servo2
330611632100507683634313 servo3
330725683807909364659243 servo2
330611632100507683634311 servo1
330725683807909364659244 servo4
330611632100507683634314 servo4
47341093878369530906031 sensor1
47341093878369530906033 sensor3
47341093878369530906032 sensors2
330725683807909364659242 servo3
motor1 motor1
425101652065656939816901 Color
motor0 motor0
330725683807909364659241 servo1
karthik-shanmugam commented 8 years ago

BTW, it turns out this issue wasn't on develop branch, it was on testbranch

matthew-zhao commented 8 years ago

Sorry, is this still an issue that should be fixed?

nikitakit commented 8 years ago

Yes, to the best of my knowledge

nikitakit commented 8 years ago

Despite best attempts, this bug is not fixed yet.

If the student code uses a servo name not in the naming map, runtime crashes. This is because if the name is not found in the naming map, the lookup function returns the identity (this works well for motors and sensors, but apparently not servos).

To reproduce:

set_servo('thisnamedoesnotexist', 110)
Traceback (most recent call last):
  File "runtime.py", line 619, in <module>
    set_servos(servo_values)
  File "runtime.py", line 248, in set_servos
    h.writeValue(device_id_to_uid(device_id),
  File "runtime.py", line 94, in device_id_to_uid
    return int(device_id[:-1])
ValueError: invalid literal for int() with base 10: 'servo'
AllanYangZhou commented 8 years ago

Closing since runtime is now in its own separate repo (atalanta)