Вы находитесь на странице: 1из 7

Proceedings of International Conference on Computational

Methods in Engineering and Health Sciences,


December 17-19, 2014.

Implementing the CANopen protocol in a


Multiple Node System in the BioBike for Motor
Position Control
Vedant Prusty

AbstractThis paper considers a computation method for


accepting data about the present status of a motor, and then
controlling it to move in a specific direction, up to a specific
limit using the CANopen communication protocol. The
investigation is focused on developing a reliable algorithm for
controlling such motors in a CANopen network with multiple
nodes (based on the BioBike project being carried out at
Hochschule Ulm, Germany). PIC microcontrollers are used to
communicate over the CAN bus-network, along with a
Bluetooth interface to communicate with a control program on
a remote computer. The major considerations in coding the
embedded programs for such communication are explained.
Special attention is paid to the management of data traffic and
to improving the response of various nodes over the network.

The BioBike has four DC motors, controlling the Seat


and Handlebar positions, forwards-backwards and updown. The seat and the handlebar have four
potentiometers attached to them. These potentiometers
send back values as voltages, which is interpreted by the
microcontroller as the present position of the seat and
handlebar.
Simple DC motor control using microcontrollers is
being researched upon even today [1]. However, the
complexity
presented through multiple nodes and various types of
devices in the BioBike require that a dedicated and fast
communication protocol be used.

Keywords: BioBike, CANopen, data traffic, motor


position control.

I. INTRODUCTION

HE growing trend of integrating multiple


independently
manufactured
electronics
components into a single compact system has given rise
to the idea of standardization of communication
protocols. Such standards enable the addition of newer
components or nodes to the system over time,
allowing continuity in any ongoing project or research.
The BioBike (Fig. 1) project being developed at
Hochschule Ulm, University of Applied Sciences,
Germany, aims to develop a special test bench for bikers
covering biomechanics, effective pedaling, and optimal
power consumption. The project extracts the optimal
position between the bikers seat, the handlebars, and
the pedals in order to produce maximum forces through
minimum effort by the biker.
Vedant Prusty is an undergraduate Student pursuing a Bachelors
degree at the Dept. of Mechatronics, in Manipal Institute of
Technology,
Manipal,
India
576104.
This paper is based on his work at Hochschule Ulm University of
Applied Sciences, Ulm, Germany, where he worked at the Laboratory
for Medical Technology in the Department of Mechatronics and
Medical Engineering. (e-mail: vedant.prusty@learner.manipal.edu).

Directorate of Research, Manipal University

Fig. 1 Control Plan of the BioBike System being designed at


Hochschule Ulm

II. COMMUNICATION WITH CANOPEN PROTOCOL


A. CAN-bus
The CAN (Controller Area Network) bus is a serial bus
that works with a differential tension. Each CAN node
is connected in parallel. (Two termination resistors of
120 Ohm at the ends of the bus are recommended. [2])
Here, a node represents any device following the same

ES013- 01

Proceedings of International Conference on Computational


Methods in Engineering and Health Sciences,
December 17-19, 2014.

communication protocol as the other devices in the


network. The CAN-bus specification has been there
now for more than 20 years (being widely used in the
automation industry [3]) and is well integrated in
microcontrollers today. Fig. 2 illustrates a typical CAN
bus network with nodes.

Fig. 2 A typical CAN bus network with nodes

B. CANopen protocol
[4] Real world problems require the integration of
several devices that have same or similar functionality.
However, more than often, these devices may not be
interchangeable due to different implementation details,
communication protocols or parameter setups. The CIA
CAN in Automation organization has created several
standards to define functionality of such devices so that
they may be used interchangeably. [7] Devices profiles
like generic I/O modules and drives and motion
control have been created. Today, there are many
vendors selling products with integrated CANopen
protocol. The PIC 18F family of microcontrollers has
CAN input and output ports defined.
The CANopen standard consists of an addressing
scheme, several communication protocols and an
application layer defined by a device profile. The
communication protocols have support for network
management, device monitoring and communication
between nodes, including a simple transport layer for
message segmentation/de-segmentation. [5] The basic
CANopen device and communication profiles are given
in the CiA 301 specification released by CAN in
Automation.
CAN may be implemented over a number of physical
media as long as the drivers are open-collector and each
node can hear itself (and others) while transmitting (this
is necessary for its message priority and error handling
mechanisms).

