Hello, I get the NamerError when I try servo control on the Jetson Xavier nx series using pwm. The motor does not turn. nothing happens. The full trace is pasted below. Motor attached to pin 32. The python function is also provided below. How can I resolve this? or what am I doing wrong?
Note: If i comment out the
GPIO.output
The motor turns momentarily, but gives some funny sound and warms up.
The script:
import Jetson.GPIO as GPIO
from time import sleep
# helper function to map angles to PWs
def set_angle(angle, lower_lim, output_pin, pwm):
duty = angle / 18.0 + lower_lim
GPIO.output(output_pin, True)
pwm.ChangeDutyCycle(duty)
# wait 15ms
sleep(0.015)
GPIO.output(output_pin, False)
pwm.ChangeDutyCycle(0)
sleep(0.015)
GPIO.setmode(GPIO.BOARD)
output_pin = 32
# set pin 32 as an output pin
GPIO.setup(output_pin, GPIO.OUT, initial=GPIO.HIGH)
# setting up PWM on pin #32 at 50Hz
pwm = GPIO.PWM(output_pin, 50)
# starting with duty cycle = 0 so no angles are set on startup
pwm.start(0)
lower_lim = 5
set_angle(45, lower_lim, output_pin, pwm)
pwm.stop()
GPIO.cleanup()
The Error trace
Traceback (most recent call last):
File "better_servo_test.py", line 31, in <module>
set_angle(45, lower_lim, output_pin, pwm)
File "better_servo_test.py", line 8, in set_angle
GPIO.output(output_pin, True)
File "/usr/local/lib/python3.6/dist-packages/Jetson.GPIO-2.0.17-py3.6.egg/Jetson/GPIO/gpio.py", line 451, in output
RuntimeError: The GPIO channel has not been set up as an OUTPUT
Exception ignored in: <bound method PWM.__del__ of <Jetson.GPIO.gpio.PWM object at 0x7f9fb65a58>>
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/Jetson.GPIO-2.0.17-py3.6.egg/Jetson/GPIO/gpio.py", line 644, in __del__
File "/usr/local/lib/python3.6/dist-packages/Jetson.GPIO-2.0.17-py3.6.egg/Jetson/GPIO/gpio.py", line 660, in stop
File "/usr/local/lib/python3.6/dist-packages/Jetson.GPIO-2.0.17-py3.6.egg/Jetson/GPIO/gpio.py", line 278, in _disable_pwm
NameError: name 'open' is not defined
I run it both as: sudo python3 better_servo_test.py
also as: python3 better_servo_test.py
My goal is to eventually use this setup to move the motor back and forth between 0 and 180 degrees. 0 maps to 1ms, while 180 degrees maps to 2ms. An alternative solution is also greatly appreciated. Thanks.