Package: rdrive
Python-APIThis folder containsPython 3wrapper for theClibrary.
Implementation is based on thectypesmodule.PrerequisitesOperating systems (OS): Linux, macOS, Windows.Python 3.5 or a later version.To install Python, proceed as below, depending on your OS:Windows: Navigate toPython. Download and complete the setup process.Important!At the installation setup screen, make sure to checkAdd Python v.Х to PATH(wherev.Х.is the downloaded Python version).Linux: To install Python and a corresponing pip package, run one of the following commands in the console.
In case you have a Linux distribution other than specified below, proceed in the usual order of running the installation pocedure in your system.Ubuntu/Debian: Run the commandsudo apt install python3 python3-pip.Fedora starting from version 22: Run the commandsudo dnf install python3 python3-pip.RedHat and Fedora before version 22: Run the commandsudo yum install python3 python3-pip.pip 3packageImportant!The Python installation package for Windows already contains apippackage. For Ubuntu/Debian and other Linux systems, see Step 2 above.On MacOS and Linux, make sure to install thegcccompiler andmake.Installation Windows OSNote:If your PC runs Windows 8 or earlier versions of the operating system, download and install a driver for the CAN-USB dongle from theweb page.To install the API library on a PC running under Windows OS, run the pip install command as described below:To get the latest version, use the following command:pip install rdrive -i https://pip.rozum.com/simpleTo install a specific version:pip install rdrive==v1.v2.v3 -i https://pip.rozum.com/simplewherev1,v2, andv3(e.g., rdrive==1.0.31) are version numbers.Now, the API library for Windows is installed, and you can proceed to working with the cmd console (for further steps, refer toGetting started Windows OS).Installation LinuxTo install the API library on a PC running under Linux OS, run the pip install command as described below:To get the latest version, use the following command:pip3 install rdrive -i https://pip.rozum.com/simpleTo install a specific version:pip3 install rdrive==v1.v2.v3 -i https://pip.rozum.com/simplewherev1,v2, andv3(e.g., rdrive==1.0.31) are version numbers.Getting started Windows OSTo run any of the program examples with Python code on Windows OS, complete the steps below.Note:Before running a tutorial, RDrive servo should be wired to a power supply and the CAN-USB dongle.
as described in the User Manual or the Quick-Start Guide available for downloading at the [company website] (https://rozum.com/servomotors/#rdrive-documentation).Open the Command Line Interface via the Start menu.Find out theCANinterface name. To do this, complete the following steps:Open the startMenu-System Settings-Devices-Bluetooth and other devices.On theOther deviceslist find a serial USB device with a COM port. The COM port number is the CAN ID interface you need—e.g.,COM3.Find out theCAN ID of the connected servo motor. To do this, complete the following steps:In the command console, run a tutorial from theexamplesfolder by executing the following command with a specified CAN Interface ID and CAN Servo ID.Note:To run the examples you should clone the repository on your local machine.python userapi\python\examples\read_servo_max_velocity.py --interface COM3 --servo_1_id 32whereread_servo_max_velocity.pyis the tutorial name;interface COM3is the parameter specifying the CAN Interface ID;servo_1_id 37is the parameter specifying an arbitrary CAN ID for the connected servo.In the command output, go to the INFO lines (see the example below). Look for IDs within the range between 32 to 37 — default servo IDs (37 in the example below).Example:INFO:	ID: 50 Device is in operational modeINFO:	ID: 37 Device is in pre-operational modeNow, you can run any of the tutorials from theexamplesfolder to move your RDrive servo or read parameters from it.To do this, run the following command in the cmd console:python userapi\python\examples\read_servo_max_velocity.py --interface COM3 --servo_1_id 37whereread_servo_max_velocity.pyis the tutorial name (replace the name from the current example with any other tutorial name as needed);interface COM3is the parameter specifying the CAN Interface ID (the one we got at Step 2);servo_1_id 37is the parameter specifying an arbitrary CAN ID for the connected servo (the one we got at Step 3).If the command is successfully executed, the connected servo will behave as commanded—return parameters or move.Note:Some of the tutorials may require specifing some other parameters in addition to the CAN Interface ID and a CAN Servo ID.Getting started Linux OSTo run any of the program examples with Python code on Linux OS, complete the steps below.Find out theCANinterface name. To do this, open the console and type in the following command:ls /dev/serial/by-id/.In the output, look for something like:usb-Rozum_Robotics_USB-CAN_Interface_301-if00. It is the CAN interface name you need.Note:On MacOS, you can find out the CAN Interface name by executing thels /dev/ | grep cu.usbcommand in the console. The output will contain something like:/dev/cu.usbmodem301Find out theCAN ID of the connected servo motor. To do this, complete the following steps:In the console, run a tutorial from theexamplesfolder by executing the following command with a specified CAN Interface ID and a CAN Servo ID.Note:To run the examples you should clone the repository on your local machine.python3 userapi/python/examples/read_servo_max_velocity.py --interface /dev/serial/by-id/usb-Rozum_Robotics_USB-CAN_Interface_301-if00 --servo_1_id 32whereread_servo_max_velocity.pyis the tutorial name;interface /dev/serial/by-id/usb-Rozum_Robotics_USB-CAN_Interface_301-if00is the parameter specifying the CAN Interface ID;servo_1_id 37is the parameter specifying an arbitrary CAN ID for the connected servo.In the command output, go to the INFO lines (see the example below). Look for IDs within the range between 32 to 37 — default servo IDs (37 in the example below).Example:INFO:   ID: 50 Device is in operational modeINFO:	ID: 37 Device is in pre-operational modeNow, you can run any of the tutorials from theexamplesfolder to move your RDrive servo or read parameters from it.To do this, run the following command in the console:python3 userapi/python/examples/read_servo_max_velocity.py --interface /dev/serial/by-id/usb-Rozum_Robotics_USB-CAN_Interface_301-if00 --servo_1_id 37whereread_servo_max_velocity.pyis the tutorial name (replace the name from the current example with any other tutorial name as needed);interface /dev/serial/by-id/usb-Rozum_Robotics_USB-CAN_Interface_301-if00is the parameter specifying the CAN Interface ID (the one we got at Step 1);servo_1_id 37is the parameter specifying an arbitrary CAN ID for the connected servo (the one we got at Step 2).If the command is successfully executed, the connected servo will behave as commanded—return parameters or move.Note:Some of the tutorials may require specifing some other parameters in addition to the CAN Interface ID and a CAN Servo ID.Python script examplesThe two subsections below contain examples of Python scripts based on available Python API commands.Basic usageimportrdriveasrrapi=rr.ServoApi()# api initialization and library loadinginterface=api.init_interface("/dev/serial/by-id/usb-Rozum_Robotics_USB-CAN_Interface_301-if00")# interface initialization# servo initializationservo=interface.init_servo(64)# toggle operational state on servoservo.set_state_operational()# go to specific position(degrees)servo.set_position(100.)# set specific velocity(degrees/sec)servo.set_velocity(204.5)Advanced usageBelow is the usual sequence of working with servos. For detailed instructions, refer toexamples.# importing modulesimportrdriveasrr# api initialization and library loadingapi=rr.ServoApi()# interface initializationinterface=api.init_interface("/dev/serial/by-id/usb-Rozum_Robotics_USB-CAN_Interface_301-if00")# servo initializationservo=interface.init_servo(64)# toggle operational state on servoservo.set_state_operational()# servo usage# preparing specific realtime parameters for extractionservo.param_cache_setup_entry(rr.APP_PARAM_CURRENT_INPUT,True)servo.param_cache_setup_entry(rr.APP_PARAM_VOLTAGE_INPUT,True)# set motor trajectory (adding motion points - position(deg), velocity(deg/sec), time(ms))servo.add_motion_point(100.,0.,6000)servo.add_motion_point(-100.,0.,6000)servo.add_motion_point(0,0,6000)# start motion with delay(ms)interface.start_motion(0)# reading realtime parameters from cacheservo.param_cache_update()current_input=servo.read_cached_parameter(rr.APP_PARAM_CURRENT_INPUT)voltage_input=servo.read_cached_parameter(rr.APP_PARAM_VOLTAGE_INPUT)print("current_input ={}, voltage_input ={}".format(current_input,voltage_input))# printing parameters# direct reading of realtime parametersvelocity_rotor=servo.read_parameter(rr.APP_PARAM_VELOCITY_ROTOR)print("velocity_rotor ={}".format(velocity_rotor))# awaiting motionapi.sleep_ms(20000)# simple motion controlservo.set_current(5)api.sleep_ms(1000)servo.set_current(0)# reading errorsnum,arr=servo.read_error_status(100)foriinrange(num):api.describe_emcy_bit(arr[i])