我目前正在使用 IMOT233S 电机,我正在尝试通过 CAN OPEN 与它交谈。我刚刚在 Linux 上用我的计算机测试了我的代码并且它工作正常,所以我决定在我的 Raspberry 4 上测试它(因为我的目标是让它在 raspberry pi 上工作)。
但我在 rapsberry pi 4 上收到以下错误:
Traceback (most recent call last):
File "canopen-test.py", line 70, in <module>
print('move home', a.move_absolute())
File "canopen-test.py", line 47, in move_absolute
self.motor_node.sdo[0x2077].raw = function_id
File "/home/camille/.local/lib/python3.8/site-packages/canopen/variable.py", line 88, in raw
self.data = self.od.encode_raw(value)
File "/home/camille/.local/lib/python3.8/site-packages/canopen/variable.py", line 40, in data
self.set_data(data)
File "/home/camille/.local/lib/python3.8/site-packages/canopen/sdo/base.py", line 112, in set_data
self.sdo_node.download(self.od.index, self.od.subindex, data, force_segment)
File "/home/camille/.local/lib/python3.8/site-packages/canopen/sdo/client.py", line 155, in download
fp.close()
File "/home/camille/.local/lib/python3.8/site-packages/canopen/sdo/client.py", line 381, in write
response = self.sdo_client.request_response(request)
File "/home/camille/.local/lib/python3.8/site-packages/canopen/sdo/client.py", line 85, in request_response
return self.read_response()
File "/home/camille/.local/lib/python3.8/site-packages/canopen/sdo/client.py", line 73, in read_response
raise SdoAbortedError(abort_code)
canopen.sdo.exceptions.SdoAbortedError: Code 0x08000020, Data cannot be transferred or stored to the application
所以我认为问题出在 RPI 上,所以我用我的电脑再次尝试,现在我的电脑上出现了同样的错误。
这是我正在执行的代码canopen_test.py
:
import canopen
import time
from canopen import node
import os
from canopen.profiles.p402 import BaseNode402
os.system("sudo ifconfig can0 down")
os.system("sudo ip link set can0 type can bitrate 500000")
os.system("sudo ifconfig can0 up")
class Drive(object):
def __init__(self, object_controlword, object_statusword, function_id, motor_node3):
self.object_controlword = object_controlword
self.object_statusword = object_statusword
self.function_id = function_id
self.motor_node = BaseNode402(motor_node3, '/home/camille/Downloads/iPOS.v1.09.eds')
self.network = canopen.Network()
self.network.connect(channel='can0', bustype='socketcan', bitrate=500000)
self.network.add_node(self.motor_node)
self.motor_node.nmt.state = 'OPERATIONAL'
print('here ici')
def enable(self):
print('hey')
self.motor_node.sdo[object_statusword].raw
print('State of the status word', self.motor_node.sdo[object_controlword].raw)
self.statusword = "{:0>15b}".format(self.motor_node.sdo[object_statusword].read())
print('status word', self.statusword)
# shutdown
self.motor_node.sdo[object_controlword].raw = 0x06
# switch_on
self.motor_node.sdo[object_controlword].raw = 0x07
# enable operation
self.motor_node.sdo[object_controlword].raw = 0x0F
def move_relative(self):
# start TML functions
self.motor_node.sdo[0x2077].raw = function_id
self.motor_node.sdo[0x2006].raw = 0x05
print('here')
def move_absolute(self):
# start TML functions
self.motor_node.sdo[0x2077].raw = function_id
self.motor_node.sdo[0x2006].raw = 0x06
print('here')
def move_home(self):
# start TML functions
self.motor_node.sdo[0x2077].raw = function_id
self.motor_node.sdo[0x2006].raw = 0x01
print('here')
if __name__ == "__main__":
object_controlword = 0x6040
object_statusword = 0x6041
function_id = 0x01
motor_node3 = 3
a = Drive(object_controlword, object_statusword, function_id, motor_node3)
print('here', a)
print('enable', a.enable())
print('move home', a.move_absolute())