def setup(self): try: os.system('sudo ip link set can0 type can bitrate 1000000') os.system('sudo ifconfig can0 up') os.system('sudo ifconfig can0 txqueuelen 1000') # Start with creating a network representing one CAN bus self.network = canopen.Network() # Connect to the CAN bus self.network.connect(bustype='socketcan', channel='can0') self.network.check() # Add some nodes with corresponding Object Dictionaries self.node1 = canopen.BaseNode402(12, '/home/pi/canopen/examples/brunner_eds.eds') self.node2 = canopen.BaseNode402(15, '/home/pi/canopen/examples/brunner_eds.eds') for node in [self.node1, self.node2]: self.network.add_node(node) # Read a variable using SDO node.sdo[0x1006].raw = 1 node.sdo[0x1014].raw = 163 node.sdo[0x1003][0].raw = 0 # Transmit SYNC every 100 ms self.network.sync.start(0.1) for node in [self.node1, self.node2]: node.load_configuration() node.setup_402_state_machine() node.state = 'SWITCH ON DISABLED' node.op_mode = "PROFILED VELOCITY" # Read PDO configuration from node node.tpdo.read() # Re-map TxPDO1 node.tpdo[1].clear() node.tpdo[1].add_variable('Statusword') node.tpdo[1].add_variable('Position actual value') node.tpdo[1].trans_type = 1 node.tpdo[1].event_timer = 0 node.tpdo[1].enabled = True # Save new PDO configuration to node node.tpdo.save() node.rpdo.read() node.state = 'READY TO SWITCH ON' acceleration = 1600 deceleration = acceleration self.node1.sdo[0x6083].raw = acceleration # target acc self.node2.sdo[0x6083].raw = acceleration self.node1.sdo[0x6084].raw = deceleration # target dec self.node2.sdo[0x6084].raw = deceleration self.is_setup = True except Exception as e: self.is_setup = False
def addDs402Node(self, eds_path, node_id, number_of_motors=1): if self._debug: print("Adding network node (id: {0:d}) with {1:d} motors using EDS file: {3:s}".format(node_id, number_of_motors, eds_path)) # Add some nodes with corresponding Object Dictionaries node = canopen.BaseNode402(1, eds_path) self.__network.add_node(node) node.setup_402_state_machine() self.__nodes.append({ "node_id" : node_id, "node" : node, }) return node
6090h: Water level status cia419 : charger 6000h VAR Battery status UNSIGNED8 rw M 6001h VAR Charger status UNSIGNED8 ro M 6010h VAR Temperature INTEGER16 rw M 6052h VAR Ah returned during last charge UNSIGNED16 ro C 6060h VAR Battery voltage UNSIGNED32 rw C 6070h VAR Charge current requested UNSIGNED16 rw C 6080h VAR Charger state of charge UNSIGNED8 ro C 6081h VAR Battery state of charge UNSIGNED8 rw C idx 2000 """ node = canopen.BaseNode402(0x55, 'EDS/CR2016.eds') network.add_node(node) time.sleep(0.1) node.nmt.state = 'RESET COMMUNICATION' node.nmt.wait_for_bootup(15) time.sleep(0.1) node.nmt.state = 'RESET' node.nmt.wait_for_bootup(15) time.sleep(1) def getnodestate(): print("*** Get node State***")
import traceback import time try: # Start with creating a network representing one CAN bus network = canopen.Network() # Connect to the CAN bus network.connect(bustype='kvaser', channel=0, bitrate=1000000) network.check() # Add some nodes with corresponding Object Dictionaries node = canopen.BaseNode402(35, '/home/andre/Code/test/jupiter.eds') network.add_node(node) # network.add_node(34, '/home/andre/Code/test/jupiter.eds') # node = network[34] # Reset network node.nmt.state = 'RESET COMMUNICATION' #node.nmt.state = 'RESET' node.nmt.wait_for_bootup(15) print('node state 1) = {0}'.format(node.nmt.state)) # Iterate over arrays or records error_log = node.sdo[0x1003] for error in error_log.values(): print("Error {0} was found in the log".format(error.raw))
# instantiate the argument parser and parse the arguments ap = argparse.ArgumentParser() ap.add_argument("-d", "--directory", required = True) ap.add_argument("-l", "--labels", required = True) # help = "Path to the image to be scanned") args = vars(ap.parse_args()) # instantiate CAN bus # Start with creating a network representing one CAN bus can = canopen.Network() # Connect to the CAN bus can.connect(bustype='pcan', channel='PCAN_USBBUS1', bitrate=1000000) can.check() # Add some nodes with corresponding Object Dictionaries pd2c = canopen.BaseNode402(3, 'PD2-C4118L1804-E-08.eds') can.add_node(pd2c) # instantiate cv2 and file stuff cur_dir = Path().absolute() # read file telling which directory to save to directoryfile = args["directory"] with open(cur_dir / directoryfile) as file: # Use file to refer to the file object directory = file.read() label_dir = cur_dir / directory # read file telling which labels to use with open(cur_dir / args["labels"]) as file: # Use file to refer to the file object lbls = file.read() try:
import traceback import time try: # Start with creating a network representing one CAN bus network = canopen.Network() # Connect to the CAN bus network.connect(bustype='kvaser', channel=0, bitrate=1000000) network.check() # Add some nodes with corresponding Object Dictionaries node = canopen.BaseNode402(35, 'eds/e35.eds') network.add_node(node) # network.add_node(34, 'eds/example34.eds') # node = network[34] # Reset network node.nmt.state = 'RESET COMMUNICATION' #node.nmt.state = 'RESET' node.nmt.wait_for_bootup(15) print('node state 1) = {0}'.format(node.nmt.state)) # Iterate over arrays or records error_log = node.sdo[0x1003] for error in error_log.values(): print("Error {0} was found in the log".format(error.raw))