ABN Report 1.1 Fin
ABN Report 1.1 Fin
ABN Report 1.1 Fin
Pranav Tankkar
October 2022
Abstract
Machine-to-machine (M2M) communication is a rapidly growing
field with a wide range of applications in industrial automation,
smart cities, and the Internet of Things (IoT). M2M
communication allows devices to communicate with each other
directly, without the need for human intervention. This report
provides an overview of M2M communication for motor PID
control over a wired network. Motor PID controllers are widely
used in industrial automation applications to control the speed and
torque of motors. M2M communication can be used to create
closed-loop control systems in which the controller monitors the
performance of the motor and makes adjustments in real time to
ensure that it is operating at the desired speed and torque. This
report also discusses how to configure the network for
multihoming, firewall configuration, and route setup between
different LANs. This is necessary to ensure that the motor PID
controller and other devices on the network can communicate with
each other.
Contents
Chapter 1.....................................................................................................................................................4
Introduction....................................................................................................................................................4
1.1 Aims and Objectives....................................................................................................................4
Aims 4
Objectives.......................................................................................................................................5
1.2 The OSI Reference Model and M2M Identification............................................................................5
M2M Identification in OSI Model:..................................................................................................7
1.3 Hardware and Software Information....................................................................................8
Hardware.........................................................................................................................................8
Software..........................................................................................................................................8
Chapter 2.....................................................................................................................................................9
Course Work Part-1.................................................................................................................................9
2.1 Network Design Specification................................................................................................9
2.2 IP Configuration........................................................................................................................10
2.3 Multihoming...............................................................................................................................11
2.4 Configuration of Devices.......................................................................................................12
2.5 Testing the Latency..................................................................................................................14
2.6 Configuring the Wifi................................................................................................................15
2.7 Password-less SSH sessions...........................................................................................................17
2.8 Throughput, TCPdump and SSH Pipeline......................................................................................19
Chapter 3...................................................................................................................................................22
Course Work Part-2............................................................................................................................22
3.1 Design of the M2M communication framework............................................................................22
3.2 DC Motor........................................................................................................................................22
3.3 Specifications.............................................................................................................................23
3.3.1 Objectives and Components of a Closed Loop Control System.......................................23
3.4 Control System Analysis........................................................................................................25
3.4.1 Software Process Controller Block...................................................................................25
3.4.2 Step Response Measurements...........................................................................................25
3.5 Rig Components.............................................................................................................................26
3.6 Ensuring System Stability..........................................................................................................26
3.7 Essential Libraries.......................................................................................................................26
3.8 GPIO Configuration....................................................................................................................27
3.9 Interrupts and Significance of the Encoder C Program.........................................................27
3.10 Encoder Algorithm......................................................................................................................27
3.11 Controller Algorithm...................................................................................................................28
3.12 Proportional, Integral, and Derivative Responses..................................................................28
3.13 The Significance of the Controller/Regulator C Program.....................................................28
3.14 Experiment 1................................................................................................................................28
3.15 Experiment 2................................................................................................................................29
Chapter 4...................................................................................................................................................31
Conclusion.....................................................................................................................................................31
References..................................................................................................................................................32
Appendices................................................................................................................................................32
3
Chapter 1
Introduction
The introduction serves as a fundamental section providing a
context for the subsequent discussions. In this chapter, we delve
into the expansive realm of the Internet of Things (IoT) with a
specific focus on machine-to-machine (M2M) communication
over wired networks. The Internet of Things (IoT) is a
transformative technological paradigm that has gained remarkable
traction in recent years. It encompasses a vast ecosystem of
interconnected devices, enabling them to communicate, collect,
and exchange data, leading to intelligent decision-making and
automation. IoT applications are ubiquitous, ranging from smart
homes and wearable devices to industrial automation and
healthcare systems. At the heart of IoT lies machine-to-machine
(M2M) communication, a pivotal aspect that drives the seamless
flow of data between devices.
Aims
The initial aim of the experiment is to establish network
connections among the computer hardware (Raspberry Pis)
across various LANs. This involves setting up IP routing
between these devices and to the internet, as well as
configuring them with IPv4 addresses. The objective is to
select the gateways for efficient packet transmission
between different LANs.
Objectives
Configure hosts and define LANs with provided IP
addresses for effective communication.
6
Figure 2: OSI Model
The presentation layer in the OSI model provides the API necessary for
devices, clients, and administrators to communicate with the M2M
framework. It acts as an intermediary for transforming data into a format
that the application layer can utilize.
At the application layer, the M2M system defines its topology, protocols,
and languages. It is unaware of the method of communication (whether
7
it's the Internet or OSI layers 1-4) and the method of registration of the
"things" (Layer 5). The application layer uses the OSI 6 API for
communication within the M2M system.
Understanding how M2M integrates into the OSI reference model allows
for a clear grasp of the system's structure and the interactions that occur
at various levels, aiding in effective design and implementation of M2M
networks. Understanding these layers is crucial for delving into the
intricacies of M2M communication within IoT, as each layer plays a
vital role in ensuring seamless communication between devices.
Hardware
As a network host device (RigPi Device), a Raspberry Pi computer is
used. Using multihoming, it functions both as a host and a gateway
on the network. When connected to one of the network's RigPi
devices, a DC motor performs the role of an IoT device. To power
and manage the DC motor, a Driver Board is utilized.
Software
The RigPi hardware runs a Linux-based operating system. C is a
programming language used to create computer programs. Making
and editing "C" programs requires the use of an nano editor. ssh,
ping, netstat, nslookup, route, iptables, and ifconfig are among the
numerous network Linux commands used. Plotting graphs using
output data requires the use of GNUPlot.
8
Chapter 2
Course Work Part-1
2.1Network Design Specification
All these Raspberry Pi devices operate on the Linux operating
system. Raspberry Pi A, known as Manager Pi 1 A, acts as the
Master Pi, while the other three devices (pi1b, pi2a, pi2b) are
collectively referred to as My Rig or RigPi. The next objective is
to configure these RigPi devices to be part of three LAN
networks: LAN 1, LAN 2, and LAN 3.
9
2.2IP Configuration
ManagerPi A (pi1a):
LAN 1: 192.168.27.1
MyRig B (pi1b):
10
LAN 1: 192.168.27.2
LAN 2: 192.168.124.4
MyRig C (pi2a):
LAN 2: 192.168.124.3
LAN 3: 192.168.116.2
MyRig D (pi2b):
LAN 3: 192.168.116.1
1. LAN 1:
Connects ManagerPi A (pi1a) with IP 192.168.27.1
Connects MyRig B (pi1b) with IP 192.168.27.2
Subnet: 192.168.27.0
2. LAN 2:
Connects MyRig B (pi1b) with IP 192.168.27.1
Connects MyRig C (pi2a) with IP 192.168.124.4
Subnet: 192.168.124.0
3. LAN 3:
Connects MyRig C (pi2a) with IP 192.168.124.4
Connects MyRig D (pi2b) with IP 192.168.116.2
Subnet: 192.168.116.0
2.3Multihoming
The allocation of RigPi devices to their respective LANs, each
given a different IPv4 Class C address, as shown above. The
network computers are set up as multihoming devices, which is
highlighted by the specific IPv4 Class C range at which these
addresses are set. Surprisingly, this configuration is carried out on
11
a single network interface card, demonstrating the efficient use of
IPv4 Class C addresses for efficient networking between the
devices.
2.4Configuration of Devices
Interconnecting all devices within a network is essential for
seamless communication and efficient data exchange. In the
described network scenario involving ManagerPi A (pi1a), MyRig
B (pi1b), MyRig C (pi2a), and MyRig D (pi2b) with their
respective LANs and IP addresses, establishing internetworking
involves configuring routing tables and firewall rules to enable
communication between these devices across different LANs.
ManagerPi A (pi1a):
MyRig C (pi2a):
MyRig D (pi2b):
ManagerPi A (pi1a):
MyRig B (pi1b):
MyRig C (pi2a):
13
sudo route add -net 192.168.27.0 netmask 255.255.255.0 gw
192.168.124.3: This sets up a route to the 192.168.27.0/24 subnet
via the gateway at 192.168.124.3 (machine B).
MyRig D (pi2b):
Traceroute from A to D:
15
The following instructions were followed to configure of Wi-Fi
and network settings on ManagerPi A (pi1a):
1. Configuration of `/etc/network/interfaces`:
3. Configuration of `/etc/wpa_supplicant/wpa_supplicant.conf`:
16
Figure: wpa_supplicant.conf file
4. Adjustment of `/etc/sysctl.conf`:
5. Network Restart:
17
As a further assessment of network functionality, the 'ping'
command is employed to ping the Newcastle University website
with the hostname 'www.ncl.ac.uk.' This assesses the device's
capacity to access specific web resources on the network.
18
Generate an SSH key pair: `ssh-keygen`
Copy the public key from A to B:
`ssh-copy-id [email protected]`
Copy the public key from A to C:
`ssh-copy-id [email protected]`
Copy the public key from A to D:
`ssh-copy-id [email protected]`
Edit dhcpcd.conf:
Edit resolv.conf:
19
Figure: Throughput
20
Figure: TCPdump
On Device A:
21
mkfifo ~/fifoB
22
Chapter 3
Course Work Part-2
Part 2 of the practical coursework entails the design and
implementation of a closed-loop control system. It consists of two
experiments, each highlighting different aspects of control system
architecture. Experiment 1 emphasizes simplicity and stability by
connecting the control system to a Rig Pi. It involves fine-tuning
PID coefficients and sample rates to achieve system stability. In
Experiment 2, network complexity is introduced, leading to
increased latency and decreased stability. This experiment
requires rewiring the system, employing secure shell connections,
and testing different PID coefficients and sample rates. Both
experiments involve measuring the step response, plotting motor
speed over time in response to a Heaviside step function.
Proficiency in C programming is essential, particularly in
handling data formats and utilizing C libraries for hardware
control. Careful consideration of PID coefficients and sample rates
is crucial to achieving system stability in these experiments.
3.2 DC Motor
23
Figure: DC motor Connected to Raspberry Pi
For the purpose of regulating the DC motor's speed via the RigPi-
B host, a particular command is employed:
It's important to note that when the value in this command is set to
737, it acts as a reference point equivalent to bringing the motor to
a standstill. When the value surpasses 737, the motor's shaft
initiates clockwise rotation, as demonstrated by this command:
24
echo 800 1\\ > /dev/serial0
3.3 Specifications
Hardware Rig Block: The output of this block is the rotation of the shaft,
which is realized through a DC motor. The key parameter here is the
rotational frequency of the shaft.
The encoder is used to record the output data, with the encoder's output
connected to the controller's input through a pipeline. The "tee" utility, a
standard tool in the Linux system, is used to create a copy of the standard
output and save it to a file.
To gain insights from the data and tune the PID coefficients, "Gnuplot"
software is employed to plot the step response data over time. To plot the
data stored in a file, the "gnuplot" tool is initiated, and the data can be
visualized using the command "plot samples.dat with lines." The
"samples.dat" file contains data with one data point per line.
27
3.6 Ensuring System Stability
Upon the system's deployment, it is imperative to conduct a
thorough assessment of its stability. If any indications of
instability emerge, it becomes necessary to finetune the
coefficients of the PID controller. A reduction in the gain
mitigates oscillations, thereby enhancing system stability, albeit at
the potential cost of a diminished system response rate.
3.14 Experiment 1
30
device. RigPi B is chosen primarily for its operational
convenience, as it obviates the introduction of additional latency
stemming from network interactions. The consolidation of both
encoder and controller within the same device yields a robust step
response function.
31
engender diminished system stability.
3.15 Experiment 2
32
Figure 21: Encoder Readings
Within this less stable framework, the PID coefficients retain their
values (Kp = 0.85, Ki = 0.8), though the sample rate is curtailed to
SAMPLE_RATE_MS ms. This modification precipitates a
situation of system instability, underscored by the salient principle
that as the sample time dwindles, system stability wanes
proportionally. These experiments collectively unveil the
dynamics of system stability amidst varied settings and the
influence of network complexity.
33
Chapter 4
Conclusion
Comprehending Machine-to-Machine (M2M) Concepts:
Gaining a solid grasp of M2M principles.
34
a control system to a network device to enable remote
control, exemplifying the Internet of Things (IoT).
35
References
Appendices
a. Encoder C Program
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <poll.h>
#include <fcntl.h>
#include <pthread.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#define SAMPLE_RATE_MS 20
#define TOTAL_INTERRUPTS_PER_ROTATION 500
#define ROTATION_DIRECTION_GPIO 10
#define INTERRUPT_GPIO9
double frequency;
while(1)
{
usleep(SAMPLE_RATE_MS * 1000);
pthread_mutex_lock(&lock);
frequency=(double)( interrupt_count * 0.1);
interrupt_count = 0;
36
pthread_mutex_unlock(&lock);
printf("%1f\n", frequency);
fflush(stdout);
}
return NULL;
}
int main() {
pthread_t freq_thread;
char buffer[4];
lseek(fd1, 0, SEEK_SET);
read(fd1,buffer,1);
if(buffer[0] == '1')
{
printf("+1\n");
}
else
{
printf("-1\n");
}
fflush(stdout);
}
close(pfd0.fd);
pthread_mutex_destroy(&lock);
return 0;
}
b. Regulator C Program
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <time.h>
#include <pthread.h>
#define Kp 0.85
#define Ki 0.8
38
#define Kd 0.0008
#define Km 65
double I=0;
double Eold=0;
char buffer[100];
void *variableInput() {
while (1) {
usleep(10000000);
pthread_mutex_lock(&lock);
if(Finp==0.0) Finp=2.0;
else Finp=0.0;
pthread_mutex_unlock(&lock);
int main()
pthread_t threadOne;
double E, D, PID,Y;
double Tsample=0.02;
double Fenc;
char buf[100];
39
while(scanf("%lf\n", &Fenc) == 1){
E= Finp - Fenc;
I = I + (E * Tsample);
D = (E - Eold)*50;
char command[100];
system(command);
printf("%lf\n", Fenc);
Eold = E;
pthread_mutex_destroy(&lock);
return 0;
40