Q- How To Communicate Between RoboteQ Devices Using RoboCAN

RoboCAN is a powerful networking protocol designed to allow RoboteQ products to easily communicate with one another. However, it can be a bit confusing initially to new RoboteQ users or those unfamiliar with CAN. Thus, the purpose of this brief article is to review the basics of RoboCAN and give a practical tutorial of networking to RoboteQ products together using RoboCAN.

RoboCAN Basics

RoboCAN is a proprietary networking protocol intended to interconnect and communicate between RoboteQ products specifically. Note that the specifics of RoboCAN are described in more detail in our article, “RoboCAN: A Simple Meshed Network,” as well as in Section 15 of our User Manual. But for now, let’s just review some of the basics:

The RoboCAN network is generally set up in a Master – Slave configuration, where you have one RoboteQ device configured as the Master Node and then up to 125 Slave Nodes. The bus will require that you connect CANL and CANH between all of the RoboteQ devices, and then use 120Ω termination resistors on each end of your bus.

Image

You can then send serial commands through your Master Node connected to a PC or Microcomputer via RS232 or USB, or you can have a MicroBasic script loaded to your Master Node that gives full automated control over the entire network.

Serial Runtime Commands/Queries

 

Serial commands are sent from your PC using the Roborun+ Console or a terminal program. Serial commands can also be sent from a Micro or other hardware device via RS232 or USB to the Master Node.

 

Runtime Command

 

Syntax: @id!cc ch vv

Where:

id is the remote Node Id in decimal

cc is the Command code, eg !G

ch is the channel number. Put 1 for commands that do not normally require a channel number

vv is the value

Example:

@04!G 1 500

This will give a run command of 500 to motor channel one on the slave motor controller assigned as Node ID: 4.

 

Runtime Query

 

Syntax: @id?cc ch vv

Where:

id is the remote Node Id in decimal

cc is the Command code, eg ?AI

ch is the channel number. Put 1 for commands that do not normally require a channel number

vv is the value Put 0 for queries that do not normally require a value

Example:

@03?AI 2 0

This will read the analog input voltage of analog input 2 on the motor controller assigned to Node ID: 3.


MicroBasic Runtime Commands

 

Commands and queries can also be sent from a MicroBasic Script running on the Master Node.

 

Runtime Command

 

Syntax: SetCANCommand(id, cc, ch, vv)

Where:

id is the remote Node Id in decimal

cc is the Command code, eg _G

ch is the channel number. Put 1 for commands that do not normally require a channel number

vv is the value

Example:

SetCANCommand(04, _G, 1, 500)

This will apply 50% power to channel 1 of node 4.

For more details and examples of runtime commands/queries, as well as configuration commands and queries, please review Section 15 of our User Manual.


Practical Example Tutorial

 

Now that we are familiar with the syntax needed to communicate between devices on a RoboCAN network, let’s apply this knowledge in a simple practical example. In this example we will simply connect a RoboteQ MDC2460 motor controller to a RIOX1216-AH IO Extender via CAN. We will then configure the RIOX1216-AH as a Slave Node, and configure the MDC2460 as the Master Node. Finally we will load a MicroBasic Script to the Master Node (MDC2460) that will turn on all of the Slave Node’s digital outputs in sequence, then turn them off in sequence in a loop.


Wiring

 

Wiring is simple in this case, since we are only connecting two devices to the bus. We simply need to connect CANL of the MDC2460 to CANL of the RIOX, and then connect CANH of the MDC2460 to CANH of the RIOX. Note that the CANL and CANH pins may not be the same on different models of RoboteQ devices. Please refer to the product datasheet for the correct CAN pins of your device.

After connecting the CANL and CANH lines together we need to add the 120Ω termination resistor between them. In this example we are using only two nodes, and our bus length is quite short, only ~2ft. So, in this case only one termination resistor is necessary. If you are using more nodes and have a longer bus it will be necessary to add a second termination resistor, one on each end of the BUS.

Image

In the end, our network wiring looks like this:

Image

Configuration

Slave Configuration

 

Now we will configure our two devices. First we will configure our RIOX1216-AH as a Slave Node. This is done simply from the RIOX Configuration Utility. We will set the CAN Mode: RoboCAN, Node ID: 2, and Bit Rate: 250. All other CAN settings besides these three will be irrelevant in RoboCAN. After making these configuration changes, be sure to click “Save to Sensor” in order to save the new configuration settings to the RIOX.

Image

Master Configuration

 

Next we will configure the MDC2460 as the Master Node. This is done simply from the Roborun+ Configuration Utility. We will set CAN Mode: RoboCAN, Node ID: 1 (master node), and Bit Rate: 250. Note that for sake of this tutorial we are using the bit rate 250. In general you can use any of the available bit rates, you will just need to be sure that the same bit rate is configured to all nodes. After changing these settings be sure to click “Save to Controller” in order to save the new settings.

