rcruzoliver_0-1702039156419.png

Controlling a CANopen motor using ctrlX CORE X3 and ZK-USB-CAN-1 from Nanotec

rcruzoliver
Established Member

The example described in this how-to is available in the attached .zip. There you will find a detailed README with everything you need to set up this project by your own. You will also find general indications about how to develop a C++ application for ctrlX CORE, as well as, a simplified tutorial about Snapcraft and how it is applied to this specific project.

1. System overview

The connection topology can be seen in the following picture. The serial port of the ctrlX X3 is connected to the Nanotec adapter with a USB-C->USB-B cable. The motor+driver is then connected to the adapter using the wiring convention for CANopen. Although it is not represented in the picture, the motor+driver is powered at 24V.

System overviewSystem overview

Documentation about the adapter and the CANopen protocol (CiA 402) can be found in the folder "documentation/" in the .zip. PD2C_CANopen_Techschisches-Handbuch_v3.3.0 is the documentation related with the motor and ZK-USB-CAN-1_Betriebsanleitung_V1.0.0..pdf is the corresponding with the adapter. 

2. Easy Start-up 

This example is designed for Ubuntu Jammy Jellyfish 22.04 x86_64 Desktop. The "cmake" process that would be used has been designed for a Linux machine, and moreover Snapcraft is a technology from Canonical (the developers of Ubuntu). If you want to develop apps for the ctrlX ecosystem, you must mandatory work in a Ubuntu 22.04 OS, no matter if it is a virtual machine or a native installation.

2.1 Install the necessary tools in your system

Since you are (most likely) developing in a amd64, but your target device (the ctrlX CORE X3) has architecture arm64, you will need to install the necessary system libraries for cross-compilation. The specific libraries from ctrlX and Nanotec have been included in this project for both architectures. 

See more details in the .zip.

2.2 Build the source code

You will find batch files in the .zip that automate this process for you. 

2.3 Pack in a snap

You will find a batch file in the .zip that automate this process for you. 
Once you have the snap, you can install it on your ctrlX CORE X3. 

3. API in the datalayer

If the hardware is available the app should be successfully initialized and a new node called "ctrlx_nanotec" should appear in the data layer.

Inside this node one can find the following:

  • cmd/ : this branch includes all the parameters that can be edited by the user
  • state/: this branch includes all the parameters that are read only.

Inside cmd/ one can find:

  • cmd/mode_id: it controls the operation mode of the motor. "0" means stop mode, "1" means relative positioning mode, "2" means velocity mode. It is initialized with "0". To go from relative positioning mode to velocity mode you must go first to stop mode (1->0->2). Similarly from velocity to positioning mode.
  • cmd/position_mode/pos_cmd: when in relative positioning mode (mode_id = 1) angle in degrees that you want to turn the motor. There are to decimal positions in the value, i.e. 135.65º should be entered as 13565.
  • cmd/velocity_mode/vel_cmd: when in velocity mode (mode_id = 2) rotation velocity in rpm you want the motor to spin. There are to decimal positions in the value, i.e. 15.35 rpm should be entered as 1535.

Inside state/ one can find:

  • state/driver: it contains the status (address 0x6041) and control word (address 0x6040) from the CANopen protocol. They are represented in integers, to better understand them convert it to binary.
  • state/current_values/position: it contains the current position of the motor in degrees. There are two decimal positions in the value, i.e. 13565 corresponds to 135.65º.
  • state/current_values/velocity: it contains the current position of the motor in rpm.There are two decimal positions in the value, i.e. 1535 corresponds to 15.35 rpm.
  • state/target_values/position: it contains the internal target position of the motor in degrees, the one the driver solver computes to follow the defined movement profile. There are two decimal positions in the value, i.e. 13565 corresponds to 135.65º.
  • state/target_values/velocity: it contains the target position of the motor in rpm, the one the driver solver computes to follow the defined movement profile. There are to decimal positions in the value, i.e. 1535 corresponds to 15.35 rpm.
rcruzoliver
rcruzoliver
Enhancing ctrlX platform with solutions. Everything can be snapcrafted! Robotics specialist, ask me anything about ROS2 and ctrlX OS.
Must Read
Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist