Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

1

Hanoi University of Science and Technology


School of Electrical Engineering, 03 July 2022
*

*
2
Hanoi University of Science and Technology
School of Electrical Engineering, 03 July 2022

Mini Project
Simulating A Speed Sensor Mounted On
A DC Motor Programming
Student Names & ID
Phan Sỹ Nhật Tân – 20192247- ĐKTĐH- HTĐ Name Instructor
Vũ Quang Khải – 20192218 - ĐKTĐH- HTĐ TS. Hoàng Đức Chinh
Nguyễn Thành Hưng– 20192211- ĐKTĐH- HTĐ

together represent a sequence. In its most basic form, each


Abstract— Nowadays, DC Motor applications in Industries node contains- data and reference(in other words, a link or
are outstanding compared to AC motors. It is devided pointer) to the next node in the sequence.
three main parts: DC Series Motor; DC Shunt motor;
Cumulative Compound motors. The speed of DC motor
can be controlled in three ways: By varying supply voltage,
the flux and the current through the field winding. This
paper is related to C++ program to represent the changing
velocity displayment. It includes the basic knowledge
about linked list, string, file, time, sorting algorithm,etc.

Keyworks:
Linked list,n_number_sensors(n),t_sampling,(t),t_interval,
speed, node.

I. INDUCTION
 The requirement

D esign and write program(s) in C or C++ with proper


functions and data structure to simulate a speed
sensor mounted on a DC motor with these
specifications: measurement rage: [0;3000] rpm; resolution:
0.2 rpm.

 The idea
In this report, we show a program that creates a data
file including speed of motor in “speed_data” and
processing this information following to
characteristics of them. There are several data
structures used for this task, such as array,stack,hash  Structures
table,etc; however, we choose Linked-List because of This mini project based on parent folder contains three main
its easy and it is suitable to supplied characteristics part:
for enlarge the size of data results. The program can + files of task 1
hadle some error that may occur by displaying a + files of task 2
message and default values when user have incorrect + report.docx
syntax in comment line.

 The solution II. DESIGN, IMPLEMENTATION AND RESULTS

 Linked List
In computer science, a linked list is a linear collection of data  Flowchart Task 1, Task 2
elements, whose order is not given by their physical placement (as figures below)
in memory. Instead, each elements points to the next. It is a  Implementaton And Invaluation Of Results
data structure consisting of a collection of nodes which
a, Task 1
3
Hanoi University of Science and Technology
School of Electrical Engineering, 03 July 2022
continue to check argv[i+1]. If argv[i+1] is satisfied; program
The users can insert the requirement on command window will get that value; otherwise, it will notify corresponding
with optional number of argv but it should be abeyed the error on ‘task1.log’. More than one errors can be represented
correct format: cause of lots of argv[i] here.

; otherwise, it will automatically default values according to + argc=5


this(1;10;1).
A few optional commands can be:
- Case 1: Just 1 or 2 argv(s) e.x

-> notify the errors -> create ‘task1.log’ file with the content + argc=6
like that:

- Case 2: Within 3 argv. In this case; if user insert correctly


two argv: “-n [n_num_sensor]” or “-st [T_sampling]” or “-si
[t_interval]”, program will get this values and two another
data will be actually set default values. Then it also displays
the notification as in case 2. It also occurs when user enter
wrong format for one of 2 argv or both of them.
+ argc=7:

If user insert only “-n” or “-st” or “-si” and after with wrong
format argv, it will represents notify such as:
. A compelete format within 7 argv

- Case 3: Within 4 argv . This case happens two situations:


argv[1] & argv[2] ; argv[2] & argv[3] are selected sensor’s (where n_num_sensors=8;
T_sampling= 20(s); t_interval =1
parameters. Each pairs can be: “-n [n_num_sensor]” or “-st
(hour) )
[T_sampling]” or “-si [t_interval]”. This one parameter will be
=> numbers of line in
set and other parameters will get default values. If occuring
is: 8 * 1 * 3600/ 20 = 2880 ).
any error, they will appear in ‘task1.log’ , such as figure After execution,
below: the program will create a csv
with the content like that:

- Case 5: argc >= 8. The program will display the error


- Case 4: Within 5 argv/ 6 argv / 7 argv. In this case, notification. For example:
algorithm here is checking argv[i]; if it is one of “-n
[n_num_sensor]”; “-st [T_sampling]”; “-si [t_interval]” then
4
Hanoi University of Science and Technology
School of Electrical Engineering, 03 July 2022

b, Task 2

Argorithm: including 6 steps:

# Step 1: reading data -> list node: head

- Open ‘data_speed’ through the argv[1]