Image


Confirm That Slave Is Present

 

After configuring both devices you will want to make sure that the Slave Node is present and ready to be instructed by the Master Node. Make sure both devices are powered on and that they are connected via CAN. At this point you only need to have your Master Node (MDC2460) connected to your PC via RS232 or USB.

To confirm that the Slave Node (RIOX1216-AH) is present, open the Console tab of Roborun+. From one of the Out Data lines send the query ?ICL 02. ?ICL is the serial query syntax to check for the presense of any remote node, 02 of course is the node id we are checking. After sending this query you will get one of two responses in the In Data window. If you receive ICL = 1, then this means that the slave node is present and ready for commands. If you receive ICL = 0, then your slave node is not present.

 

Node Present

Image

Node Note Present

Image

If you do receive a response of ICL = 0 you will want to double check your wiring and configuration to make sure all is correct. Additionally you can follow the Basic Setup and Troubleshooting instructions detailed on pages 152-153 of the User Manual.


Load MicroBasic Script to Master Node

 

After we have connected our two devices, configured them for RoboCAN, and confirmed that the Slave Node is present, we are ready to load a script to our Master Node to give commands to the Slave. Again, we will be using a simple script that will send commands from the Master (MDC2460) to activate and deactivate the digital outputs in sequence on our Slave (RIOX1216-AH).

Simply copy and paste the script below into the Scripting Tab of Roborun+:

' This script is provided "as-is", without warranty of any kind,
' expressed or implied, including but not limited to the warranties of
' merchatability, fitness for a particular purpose and
' noninfringemement. In no event shall Roboteq be liable for any claim,
' damages or other liability, arising from the use of the software"

' Sends RoboCAN commands in sequence to RIOX board configured as Slave Node.
' Activates Douts 1 - 8, holds then deactivates Douts 8 - 1 in a loop.


Print("Starting...") 'Prints verification in console that script has started

Top:

setCANcommand(02,_Dset, 0, 1) 'Enable RIOX Digital Output 1

wait(250) 'wait 250 milliseconds

setCANcommand(02,_DSET, 0, 2) 'Enable RIOX Digital Output 2

wait(250) 'wait 250 milliseconds

setCANcommand(02,_Dset, 0, 3) 'Enable RIOX Digital Output 3

wait(250) 'wait 250 milliseconds

setCANcommand(02,_Dset, 0, 4) 'Enable RIOX Digital Output 4

wait(250) 'wait 250 milliseconds

setCANcommand(02,_Dset, 0, 5) 'Enable RIOX Digital Output 5

wait(250) 'wait 250 milliseconds

setCANcommand(02,_Dset, 0, 6) 'Enable RIOX Digital Output 6

wait(250) 'wait 250 milliseconds

setCANcommand(02,_Dset, 0, 7) 'Enable RIOX Digital Output 7

wait(250) 'wait 250 milliseconds

setCANcommand(02,_Dset, 0, 8) 'Enable RIOX Digital Output 8

wait(500) 'wait 500 milliseconds


setCANcommand(02,_DRES, 0, 8) 'Disable RIOX Digital Output 8

wait(250) 'wait 250 milliseconds

setCANcommand(02,_DRES, 0, 7) 'Disable RIOX Digital Output 7

wait(250) 'wait 250 milliseconds

setCANcommand(02,_DRES, 0, 6) 'Disable RIOX Digital Output 6

wait(250) 'wait 250 milliseconds

setCANcommand(02,_DRES, 0, 5) 'Disable RIOX Digital Output 5

wait(250) 'wait 250 milliseconds


setCANcommand(02,_DRES, 0, 4) 'Disable RIOX Digital Output 4

wait(250) 'wait 250 milliseconds


setCANcommand(02,_DRES, 0, 3) 'Disable RIOX Digital Output 3

wait(250) 'wait 250 milliseconds


setCANcommand(02,_DRES, 0, 2) 'Disable RIOX Digital Output 2

wait(250) 'wait 250 milliseconds


setCANcommand(02,_DRES, 0, 1) 'Disable RIOX Digital Output 1

wait(500) 'wait 500 milliseconds

goto top 'Loop forever

After pasting the script click “To Device” to load the script to the motor controller. After doing this you will simply need to click Run at the top of the Roborun+ window to start the script. After starting the script, you will see the green LEDs relative to the RIOX1216-AH digital outputs illuminate in sequence, and then turn off in sequence.

Image

It is simple as that! You are now sending commands from your Master node to your Slave node over the CAN bus!

Final Notes

 

This has been a very basic tutorial of communicating between two RoboteQ devices using RoboCAN. However, you should now see how simple and strait forward RoboCAN is. You can now begin experimenting with more nodes and more complicated tasks. Adding more nodes is simple in that you will only need to assign them a different Node ID, and then refer to that respective node ID in your script or serial commands and queries.