Directorate of Research, Manipal University

Fig. 3 The CANopen message frame

The message frames generally used to carry data are


shown in Fig. 3. They contain the following fields
(this is a simplified description as the controller takes
care of the detail)
Start of frame
(SOF)
Message Identifier (MID)
the Lower the
value the Higher the priority of the message
length is either 11 or 29 bits long depending on
the standard being used
Remote Transmission Request (RTR)
Control field (CONTROL) this specifies the
number of bytes of data to follow
Data Field (DATA) length 0 to 8 bytes
CRC field containing a fifteen bit cyclic
redundancy check code
Acknowledge field (ACK) an empty slot
which may be filled by any and every node that
receives the frame (it does NOT say that the
node you intended the data for got it, just that
at least one node on the whole network got it.)
End of Frame
(EOF)
CANopen allows the implementation of up to 127
CAN-nodes on a single bus. Each node must be
provided with a unique node ID. Each unique node
allows the use of more than one address number. [6] In
CANopen instead of addresses they are called
Communication Object Identifiers (COB ID).
C. Service Data Object (SDO)
SDOs allow access to a single entry in the Object
Dictionary, specified by index and sub-index. They use
the clientserver communication model, where the
client accesses the data and the server owns the target
Object Dictionary. (All relevant data that characterizes a
device profile of a CANopen device is implemented in
an Electronic Data Sheet (EDS) file. The EDS organizes
objects in a dictionary that stores the relevant data.)
SDOs are typically used for device configuration or for
accessing a large amount of data at a very low rate. The
difference between a Transmit and Receive SDO is that
in case of a Receive SDO a request to obtain the
contents of an object must be sent first. (Effectively, in
this project SDOs are instructions sent from control PC
to nodes)
D. Process Data Object (PDO)
PDOs are used by connected nodes, for example in a
twin motor configuration, to exchange real time data
during operation. PDOs allow up to 8 bytes of data to be

ES013- 02

Proceedings of International Conference on Computational


Methods in Engineering and Health Sciences,
December 17-19, 2014.

transmitted in one CAN message. This reduces the time


to send the PDO data over the CAN-bus. (Effectively, in
this project PDOs are statuses sent from nodes to
control PC)
E. Software used
MPLAB Integrated Development Environment (IDE)
is an integrated toolset for the development of
embedded applications in C language on Microchip's
PIC and dsPIC microcontrollers.
The Motor driver circuits in the BioBike project use
the PIC18F25K80 microcontroller from PIC, and are
programmed using the PICkit3 debugger.
The BioBike receives all information from the control
PC through a Master Interface (MI) via Bluetooth. This
MI further distributes this message over the CAN bus to
which all the motor drivers are connected as parallel
nodes. MPLAB is used to define code for this MI as
well as the chips on the motor drivers, in two separate
projects.
Qt is used to communicate with and design a Graphic
User Interface (GUI) in the control PC for the BioBike.
Qt is a cross-platform application framework that is
widely used for developing application software with
GUI, and also used for developing non-GUI programs
such as command-line tools and consoles for servers.
The CANopen protocols defined in the MPLAB
programs have to be implemented in Qt as well.

Fig. 4 Definition of CANopen message in header file

In order to speed up communication, while building


incoming CAN messages, two buffers of the PIC
microcontrollers were used. BUF0 and BUF1 are used
to load CAN messages alternatively. They are checked
for overflow in the presence of the messages using
RXB0CON.RXFUL and RXB1CON.RXFUL (as shown
in Fig. 5). At this time, after the PC_inPck function
(which is used to send the incoming CAN message to
the PC) is built, an LED on the MI board is made to
blink, which is used as an indicator for data activity.
This use of LED proved significantly helpful while
monitoring data traffic in the CAN bus network.

IV. IMPLEMENTING CANOPEN


A. Master Interface Program
Written in MPLAB under the project name
CANopenCOM.x, this program holds the code which is
used to run the MI installed on the BioBike which
communicates with the control PC via Bluetooth. The
project is essentially a standard CANopen
communication framework used in Hochschule Ulm,
modified to suit the needs and requirements of the
BioBike.
The Header files define the various CANopen
message formats, the definitions for reading or writing
messages, etc. Source files define functions to build
incoming CAN messages once latches are full, and
build outgoing messages as well. Hence the MI is
designed to work as an intermediate between all the
nodes on the BioBike and the control PC. Fig. 4 shows
the use of typedef struct to define the CANopen
message bits.