- Enter all data from ‘data_speed’ to linked list ‘head’ by
using insertFirst(head)
# Step 4: writeDataStatistics(head)
- Changing data type to be suitable for struct
s(id;time;speed)->(int;string;float) - Dealing with sensor i from 1 to n
# Step 2: writeOutlierData(head) ; using fucntion(node a) - Sensor i: outfile << (id;number of
increment/decrement)
- Checking speed: (a->s.speed <= 900 || a->s.speed
- Where:
>1600); if satisfying -> outfile
+ number of increment though functions:
- Checking sequential for all list (a= a->next)
“countAccelerationSensorK(node a, int k)” travelling all
node that has id of ‘k’; finding delta_speed by difference of
temp_speed_after & temp_speed_before. Checking
(temp_speed_after> temp_speed_before) & (delta_speed
>100) ) then increasing ‘count_acceleration’,
‘count_deceleration’ respectively.

# Step 3: writeDataSummary(head)

- Dealing with sensor i from 1 to n (number of sensors)


- Sensor i:
+ outfile << (id; time;max speed)
+ outfile << (id; time;min speed)
+ outfile << (id;TimeStamp;mean speed)
- Where:
+ time,max speed through functions: # Step 5: writeSortedData(head)
“findTime_MaxSpeedOfEachSensors(a,i)”,
findMaxSpeedOfEachSensors(a, i). In two functions; Using “Bubble Sort Algorithm”. Firstly, arranging all
traveling all node that has ‘i’ id; assigning for ‘max’ sensors that has same id together(becoming easy to
speed; return max,time_temp respectively. sort) -> save to follow_index_List. Secondly, transfer
+ time,min speed are similarly N node of id ‘i’ from ‘follow_index_List’ to
+ TimeStamp through function: ‘temp_List_a’ -> Sorting -> ‘temp_List_b’ -> erase
“find_TimeStamp_In_Hour()” count the difference ‘temp_List_a’ -> erase first N node in
between last node’time and first node’s time(in second ‘follow_index_List’; then dealing with all id from 1->
then transfer to hour) n; then all sorted data saving in ‘temp_List_b’ ->
+ mean speed through function “findAverage(node a, fileout(final step). Using functions
int i)” ; traveling all list, finding sum and increasing + eraiseElement_follow_index_list(node a, node
count-> average value &follow_index_list ): delete first N elements in
“follow_index_list”
+
“transfer_Sorted_List_A_Sorting_To_Temp_List_B
”: transfering sorted data in ‘temp_List_a’ to
‘temp_List_b’
+cutToTemp_List_A_Sorting_Transfer_Temp_List
_B_Then_Write_Sorted_File_And_Time_Duration(
5
Hanoi University of Science and Technology
School of Electrical Engineering, 03 July 2022
node a,node &para_follow_index_list,node
follow_index_list): describles by name itselft (*) Task Description of work Implementer
+ “follow_index_h_list_function(node a, int h, 1. Finding idea Making plan; deviding duties; All
node &follow_index_list )”: inserting all sensor’s finding documents.
within id ‘h’ to ‘follow_index_list’ by reference
+ “writeSortedData(node a)” inserting all sensor ‘h’
from 1 to n to ‘follow_index_list’; calling function (*) - 2. Design From the idea, sketching the Vu Quang
> fileout << ‘temp_List_b’. algorithm program and designing Khai (Leader)
flowchart algorithm flowchart.
# Step 6: writeTask_2_Log()
3.  Task 1 Design based on the Phan Sy Nhat
- Checking ability to open file-> outfile notification requirements of the topic and Tan
- Representing error to ‘task1.log’: finding solution for reading
+ Missing id: if before first ‘,’ is null-> notify error: file; outfile and coding.
"error 2.3: missing data in line " 4. Task 2 Based on flowchart to write Vu Quang
+ Missing time: if occuring ‘,,’ at middle -> notify error algorithm, get and process data. Khai
+ Missing speed: after last character ‘,’ is none-> notify Dealing with outlier, summary,
error statistics, & sorting then
impelementtion based on
linked list.
5. Additional Receive information according Nguyen Thanh
requirement : to task1 & task2; finding error Hung
error. algorithm and

6. Fixing bugs All

7. Report Write a report using a sample All


from IEEE to explain.

IV. REFERENCE
[1] https://www.geeksforgeeks.org/data-structures/linked-list/
[2] https://laptrinhcanban.com/cpp/lap-trinh-cpp-co-ban/file-
trong-cpp/doc-file-trong-cpp-stream/

[3] https://www.geeksforgeeks.org/rand-and-srand-in-ccpp/

[4] https://www.delftstack.com/howto/cpp/how-to-get-time-in-
milliseconds-cpp/

III. TASK ALLOCATIONS


 What have been done and have not been done in our
work:
We have done almost required by the assignment for task
1 and task 2; but file ‘speeed_data’ lack of first line “id,
time, values” & creates ‘task2.log’ doesn’t work very
well.
 Task assigned
6
Hanoi University of Science and Technology
School of Electrical Engineering, 03 July 2022

Flowchart Task 1
7
Hanoi University of Science and Technology
School of Electrical Engineering, 03 July 2022

Flowchart Task 2

You might also like