Fig. 5 Using RXB0CON.RXFUL and RXB1CON.RXFUL

It is to be noted that heavy data traffic was detected


on startup of the BioBike system, i.e. as soon as power
connection was made, the MI started receiving and

Directorate of Research, Manipal University

ES013- 03

Proceedings of International Conference on Computational


Methods in Engineering and Health Sciences,
December 17-19, 2014.

transmitting CAN messages from the motor controllers


to the PC. This led to interference with the initial
messages of device ID and device recognition which are
sent by the by the control PC on startup. The MI was
overwhelmed by CAN messages of potentiometer
values coming from nodes, and the Qt program on
control PC had a tendency to hang. To prevent this, a
flag errors.not_started is defined in the source files to
check if device has been started and initial setup and
device recognition is completed by the control PC
(errors.not_started flag should be 0 and a connection
has been established with PC). The flag is reset from 1
to 0 by the control PC Qt program after startup. Only
then does the program allow receiving and transmitting
of the messages from the motor driver nodes.
B. Motor Driver Circuit program
The MPLAB project named BB_Motor holds code
for the PIC microcontroller on the motor driver circuit
boards or nodes. It defines device ID (device profile
specification [5], [7]) for the node in the CAN bus, and
protocols for building, sending and receiving CANopen
messages over the network. The header files define
CAN communication protocols, message sizes, data
frames, etc. similar to the ones on the MI. This program
is common to all motor nodes with the only difference
being the COB IDs.

The main function of this program is to read CAN


messages (incoming SDOs) being transmitted over the
bus and then analyze them if and only if it the message
is addressed to the specific node, i.e. the COB ID of
message matches that of the node reading the message.
It then goes on to analyze the data frame of the message
and move motor in a specific direction, up to a specific
limit. Fig. 6 shows how when a CAN message is
received to control motor; the corresponding motor
control function is called and the isMoving flag is set
accordingly.
It is also programmed to continuously read the
incoming value from the potentiometer for the specific
motor in question, and send back to the value to the
control PC via the MI. A PDO is built which holds the
CAN message with potentiometer value in data frame.
This enables the control PC to know the present location
of the seat or handle in the up-down or forwardbackward directions.
A major challenge in the project, as already
mentioned, was data traffic. Again, it was noticed that
on power connection, the motor driver circuit keeps
sending potentiometer values, over the network, even
while there is no change in the position. The reason was
identified as follows: the potentiometers may return
non-distinct values, or values between two numbers, an
interval which the microcontroller cannot recognize,
and therefore considers them as moving. It then keeps
sending CAN messages of apparent new positions of
potentiometers (It is also possible that the potentiometer
itself keeps oscillating between two values and keeps
updating the input latch in the microcontroller). This
adds to garbage data going to the PC which cannot be
used in any way, since there is no data to update on the
User Interface (UI) on screen. To prevent this data
traffic, two Status Flags were defined in the header files,
newPosition and isMoving.

Fig. 6 Handling of an incoming SDO to control motor

Directorate of Research, Manipal University

ES013- 04

Proceedings of International Conference on Computational


Methods in Engineering and Health Sciences,
December 17-19, 2014.

Fig. 8 The BioBike User Interface

Fig. 7 Presence of a new potentiometer value generates an


interrupt

The isMoving flag is initialized to 0 or false on


power connection. While starting to move the motor, the
isMoving flag is set to 1, and is set to 0 every time the
motor is halted, i.e. a halt motor instruction is received
from the PC. The incoming signal from the
potentiometer is scanned for any change in value. The
change of value of a variable named actual_position
which continuously reads values from ADRES
generates an interrupt (as shown in Fig. 7). Only then is
the newPosition flag set to true or 1 (by the interrupt).
Both the above flags, isMoving and newPosition, are
required to be true in order for the microcontroller to be
allowed to send messages regarding potentiometer
values over the network, thereby reducing the traffic.
newPosition is set back to 0 as soon as the PDO
carrying potentiometer value is sent.
C. Control PC Program
The BioBike project in Qt holds code (in C++)
for the PCs communication with the remote
microcontroller. It defines the various functions to send
messages for moving motors in various directions and
reading their positions. It also defines a User Interface,
which may be run as an executable file on building the
project. The user interface designed has all basic
commands for motor control and focuses on simplicity
of use.

Directorate of Research, Manipal University

Similar to the programs in MPLAB, the


BioBikeCAN.h header file in the Qt project has
definitions for various CAN message commands,
controls, statuses, operations and device IDs;
corresponding to the same definitions on the
microcontrollers. The BioBike_main.cpp connects
various buttons on the UI to functions. It also defines
functions for connecting to the remote interface through
the COM ports of the PC.
It is able to build CAN messages for UP/Down and
Forward/Backward controls entered through buttons. It
is able to process incoming CAN messages (PDOs
from the microcontroller on the nodes) and analyze
potentiometer data, in order to display the Seat or
Handlebar position on sliders on the UI. All these CAN
messages are transmitted serially to the remote
Bluetooth module on the MI, which further distributes
signals over the bus. Fig. 10 shows how an incoming
PDO is handled.
Example working of a motion button (Refer Fig. 9)
When the Handlebar UD button move the handlebar
upwards is clicked, a CAN message is built with
instructions for the respective motor to move upwards.
(BB_LENKER_UD device ID, BBMC_MOVE_MINUS
message data (SDO), and BBM_CONTROL message
object). When the button is released, the message data is
set to BBMC_HALT and a new CAN message is sent
over the network.

ES013- 05

Proceedings of International Conference on Computational


Methods in Engineering and Health Sciences,
December 17-19, 2014.

Fig. 9 Code for functions called when motion buttons are


clicked

The on_btnStopAll( ) function is called on clicking


the Emergency Stop All button. In turn, it calls the
STOP functions (which create SDOs to halt motors) of
all the motors consecutively. The function is meant as a
safety feature and proved useful while running tests in
the course of the project.
In the UI, there is also a slot for entering absolute
target position for a specific motor. The radio button for
the desired motor is selected, the value is entered and
the GoTo button is clicked. The program sends a motor
PLUS or MINUS SDO message based on present
position of the potentiometer (extracted from the
incoming CAN PDO from nodes) and target position
entered in the UI. As soon as the required position is
reached, the program sends a HALT SDO to the specific
motor.

leaves much scope for adding sensor and actuator


modules (such as ECG, pulse oximetry, ergo-metrics
etc.) which use the same communication protocol to the
system. The components such as the Power Brake and
the Pedal Force Analysis System which are already
installed on the BioBike need only be configured for
CANopen communication and can be directly added as
nodes. This significantly widens the scope of the
BioBike project for analyzing bio-mechanics and human
performance. Further additions to the system must only
implement CANopen and join the network architecture
as new nodes. This implementation can be used as an
example to build other systems as well where several
devices need to be interfaced and communicate with a
single point of control. Also, the data traffic handling
techniques discussed can be used in similar systems
which use microcontrollers on the multiple nodes of a
system.

Fig.11 The BioBike in development with movement motors


installed

ACKNOWLEDGMENT
The Author is grateful to Prof. Rainer Brucher and
Volker Schilling-Kstle of Hochschule Ulm, Germany,
for their constant support and encouragement in the
above research work.
Fig. 10 Incoming CAN message or PDO from motor node and
extraction of potentiometer value

V. CONCLUSION
The algorithm for communication based on CANopen
protocol that was applied is specific to the BioBike
project. The implementation of this standard protocol

Directorate of Research, Manipal University

REFERENCES
[1]

Jayshree Sahu, S.K.Sahu, Jayendra Kumar, Microcontroller


Based Dc Motor Control, International Journal of Engineering
Research & Technology (IJERT), Vol. 1 Issue 3, May 2012.

[2]
[3]

http://www.canfestival.org
Industrial Automation using CAN Bus Platform White Paper,
TEXAS
INSTRUMENTS

ES013- 06

Proceedings of International Conference on Computational


Methods in Engineering and Health Sciences,
December 17-19, 2014.
[4]

[5]
[6]

[7]

Wim Catteeuw, Piet Cordemans and Jeroen Boydens,


Integration of a CANopen Protocol Stack in an Embedded
Application Employing the CANFestival Stack, Annual Journal
of Electronics, 2012.
CiA 301 - CANopen application layer and communication
profile
Pfeiffer, O.; Ayre, A. & Keydel, C. Embedded Networking with
CAN and CANopen, Copperhill Technologies Corporation,
2008
CIA401.

Directorate of Research, Manipal University

ES013- 07

Вам также может понравиться