├── .gitattributes
├── DOC
├── PID_Regulator_Protocol.mht
├── PID_Regulator_Protocol.pdf
└── images
│ ├── PID_Regulator_UI.png
│ └── RM_Logo.png
├── LICENSE
├── PC_UI
├── exe
│ ├── PID_Regulator_V1.0.exe
│ ├── PID_Regulator_V1.2.exe
│ ├── PID_Regulator_V1.21.exe
│ └── PID_Regulator_V1.22.exe
└── src
│ └── PID_Regulator
│ ├── PID_Regulator.pro
│ ├── PID_Regulator.pro.user
│ ├── RM_Logo.ico
│ ├── crc.cpp
│ ├── crc.h
│ ├── image
│ ├── NJUST_Logo.ico
│ ├── RM_Log.png
│ ├── RM_Log_Full.png
│ ├── RM_Logo_Full.ico
│ └── logo_purple_800x800.png
│ ├── main.cpp
│ ├── pid_regulator.cpp
│ ├── pid_regulator.h
│ └── pid_regulator.ui
├── README.md
└── STM32_DEMO
├── V1.0
├── CRC.c
├── CRC.h
├── usart.c
└── usart.h
└── V1.2
├── CRC.c
├── CRC.h
├── usart.c
└── usart.h
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/DOC/PID_Regulator_Protocol.mht:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jackychen227/PID_Regulator/80aa3789602d16181f5fe85cbe94c8ff96396f2c/DOC/PID_Regulator_Protocol.mht
--------------------------------------------------------------------------------
/DOC/PID_Regulator_Protocol.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jackychen227/PID_Regulator/80aa3789602d16181f5fe85cbe94c8ff96396f2c/DOC/PID_Regulator_Protocol.pdf
--------------------------------------------------------------------------------
/DOC/images/PID_Regulator_UI.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jackychen227/PID_Regulator/80aa3789602d16181f5fe85cbe94c8ff96396f2c/DOC/images/PID_Regulator_UI.png
--------------------------------------------------------------------------------
/DOC/images/RM_Logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jackychen227/PID_Regulator/80aa3789602d16181f5fe85cbe94c8ff96396f2c/DOC/images/RM_Logo.png
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 | {one line to give the program's name and a brief idea of what it does.}
635 | Copyright (C) 2018 {name of author}
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | PID_Regulator Copyright (C) 2018 Qingwu Chen
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
--------------------------------------------------------------------------------
/PC_UI/exe/PID_Regulator_V1.0.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jackychen227/PID_Regulator/80aa3789602d16181f5fe85cbe94c8ff96396f2c/PC_UI/exe/PID_Regulator_V1.0.exe
--------------------------------------------------------------------------------
/PC_UI/exe/PID_Regulator_V1.2.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jackychen227/PID_Regulator/80aa3789602d16181f5fe85cbe94c8ff96396f2c/PC_UI/exe/PID_Regulator_V1.2.exe
--------------------------------------------------------------------------------
/PC_UI/exe/PID_Regulator_V1.21.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jackychen227/PID_Regulator/80aa3789602d16181f5fe85cbe94c8ff96396f2c/PC_UI/exe/PID_Regulator_V1.21.exe
--------------------------------------------------------------------------------
/PC_UI/exe/PID_Regulator_V1.22.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jackychen227/PID_Regulator/80aa3789602d16181f5fe85cbe94c8ff96396f2c/PC_UI/exe/PID_Regulator_V1.22.exe
--------------------------------------------------------------------------------
/PC_UI/src/PID_Regulator/PID_Regulator.pro:
--------------------------------------------------------------------------------
1 | #-------------------------------------------------
2 | #
3 | # Project created by QtCreator 2018-05-24T20:53:45
4 | #
5 | #-------------------------------------------------
6 |
7 | QT += core gui
8 | QT += serialport
9 | RC_ICONS = RM_Logo.ico
10 |
11 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
12 |
13 | TARGET = PID_Regulator
14 | TEMPLATE = app
15 |
16 | SOURCES += main.cpp\
17 | pid_regulator.cpp \
18 | crc.cpp
19 |
20 | HEADERS += pid_regulator.h \
21 | crc.h
22 |
23 | FORMS += pid_regulator.ui
24 |
--------------------------------------------------------------------------------
/PC_UI/src/PID_Regulator/PID_Regulator.pro.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | EnvironmentId
7 | {f7bc70bc-1fde-4209-bdfc-91710a034a82}
8 |
9 |
10 | ProjectExplorer.Project.ActiveTarget
11 | 0
12 |
13 |
14 | ProjectExplorer.Project.EditorSettings
15 |
16 | true
17 | false
18 | true
19 |
20 | Cpp
21 |
22 | CppGlobal
23 |
24 |
25 |
26 | QmlJS
27 |
28 | QmlJSGlobal
29 |
30 |
31 | 2
32 | UTF-8
33 | false
34 | 4
35 | false
36 | 80
37 | true
38 | true
39 | 1
40 | true
41 | false
42 | 0
43 | true
44 | true
45 | 0
46 | 8
47 | true
48 | 1
49 | true
50 | true
51 | true
52 | false
53 |
54 |
55 |
56 | ProjectExplorer.Project.PluginSettings
57 |
58 |
59 |
60 | ProjectExplorer.Project.Target.0
61 |
62 | Desktop Qt 5.6.3 MinGW 32bit
63 | Desktop Qt 5.6.3 MinGW 32bit
64 | qt.563.win32_mingw49_kit
65 | 1
66 | 0
67 | 0
68 |
69 | C:/Users/Lenovo/Documents/build-PID_Regulator-Desktop_Qt_5_6_3_MinGW_32bit-Debug
70 |
71 |
72 | true
73 | qmake
74 |
75 | QtProjectManager.QMakeBuildStep
76 | true
77 |
78 | false
79 | false
80 | false
81 |
82 |
83 | true
84 | Make
85 |
86 | Qt4ProjectManager.MakeStep
87 |
88 | false
89 |
90 |
91 |
92 | 2
93 | 构建
94 |
95 | ProjectExplorer.BuildSteps.Build
96 |
97 |
98 |
99 | true
100 | Make
101 |
102 | Qt4ProjectManager.MakeStep
103 |
104 | true
105 | clean
106 |
107 |
108 | 1
109 | 清理
110 |
111 | ProjectExplorer.BuildSteps.Clean
112 |
113 | 2
114 | false
115 |
116 | Debug
117 |
118 | Qt4ProjectManager.Qt4BuildConfiguration
119 | 2
120 | true
121 |
122 |
123 | G:/PID_Regulator/release
124 |
125 |
126 | true
127 | qmake
128 |
129 | QtProjectManager.QMakeBuildStep
130 | false
131 |
132 | false
133 | false
134 | false
135 |
136 |
137 | true
138 | Make
139 |
140 | Qt4ProjectManager.MakeStep
141 |
142 | false
143 |
144 |
145 |
146 | 2
147 | 构建
148 |
149 | ProjectExplorer.BuildSteps.Build
150 |
151 |
152 |
153 | true
154 | Make
155 |
156 | Qt4ProjectManager.MakeStep
157 |
158 | true
159 | clean
160 |
161 |
162 | 1
163 | 清理
164 |
165 | ProjectExplorer.BuildSteps.Clean
166 |
167 | 2
168 | false
169 |
170 | Release
171 |
172 | Qt4ProjectManager.Qt4BuildConfiguration
173 | 0
174 | true
175 |
176 |
177 | C:/Users/Lenovo/Documents/build-PID_Regulator-Desktop_Qt_5_6_3_MinGW_32bit-Profile
178 |
179 |
180 | true
181 | qmake
182 |
183 | QtProjectManager.QMakeBuildStep
184 | true
185 |
186 | false
187 | true
188 | false
189 |
190 |
191 | true
192 | Make
193 |
194 | Qt4ProjectManager.MakeStep
195 |
196 | false
197 |
198 |
199 |
200 | 2
201 | 构建
202 |
203 | ProjectExplorer.BuildSteps.Build
204 |
205 |
206 |
207 | true
208 | Make
209 |
210 | Qt4ProjectManager.MakeStep
211 |
212 | true
213 | clean
214 |
215 |
216 | 1
217 | 清理
218 |
219 | ProjectExplorer.BuildSteps.Clean
220 |
221 | 2
222 | false
223 |
224 | Profile
225 |
226 | Qt4ProjectManager.Qt4BuildConfiguration
227 | 0
228 | true
229 |
230 | 3
231 |
232 |
233 | 0
234 | 部署
235 |
236 | ProjectExplorer.BuildSteps.Deploy
237 |
238 | 1
239 | 在本地部署
240 |
241 | ProjectExplorer.DefaultDeployConfiguration
242 |
243 | 1
244 |
245 |
246 | false
247 | false
248 | 1000
249 |
250 | true
251 |
252 | false
253 | false
254 | false
255 | false
256 | true
257 | 0.01
258 | 10
259 | true
260 | 1
261 | 25
262 |
263 | 1
264 | true
265 | false
266 | true
267 | valgrind
268 |
269 | 0
270 | 1
271 | 2
272 | 3
273 | 4
274 | 5
275 | 6
276 | 7
277 | 8
278 | 9
279 | 10
280 | 11
281 | 12
282 | 13
283 | 14
284 |
285 | 2
286 |
287 | PID_Regulator
288 |
289 | Qt4ProjectManager.Qt4RunConfiguration:G:/PID_Regulator/src/PID_Regulator/PID_Regulator.pro
290 | true
291 |
292 | PID_Regulator.pro
293 | false
294 |
295 | G:/PID_Regulator/release
296 | 3768
297 | false
298 | true
299 | false
300 | false
301 | true
302 |
303 | 1
304 |
305 |
306 |
307 | ProjectExplorer.Project.TargetCount
308 | 1
309 |
310 |
311 | ProjectExplorer.Project.Updater.FileVersion
312 | 18
313 |
314 |
315 | Version
316 | 18
317 |
318 |
319 |
--------------------------------------------------------------------------------
/PC_UI/src/PID_Regulator/RM_Logo.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jackychen227/PID_Regulator/80aa3789602d16181f5fe85cbe94c8ff96396f2c/PC_UI/src/PID_Regulator/RM_Logo.ico
--------------------------------------------------------------------------------
/PC_UI/src/PID_Regulator/crc.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "crc.h"
3 | /************************************帧头CRC8校验**************************************************************/
4 | //crc8 generator polynomial:G(x)=x8+x5+x4+1//生成多项式
5 | const unsigned char CRC8_INIT = 0xff;
6 | const unsigned char CRC8_TAB[256] =
7 | {
8 | 0x00, 0x5e, 0xbc, 0xe2, 0x61, 0x3f, 0xdd, 0x83, 0xc2, 0x9c, 0x7e, 0x20, 0xa3, 0xfd, 0x1f, 0x41,
9 | 0x9d, 0xc3, 0x21, 0x7f, 0xfc, 0xa2, 0x40, 0x1e, 0x5f, 0x01, 0xe3, 0xbd, 0x3e, 0x60, 0x82, 0xdc,
10 | 0x23, 0x7d, 0x9f, 0xc1, 0x42, 0x1c, 0xfe, 0xa0, 0xe1, 0xbf, 0x5d, 0x03, 0x80, 0xde, 0x3c, 0x62,
11 | 0xbe, 0xe0, 0x02, 0x5c, 0xdf, 0x81, 0x63, 0x3d, 0x7c, 0x22, 0xc0, 0x9e, 0x1d, 0x43, 0xa1, 0xff,
12 | 0x46, 0x18, 0xfa, 0xa4, 0x27, 0x79, 0x9b, 0xc5, 0x84, 0xda, 0x38, 0x66, 0xe5, 0xbb, 0x59, 0x07,
13 | 0xdb, 0x85, 0x67, 0x39, 0xba, 0xe4, 0x06, 0x58, 0x19, 0x47, 0xa5, 0xfb, 0x78, 0x26, 0xc4, 0x9a,
14 | 0x65, 0x3b, 0xd9, 0x87, 0x04, 0x5a, 0xb8, 0xe6, 0xa7, 0xf9, 0x1b, 0x45, 0xc6, 0x98, 0x7a, 0x24,
15 | 0xf8, 0xa6, 0x44, 0x1a, 0x99, 0xc7, 0x25, 0x7b, 0x3a, 0x64, 0x86, 0xd8, 0x5b, 0x05, 0xe7, 0xb9,
16 | 0x8c, 0xd2, 0x30, 0x6e, 0xed, 0xb3, 0x51, 0x0f, 0x4e, 0x10, 0xf2, 0xac, 0x2f, 0x71, 0x93, 0xcd,
17 | 0x11, 0x4f, 0xad, 0xf3, 0x70, 0x2e, 0xcc, 0x92, 0xd3, 0x8d, 0x6f, 0x31, 0xb2, 0xec, 0x0e, 0x50,
18 | 0xaf, 0xf1, 0x13, 0x4d, 0xce, 0x90, 0x72, 0x2c, 0x6d, 0x33, 0xd1, 0x8f, 0x0c, 0x52, 0xb0, 0xee,
19 | 0x32, 0x6c, 0x8e, 0xd0, 0x53, 0x0d, 0xef, 0xb1, 0xf0, 0xae, 0x4c, 0x12, 0x91, 0xcf, 0x2d, 0x73,
20 | 0xca, 0x94, 0x76, 0x28, 0xab, 0xf5, 0x17, 0x49, 0x08, 0x56, 0xb4, 0xea, 0x69, 0x37, 0xd5, 0x8b,
21 | 0x57, 0x09, 0xeb, 0xb5, 0x36, 0x68, 0x8a, 0xd4, 0x95, 0xcb, 0x29, 0x77, 0xf4, 0xaa, 0x48, 0x16,
22 | 0xe9, 0xb7, 0x55, 0x0b, 0x88, 0xd6, 0x34, 0x6a, 0x2b, 0x75, 0x97, 0xc9, 0x4a, 0x14, 0xf6, 0xa8,
23 | 0x74, 0x2a, 0xc8, 0x96, 0x15, 0x4b, 0xa9, 0xf7, 0xb6, 0xe8, 0x0a, 0x54, 0xd7, 0x89, 0x6b, 0x35,
24 | };
25 | /*
26 | ** Descriptions: CRC8 checksum function
27 | ** Input: Data to check,Stream length, initialized checksum
28 | ** Output: CRC checksum
29 | */
30 | unsigned char Get_CRC8_Check_Sum(unsigned char *pchMessage,unsigned int dwLength,unsigned char ucCRC8)
31 | {
32 | unsigned char ucIndex;
33 | while (dwLength--)//Stream length
34 | {
35 | ucIndex = ucCRC8^(*pchMessage++);//^位运算:异或
36 | ucCRC8 = CRC8_TAB[ucIndex];
37 | }
38 | return(ucCRC8);//结果
39 | }
40 |
41 | /*
42 | ** Descriptions: CRC8 Verify function
43 | ** Input: Data to Verify,Stream length = Data + checksum
44 | ** Output: True or False (CRC Verify Result)
45 | */
46 |
47 | unsigned int Verify_CRC8_Check_Sum(unsigned char *pchMessage, unsigned int dwLength)
48 | {
49 | unsigned char ucExpected = 0;
50 | if ((pchMessage == 0) || (dwLength <= 2)) return 0;
51 | ucExpected = Get_CRC8_Check_Sum (pchMessage, dwLength-1, CRC8_INIT);
52 | return ( ucExpected == pchMessage[dwLength-1] );
53 | }
54 |
55 | /*
56 | ** Descriptions: append CRC8 to the end of data
57 | ** Input: Data to CRC and append,Stream length = Data + checksum
58 | ** Output: True or False (CRC Verify Result)
59 | */
60 |
61 | void Append_CRC8_Check_Sum(unsigned char *pchMessage, unsigned int dwLength)
62 | {
63 | unsigned char ucCRC = 0;
64 | if ((pchMessage == 0) || (dwLength <= 2)) return;
65 | ucCRC = Get_CRC8_Check_Sum ( (unsigned char *)pchMessage, dwLength-1, CRC8_INIT);
66 | pchMessage[dwLength-1] = ucCRC;
67 | }
68 |
69 |
70 | /************************************数据尾CRC16校验**************************************************************/
71 | uint16_t CRC_INIT = 0xffff;
72 | const uint16_t wCRC_Table[256] =
73 | {
74 | 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
75 | 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
76 | 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
77 | 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
78 | 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
79 | 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
80 | 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
81 | 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
82 | 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
83 | 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
84 | 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
85 | 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
86 | 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
87 | 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
88 | 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
89 | 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
90 | 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
91 | 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
92 | 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
93 | 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
94 | 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
95 | 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
96 | 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
97 | 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
98 | 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
99 | 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
100 | 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
101 | 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
102 | 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
103 | 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
104 | 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
105 | 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
106 | };
107 |
108 | /*
109 | ** Descriptions: CRC16 checksum function
110 | ** Input: Data to check,Stream length, initialized checksum
111 | ** Output: CRC checksum
112 | */
113 |
114 | uint16_t Get_CRC16_Check_Sum(uint8_t *pchMessage,uint32_t dwLength,uint16_t wCRC)
115 | {
116 | uint8_t chData;
117 | if (pchMessage == NULL)
118 | {
119 | return 0xFFFF;
120 | }
121 | while(dwLength--)
122 | {
123 | chData = *pchMessage++;
124 | (wCRC) = ((uint16_t)(wCRC) >> 8) ^ wCRC_Table[((uint16_t)(wCRC) ^(uint16_t)(chData)) & 0x00ff];
125 | }
126 | return wCRC;
127 | }
128 |
129 | /*
130 | ** Descriptions: CRC16 Verify function
131 | ** Input: Data to Verify,Stream length = Data + checksum
132 | ** Output: True or False (CRC Verify Result)
133 | */
134 |
135 | uint32_t Verify_CRC16_Check_Sum(uint8_t *pchMessage, uint32_t dwLength)
136 | {
137 | uint16_t wExpected = 0;
138 | if ((pchMessage == NULL) || (dwLength <= 2))
139 | {
140 | return CRC_Check_False;
141 | }
142 | wExpected = Get_CRC16_Check_Sum ( pchMessage, dwLength - 2, CRC_INIT);
143 | return ((wExpected & 0xff) == pchMessage[dwLength - 2] && ((wExpected >> 8) & 0xff)
144 | == pchMessage[dwLength - 1]);
145 | }
146 | /*
147 | ** Descriptions: append CRC16 to the end of data
148 | ** Input: Data to CRC and append,Stream length = Data + checksum
149 | ** Output: True or False (CRC Verify Result)
150 | */
151 | void Append_CRC16_Check_Sum(uint8_t * pchMessage,uint32_t dwLength)
152 | {
153 | uint16_t wCRC = 0;
154 | if ((pchMessage == NULL) || (dwLength <= 2))
155 | {
156 | return;
157 | }
158 | wCRC = Get_CRC16_Check_Sum ( (unsigned char *)pchMessage, dwLength-2, CRC_INIT );
159 | pchMessage[dwLength-2] = (unsigned char)(wCRC & 0x00ff);
160 | pchMessage[dwLength-1] = (unsigned char)((wCRC >> 8)& 0x00ff);
161 | }
162 |
163 |
164 |
165 | ////函数功能:生成0-255对应的16CRC校验码,其实就是计算机算法1(比特型算法)
166 | ////gEnpoly为生成多项式
167 | ////注意,低位先传送时,生成多项式应反转(低位与高位互换)。如CRC16-CCITT为0x1021,反转后为0x8408
168 | //void mK_cRctable(unsigned short gEnpoly)
169 | //{
170 | // unsigned short cRc_16=0;
171 | // unsigned short i,j,k;
172 | // uint16_t cRctable_16[256];
173 |
174 | // for(i=0,k=0;i<256;i++,k++)
175 | // {
176 | // cRc_16 = i<<8;
177 | // for(j=8;j>0;j--)
178 | // {
179 | // if(cRc_16&0x8000) //反转时cRc_16&0x0001
180 | // cRc_16=(cRc_16<<=1)^gEnpoly; //反转时cRc_16=(cRc_16>>=1)^gEnpoly
181 | // else
182 | // cRc_16<<=1; //反转时cRc_16>>=1
183 | // }
184 | // cRctable_16[k] = cRc_16;
185 | // }
186 | //}
187 |
--------------------------------------------------------------------------------
/PC_UI/src/PID_Regulator/crc.h:
--------------------------------------------------------------------------------
1 | #ifndef CRC_H
2 | #define CRC_H
3 |
4 | #define CRC_Check_False 0
5 | #define CRC_Check_True 1
6 |
7 |
8 | unsigned char Get_CRC8_Check_Sum(unsigned char *pchMessage,unsigned int dwLength,unsigned char ucCRC8);
9 | unsigned int Verify_CRC8_Check_Sum(unsigned char *pchMessage, unsigned int dwLength);
10 | void Append_CRC8_Check_Sum(unsigned char *pchMessage, unsigned int dwLength);
11 |
12 | uint16_t Get_CRC16_Check_Sum(uint8_t *pchMessage,uint32_t dwLength,uint16_t wCRC);
13 | uint32_t Verify_CRC16_Check_Sum(uint8_t *pchMessage, uint32_t dwLength);
14 | void Append_CRC16_Check_Sum(uint8_t * pchMessage,uint32_t dwLength);
15 |
16 | #endif // CRC_H
17 |
--------------------------------------------------------------------------------
/PC_UI/src/PID_Regulator/image/NJUST_Logo.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jackychen227/PID_Regulator/80aa3789602d16181f5fe85cbe94c8ff96396f2c/PC_UI/src/PID_Regulator/image/NJUST_Logo.ico
--------------------------------------------------------------------------------
/PC_UI/src/PID_Regulator/image/RM_Log.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jackychen227/PID_Regulator/80aa3789602d16181f5fe85cbe94c8ff96396f2c/PC_UI/src/PID_Regulator/image/RM_Log.png
--------------------------------------------------------------------------------
/PC_UI/src/PID_Regulator/image/RM_Log_Full.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jackychen227/PID_Regulator/80aa3789602d16181f5fe85cbe94c8ff96396f2c/PC_UI/src/PID_Regulator/image/RM_Log_Full.png
--------------------------------------------------------------------------------
/PC_UI/src/PID_Regulator/image/RM_Logo_Full.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jackychen227/PID_Regulator/80aa3789602d16181f5fe85cbe94c8ff96396f2c/PC_UI/src/PID_Regulator/image/RM_Logo_Full.ico
--------------------------------------------------------------------------------
/PC_UI/src/PID_Regulator/image/logo_purple_800x800.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jackychen227/PID_Regulator/80aa3789602d16181f5fe85cbe94c8ff96396f2c/PC_UI/src/PID_Regulator/image/logo_purple_800x800.png
--------------------------------------------------------------------------------
/PC_UI/src/PID_Regulator/main.cpp:
--------------------------------------------------------------------------------
1 | #include "pid_regulator.h"
2 | #include
3 |
4 | int main(int argc, char *argv[])
5 | {
6 | QApplication a(argc, argv);
7 | PID_Regulator w;
8 | w.show();
9 |
10 | return a.exec();
11 | }
12 |
--------------------------------------------------------------------------------
/PC_UI/src/PID_Regulator/pid_regulator.cpp:
--------------------------------------------------------------------------------
1 | #include "pid_regulator.h"
2 | #include "ui_pid_regulator.h"
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | #include "crc.h"
11 |
12 | PID_Regulator::PID_Regulator(QWidget *parent) :
13 | QWidget(parent),
14 | ui(new Ui::PID_Regulator)
15 | {
16 | ui->setupUi(this);
17 | emit checkAvailablePorts();
18 | emit setKpValue();
19 | emit setKiValue();
20 | emit setKdValue();
21 | }
22 |
23 | PID_Regulator::~PID_Regulator()
24 | {
25 | delete ui;
26 | }
27 | //非阻塞延时
28 | void PID_Regulator::Delay_MSec(unsigned int msec)
29 | {
30 | QTime _timer = QTime::currentTime().addMSecs(msec);
31 | while(QTime::currentTime() < _timer)
32 | QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
33 | }
34 | //阻塞延时
35 | //void PID_Regulator::Delay_MSec_Suspend(unsigned int msec)
36 | //{
37 | // QTime _timer = QTime::currentTime();
38 | // QTime _NowTimer;
39 | // do{
40 | // _NowTimer = QTime::currentTime();
41 | // }while(_timer.msecsTo(_NowTimer) <= msec);
42 | //}
43 |
44 | void PID_Regulator::setBaudRate()
45 | {
46 | qDebug() << "comboBox_baudRate->currentText():" << ui->comboBox_baudRate->currentText() << endl;
47 | if(portIsOpen)
48 | {
49 |
50 | if(ui->comboBox_baudRate->currentText() == "115200")
51 | mySerialPort->setBaudRate(QSerialPort::Baud115200);
52 | else if(ui->comboBox_baudRate->currentText() == "57600")
53 | mySerialPort->setBaudRate(QSerialPort::Baud57600);
54 | else if(ui->comboBox_baudRate->currentText() == "38400")
55 | mySerialPort->setBaudRate(QSerialPort::Baud38400);
56 | else if(ui->comboBox_baudRate->currentText() == "19200")
57 | mySerialPort->setBaudRate(QSerialPort::Baud19200);
58 | else if(ui->comboBox_baudRate->currentText() == "9600")
59 | mySerialPort->setBaudRate(QSerialPort::Baud9600);
60 | else if(ui->comboBox_baudRate->currentText() == "4800")
61 | mySerialPort->setBaudRate(QSerialPort::Baud4800);
62 | else if(ui->comboBox_baudRate->currentText() == "2400")
63 | mySerialPort->setBaudRate(QSerialPort::Baud2400);
64 | else if(ui->comboBox_baudRate->currentText() == "1200")
65 | mySerialPort->setBaudRate(QSerialPort::Baud1200);
66 | }
67 | }
68 |
69 | void PID_Regulator::setParity()
70 | {
71 | qDebug() << "ui->comboBox_parity->currentText():" << ui->comboBox_parity->currentText() << endl;
72 | if (portIsOpen)
73 | {
74 | if (ui->comboBox_parity->currentText() == QString::fromLocal8Bit("无校验"))
75 | mySerialPort->setParity(QSerialPort::NoParity);
76 | else if (ui->comboBox_parity->currentText() == QString::fromLocal8Bit("奇校验"))
77 | mySerialPort->setParity(QSerialPort::OddParity);
78 | else if (ui->comboBox_parity->currentText() == QString::fromLocal8Bit("偶校验"))
79 | mySerialPort->setParity(QSerialPort::EvenParity);
80 | }
81 | }
82 |
83 | void PID_Regulator::setDataBits()
84 | {
85 | if (portIsOpen)
86 | {
87 | if (ui->comboBox_wordLength->currentText() == "8")
88 | mySerialPort->setDataBits(QSerialPort::Data8);
89 | else if (ui->comboBox_wordLength->currentText() == "7")
90 | mySerialPort->setDataBits(QSerialPort::Data7);
91 | else if (ui->comboBox_wordLength->currentText() == "6")
92 | mySerialPort->setDataBits(QSerialPort::Data6);
93 | else if (ui->comboBox_wordLength->currentText() == "5")
94 | mySerialPort->setDataBits(QSerialPort::Data5);
95 | }
96 | }
97 |
98 | void PID_Regulator::setStopBits()
99 | {
100 | if (portIsOpen)
101 | {
102 | if (ui->comboBox_stopBits->currentText() == "1")
103 | mySerialPort->setStopBits(QSerialPort::OneStop);
104 | else if (ui->comboBox_stopBits->currentText() == "1.5")
105 | mySerialPort->setStopBits(QSerialPort::OneAndHalfStop);
106 | else if (ui->comboBox_stopBits->currentText() == "2")
107 | mySerialPort->setStopBits(QSerialPort::TwoStop);
108 | }
109 | }
110 |
111 | void PID_Regulator::setFlowCtrl()
112 | {
113 | if (portIsOpen)
114 | {
115 | if (ui->comboBox_flowCtl->currentText() == "off")
116 | mySerialPort->setFlowControl(QSerialPort::NoFlowControl);
117 | else if (ui->comboBox_flowCtl->currentText() == "hardware")
118 | mySerialPort->setFlowControl(QSerialPort::HardwareControl);
119 | else if (ui->comboBox_flowCtl->currentText() == "xonxoff")
120 | mySerialPort->setFlowControl(QSerialPort::SoftwareControl);
121 | }
122 | }
123 |
124 | void PID_Regulator::checkAvailablePorts()
125 | {
126 | foreach (const QSerialPortInfo &Info, QSerialPortInfo::availablePorts())
127 | {
128 | // qDebug() << Info.portName() << endl;
129 | QSerialPort availablePort;
130 | availablePort.setPortName(Info.portName());
131 | qDebug() << "availablePort.portName():" <comboBox_portName->setItemText(0, Info.portName());
137 | ui->comboBox_portName->setCurrentIndex(0);
138 | availablePort.close();
139 | }
140 | }
141 | }
142 |
143 | void PID_Regulator::serialSwitch()
144 | {
145 | emit checkAvailablePorts();
146 | static bool checked = true;
147 | qDebug() << checked << endl;
148 | if (checked == true)
149 | {
150 |
151 | checked = false;
152 | mySerialPort = new QSerialPort(this);
153 | QString tempStr = ui->comboBox_portName->currentText();
154 | mySerialPort->setPortName(tempStr);
155 | if (mySerialPort->open(QIODevice::ReadWrite))
156 | {
157 | portIsOpen = true;
158 | emit setBaudRate();
159 | emit setParity();
160 | emit setDataBits();
161 | emit setStopBits();
162 | emit setFlowCtrl();
163 | ui->pushButton_serialSwitch->setText(QString::fromLocal8Bit("Close"));
164 | ui->textBrowser_log->append(QTime::currentTime().toString()+" Open the serial port successfully!");
165 | connect(mySerialPort, SIGNAL(readyRead()), this, SLOT(readMyCom()));
166 | }
167 | else
168 | {
169 | ui->pushButton_serialSwitch->setChecked(false);
170 | QMessageBox::warning(this,\
171 | QString::fromLocal8Bit("Warning"),\
172 | QString::fromLocal8Bit("No serial USB detected!"),
173 | QMessageBox::Cancel);
174 | }
175 | }
176 | else
177 | {
178 | checked = true;
179 | portIsOpen = false;
180 | if (mySerialPort->isOpen())
181 | {
182 | mySerialPort->close();
183 | ui->textBrowser_log->append(QTime::currentTime().toString()+" Close the serial port successfully!");
184 | }
185 | ui->pushButton_serialSwitch->setText(QString::fromLocal8Bit("Open"));
186 | }
187 | }
188 |
189 | typedef struct{
190 | unsigned char motor_ID;
191 | unsigned char PID_Mode;//增量式:1;位置式:0
192 | union{
193 | unsigned char tempChar[4];
194 | float tempFloat;
195 | }Kp_value;
196 | union{
197 | unsigned char tempChar[4];
198 | float tempFloat;
199 | }Ki_value;
200 | union{
201 | unsigned char tempChar[4];
202 | float tempFloat;
203 | }Kd_value;
204 | union{
205 | unsigned char tempChar[4];
206 | float tempFloat;
207 | }P_out_max;
208 | union{
209 | unsigned char tempChar[4];
210 | float tempFloat;
211 | }I_out_max;
212 | union{
213 | unsigned char tempChar[4];
214 | float tempFloat;
215 | }D_out_max;
216 | union{
217 | unsigned char tempChar[4];
218 | float tempFloat;
219 | }PID_out_max;
220 | }PID_struct;
221 |
222 | typedef struct{
223 | unsigned char SOF;
224 | unsigned char Data_Length;
225 | unsigned char seq;
226 | unsigned char crc8;
227 | unsigned char cmd_ID;
228 | PID_struct PID;
229 | union{
230 | unsigned char tempChar[2];
231 | int tempInt;
232 | }crc16;
233 | }MsgsFrame_struct;
234 | MsgsFrame_struct query;
235 | MsgsFrame_struct set;
236 | QByteArray serialReceiveMsgs;
237 | void PID_Regulator::readMyCom()
238 | {
239 | QByteArray temp = mySerialPort->readAll();
240 | if(!temp.isEmpty())
241 | {
242 | serialReceiveMsgs.append(temp);
243 | if(serialReceiveMsgs.length() == 37)
244 | {
245 | unsigned char * receiveData = (unsigned char *)serialReceiveMsgs.data();
246 | qDebug() << "serialReceiveMsgs.length()" << serialReceiveMsgs.length() << endl;
247 | serialReceiveMsgs.clear();
248 | if(Verify_CRC8_Check_Sum(receiveData,4))
249 | {
250 | qDebug() << "CRC8_Check_OK" << endl;
251 | if(Verify_CRC16_Check_Sum(receiveData,serialReceiveMsgs.length()))
252 | {
253 | qDebug() << "CRC16_Check_OK" << endl;
254 | }
255 | query.SOF = *receiveData++;
256 | query.Data_Length = *receiveData++;
257 | query.seq = *receiveData++;
258 | query.crc8 = *receiveData++;
259 | query.cmd_ID = *receiveData++;
260 | qDebug() << "SOF_query" << query.SOF << endl;
261 | qDebug() << "Data_Length_query" << query.Data_Length << endl;
262 |
263 | query.PID.motor_ID = *receiveData++;
264 | query.PID.PID_Mode = *receiveData++;
265 | qDebug() << "motor_ID_query" << query.PID.motor_ID << endl;
266 | qDebug() << "PID_Mode_query" << query.PID.PID_Mode << endl;
267 | int i=0;
268 | for(i=0;i<4;i++) query.PID.Kp_value.tempChar[i] = *receiveData++;
269 | for(i=0;i<4;i++) query.PID.Ki_value.tempChar[i] = *receiveData++;
270 | for(i=0;i<4;i++) query.PID.Kd_value.tempChar[i] = *receiveData++;
271 | for(i=0;i<4;i++) query.PID.P_out_max.tempChar[i] = *receiveData++;
272 | for(i=0;i<4;i++) query.PID.I_out_max.tempChar[i] = *receiveData++;
273 | for(i=0;i<4;i++) query.PID.D_out_max.tempChar[i] = *receiveData++;
274 | for(i=0;i<4;i++) query.PID.PID_out_max.tempChar[i] = *receiveData++;
275 |
276 | for(i=0;i<2;i++) query.crc16.tempChar[i] = *receiveData++;
277 |
278 | ui->comboBox_motor_ID->setCurrentIndex(query.PID.motor_ID);
279 | ui->comboBox_PID_Mode->setCurrentIndex(query.PID.PID_Mode);
280 | ui->lineEdit_KpValue->setText(QString("%1").arg(query.PID.Kp_value.tempFloat));
281 | ui->lineEdit_KiValue->setText(QString("%1").arg(query.PID.Ki_value.tempFloat));
282 | ui->lineEdit_KdValue->setText(QString("%1").arg(query.PID.Kd_value.tempFloat));
283 | ui->lineEdit_Pout_MAX->setText(QString("%1").arg(query.PID.P_out_max.tempFloat));
284 | ui->lineEdit_Iout_MAX->setText(QString("%1").arg(query.PID.I_out_max.tempFloat));
285 | ui->lineEdit_Dout_MAX->setText(QString("%1").arg(query.PID.D_out_max.tempFloat));
286 | ui->lineEdit_PIDout_MAX->setText(QString("%1").arg(query.PID.PID_out_max.tempFloat));
287 |
288 | ui->textBrowser_log->append(QTime::currentTime().toString() + "PID参数如下:");
289 | ui->textBrowser_log->append("motor_ID: "+QString("%1").arg(query.PID.motor_ID));
290 | query.PID.PID_Mode == 1 ? ui->textBrowser_log->append("PID_Mode:增量式")\
291 | :ui->textBrowser_log->append("PID_Mode:位置式");
292 | ui->textBrowser_log->append("Kp_value = "+QString("%1").arg(query.PID.Kp_value.tempFloat));
293 | ui->textBrowser_log->append("Ki_value = "+QString("%1").arg(query.PID.Ki_value.tempFloat));
294 | ui->textBrowser_log->append("Kd_value = "+QString("%1").arg(query.PID.Kd_value.tempFloat));
295 | ui->textBrowser_log->append("P_out_max = "+QString("%1").arg(query.PID.P_out_max.tempFloat));
296 | ui->textBrowser_log->append("I_out_max = "+QString("%1").arg(query.PID.I_out_max.tempFloat));
297 | ui->textBrowser_log->append("D_out_max = "+QString("%1").arg(query.PID.D_out_max.tempFloat));
298 | ui->textBrowser_log->append("PID_out_max = "+QString("%1").arg(query.PID.PID_out_max.tempFloat));
299 | }
300 |
301 | }
302 | }
303 |
304 | }
305 |
306 | void PID_Regulator::setKpValue()
307 | {
308 | QString tempStr;
309 | float tempNum1, tempNum2;
310 | tempStr = ui->lineEdit_KpScale->text();
311 | tempNum1 = tempStr.toULong();
312 | tempNum2 = ui->horizontalSlider_Kp->value();
313 | tempNum1 *= tempNum2;
314 | tempStr = QString("%1").arg(tempNum1/10000);
315 | ui->lineEdit_KpValue->setText(tempStr);
316 | }
317 |
318 | void PID_Regulator::setKiValue()
319 | {
320 | QString tempStr;
321 | float tempNum1, tempNum2;
322 | tempStr = ui->lineEdit_KiScale->text();
323 | tempNum1 = tempStr.toULong();
324 | tempNum2 = ui->horizontalSlider_Ki->value();
325 | tempNum1 *= tempNum2;
326 | tempStr = QString("%1").arg(tempNum1/10000);
327 | ui->lineEdit_KiValue->setText(tempStr);
328 | }
329 |
330 | void PID_Regulator::setKdValue()
331 | {
332 | QString tempStr;
333 | float tempNum1, tempNum2;
334 | tempStr = ui->lineEdit_KdScale->text();
335 | tempNum1 = tempStr.toULong();
336 | tempNum2 = ui->horizontalSlider_Kd->value();
337 | tempNum1 *= tempNum2;
338 | tempStr = QString("%1").arg(tempNum1/10000);
339 | ui->lineEdit_KdValue->setText(tempStr);
340 | }
341 |
342 | void PID_Regulator::setKpSliderValue()
343 | {
344 | QString tempStr;
345 | float tempNum1, tempNum2;
346 | tempStr = ui->lineEdit_KpScale->text();
347 | tempNum1 = tempStr.toULong();
348 | tempStr = ui->lineEdit_KpValue->text();
349 | tempNum2 = tempStr.toFloat();
350 | tempNum2 = tempNum2*10000/tempNum1;
351 | ui->horizontalSlider_Kp->setValue((int)tempNum2);
352 | }
353 |
354 | void PID_Regulator::setKiSliderValue()
355 | {
356 | QString tempStr;
357 | float tempNum1, tempNum2;
358 | tempStr = ui->lineEdit_KiScale->text();
359 | tempNum1 = tempStr.toULong();
360 | tempStr = ui->lineEdit_KiValue->text();
361 | tempNum2 = tempStr.toFloat();
362 | tempNum2 = tempNum2*10000/tempNum1;
363 | ui->horizontalSlider_Ki->setValue((int)tempNum2);
364 | }
365 |
366 | void PID_Regulator::setKdSliderValue()
367 | {
368 | QString tempStr;
369 | float tempNum1, tempNum2;
370 | tempStr = ui->lineEdit_KdScale->text();
371 | tempNum1 = tempStr.toULong();
372 | tempStr = ui->lineEdit_KdValue->text();
373 | tempNum2 = tempStr.toFloat();
374 | tempNum2 = tempNum2*10000/tempNum1;
375 | ui->horizontalSlider_Kd->setValue((int)tempNum2);
376 | }
377 |
378 | union{
379 | char byte[4];
380 | float floatValue;
381 | }uF2C;
382 | #define SOF 0xA5
383 | #define DATA_LENGTH_SET_PID_PATAMS 30
384 | #define CMD_ID_SET_PID_PATAMS 0x01
385 |
386 | #define DATA_LENGTH_QUERY_PID_PATAMS 1
387 | #define CMD_ID_QUERY_PID_PATAMS 0x00
388 | void PID_Regulator::setPIDParams()
389 | {
390 | QByteArray sendData;
391 | //帧开头
392 | unsigned char j = 0;
393 | sendData[j++] = SOF;
394 | sendData[j++] = DATA_LENGTH_SET_PID_PATAMS;
395 | static unsigned char seq = 0;
396 | sendData[j++] = seq;
397 | seq++;
398 | //crc8
399 | unsigned char * tempData = (unsigned char *)sendData.data();
400 | unsigned char crc8 = Get_CRC8_Check_Sum(tempData,j,0xff);
401 | qDebug() << "crc8" << crc8 << endl;
402 | for(int i = 0; icomboBox_motor_ID->currentText();
412 | sendData[j++] = motorID.toUShort();
413 | //PID_Mode
414 | char pidMode = ui->comboBox_PID_Mode->currentIndex();
415 | sendData[j++] = pidMode;
416 |
417 | QString tempStr;
418 | for(int i=0;i<4;i++)
419 | {
420 | uF2C.byte[i] = i;
421 | }
422 | qDebug() << "iiiii" << uF2C.floatValue << endl;
423 |
424 | //KpValue
425 | tempStr = ui->lineEdit_KpValue->text();
426 | float KpValue = tempStr.toFloat();
427 | uF2C.floatValue = KpValue;
428 | for(int i=0;i<4;i++) sendData[j++] = uF2C.byte[i];
429 | qDebug() << "lineEdit_KpValue" << uF2C.floatValue << endl;
430 | //KiValue
431 | tempStr = ui->lineEdit_KiValue->text();
432 | float KiValue = tempStr.toFloat();
433 | uF2C.floatValue = KiValue;
434 | for(int i=0;i<4;i++) sendData[j++] = uF2C.byte[i];
435 | qDebug() << "lineEdit_KiValue" << uF2C.floatValue << endl;
436 | //KdValue
437 | tempStr = ui->lineEdit_KdValue->text();
438 | float KdValue = tempStr.toFloat();
439 | uF2C.floatValue = KdValue;
440 | for(int i=0;i<4;i++) sendData[j++] = uF2C.byte[i];
441 | qDebug() << "lineEdit_KdValue" << uF2C.floatValue << endl;
442 | //Pout_MAX
443 | tempStr = ui->lineEdit_Pout_MAX->text();
444 | float Pout_MAX = tempStr.toFloat();
445 | uF2C.floatValue = Pout_MAX;
446 | for(int i=0;i<4;i++) sendData[j++] = uF2C.byte[i];
447 | qDebug() << "Pout_MAX" << uF2C.floatValue << endl;
448 | //Iout_MAX
449 | tempStr = ui->lineEdit_Iout_MAX->text();
450 | float Iout_MAX = tempStr.toFloat();
451 | uF2C.floatValue = Iout_MAX;
452 | for(int i=0;i<4;i++) sendData[j++] = uF2C.byte[i];
453 | qDebug() << "Iout_MAX" << uF2C.floatValue << endl;
454 | //Dout_MAX
455 | tempStr = ui->lineEdit_Dout_MAX->text();
456 | float Dout_MAX = tempStr.toFloat();
457 | uF2C.floatValue = Dout_MAX;
458 | for(int i=0;i<4;i++) sendData[j++] = uF2C.byte[i];
459 | qDebug() << "Dout_MAX" << uF2C.floatValue << endl;
460 | //PID_out_max
461 | tempStr = ui->lineEdit_PIDout_MAX->text();
462 | float PIDout_MAX = tempStr.toFloat();
463 | uF2C.floatValue = PIDout_MAX;
464 | for(int i=0;i<4;i++) sendData[j++] = uF2C.byte[i];
465 | qDebug() << "PIDout_MAX" << uF2C.floatValue << endl;
466 | //crc16
467 | qDebug() << "jj" << j << endl;
468 | qDebug() << "sendData.length()" << sendData.length() << endl;
469 |
470 | unsigned char * ttempData = (unsigned char *)sendData.data();
471 | uint16_t crc16 = Get_CRC16_Check_Sum(ttempData,j,0xffff);
472 | qDebug() << "crc16" << crc16 << endl;
473 | char crc16_L = crc16&0xff;
474 | char crc16_H = (crc16>>8)&0xff;
475 | // qDebug() << "crc16_L" << crc16_L << endl;
476 | // qDebug() << "crc16_H" << crc16_H << endl;
477 | sendData[j++] = crc16_L;
478 | sendData[j] = crc16_H;
479 |
480 | qDebug() << "sendData.length()" << sendData.length() << endl;
481 | qDebug() << "jj" << j << endl;
482 | qDebug() << "sendData" << sendData << endl;
483 | if(portIsOpen == true)
484 | {
485 | // ui->textBrowser_log->append("Sending the PID params!");
486 | ui->textBrowser_log->append(QTime::currentTime().toString()+" 正在设置PID参数...");
487 | unsigned char i = 3;
488 | while(i)
489 | {
490 | i--;
491 | mySerialPort->write(sendData);
492 | // Delay_MSec(2);
493 | }
494 | // mySerialPort->write(sendData);
495 | }
496 | }
497 |
498 | void PID_Regulator::queryPIDParams()
499 | {
500 | QByteArray sendData;
501 | //帧开头
502 | unsigned char j = 0;
503 | sendData[j++] = SOF;
504 | // qDebug() << "j" << j << endl;
505 | sendData[j++] = DATA_LENGTH_QUERY_PID_PATAMS;
506 | // qDebug() << "j" << j << endl;
507 | static unsigned char seq = 0;
508 | sendData[j++] = seq;
509 | seq++;
510 | //crc8
511 | unsigned char * tempData = (unsigned char *)sendData.data();
512 | unsigned char crc8 = Get_CRC8_Check_Sum(tempData,j,0xff);//TODO
513 | qDebug() << "crc8" << crc8 << endl;
514 | for(int i = 0; icomboBox_motor_ID->currentText();
524 | sendData[j++] = motorID.toUShort();
525 |
526 | //crc16
527 | unsigned char * ttempData = (unsigned char *)sendData.data();
528 | uint16_t crc16 = Get_CRC16_Check_Sum(ttempData,j,0xffff);
529 | qDebug() << "crc16" << crc16 << endl;
530 | char crc16_H = (crc16>>8)&0x00ff;
531 | char crc16_L = crc16&0x00ff;
532 | sendData[j++] = crc16_L;
533 | sendData[j] = crc16_H;
534 |
535 | qDebug() << "sendData.length()" << sendData.length() << endl;
536 | qDebug() << "sendData" << sendData << endl;
537 |
538 | if(portIsOpen == true)
539 | {
540 | // ui->textBrowser_log->append("Querying the PID params!");
541 | // ui->textBrowser_log->append(QTime::currentTime().toString());
542 | ui->textBrowser_log->append(QTime::currentTime().toString()+" 正在查询板载PID参数...");
543 | unsigned char i = 3;
544 | while(i)
545 | {
546 | i--;
547 | mySerialPort->write(sendData);
548 | // Delay_MSec(2);
549 | }
550 | // mySerialPort->write(sendData);
551 | }
552 | }
553 |
--------------------------------------------------------------------------------
/PC_UI/src/PID_Regulator/pid_regulator.h:
--------------------------------------------------------------------------------
1 | #ifndef PID_REGULATOR_H
2 | #define PID_REGULATOR_H
3 |
4 | #include
5 | #include "pid_regulator.h"
6 | #include "ui_pid_regulator.h"
7 | class SerialPortSetting;
8 | class QSerialPort;
9 |
10 | namespace Ui {
11 | class PID_Regulator;
12 | }
13 |
14 | class PID_Regulator : public QWidget
15 | {
16 | Q_OBJECT
17 |
18 | public:
19 | explicit PID_Regulator(QWidget *parent = 0);
20 | ~PID_Regulator();
21 | void Delay_MSec(unsigned int msec);
22 | // void Delay_MSec_Suspend(unsigned int msec);
23 |
24 | private:
25 | Ui::PID_Regulator *ui;
26 | bool portIsOpen = false;
27 | QSerialPort* mySerialPort;
28 | public slots:
29 | void setBaudRate();
30 | void setParity();
31 | void setDataBits();
32 | void setStopBits();
33 | void setFlowCtrl();
34 | void checkAvailablePorts();
35 |
36 | void serialSwitch();
37 | void queryPIDParams();
38 | void setPIDParams();
39 | void readMyCom();
40 |
41 | void setKpValue();
42 | void setKiValue();
43 | void setKdValue();
44 | void setKpSliderValue();
45 | void setKiSliderValue();
46 | void setKdSliderValue();
47 | };
48 |
49 | #endif // PID_REGULATOR_H
50 |
--------------------------------------------------------------------------------
/PC_UI/src/PID_Regulator/pid_regulator.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | PID_Regulator
4 |
5 |
6 |
7 | 0
8 | 0
9 | 550
10 | 581
11 |
12 |
13 |
14 | PID_Regulator
15 |
16 |
17 |
18 | RM_Logo.icoRM_Logo.ico
19 |
20 |
21 | 1.000000000000000
22 |
23 |
24 |
25 |
26 | 10
27 | 20
28 | 151
29 | 221
30 |
31 |
32 |
33 | 串口设置
34 |
35 |
36 |
37 |
38 | 11
39 | 20
40 | 133
41 | 195
42 |
43 |
44 |
45 | -
46 |
47 |
-
48 |
49 |
50 | 串口号
51 |
52 |
53 |
54 | -
55 |
56 |
57 |
58 | 75
59 | 0
60 |
61 |
62 |
-
63 |
64 | COM0
65 |
66 |
67 | -
68 |
69 | COM1
70 |
71 |
72 | -
73 |
74 | COM2
75 |
76 |
77 | -
78 |
79 | COM3
80 |
81 |
82 | -
83 |
84 | COM4
85 |
86 |
87 | -
88 |
89 | COM5
90 |
91 |
92 | -
93 |
94 | COM6
95 |
96 |
97 | -
98 |
99 | COM7
100 |
101 |
102 | -
103 |
104 | COM8
105 |
106 |
107 | -
108 |
109 | COM9
110 |
111 |
112 |
113 |
114 |
115 |
116 | -
117 |
118 |
-
119 |
120 |
121 | 波特率
122 |
123 |
124 |
125 | -
126 |
127 |
128 |
129 | 75
130 | 0
131 |
132 |
133 |
-
134 |
135 | 115200
136 |
137 |
138 | -
139 |
140 | 57600
141 |
142 |
143 | -
144 |
145 | 38400
146 |
147 |
148 | -
149 |
150 | 19200
151 |
152 |
153 | -
154 |
155 | 9600
156 |
157 |
158 | -
159 |
160 | 4800
161 |
162 |
163 | -
164 |
165 | 2400
166 |
167 |
168 | -
169 |
170 | 1200
171 |
172 |
173 |
174 |
175 |
176 |
177 | -
178 |
179 |
-
180 |
181 |
182 | 停止位
183 |
184 |
185 |
186 | -
187 |
188 |
189 |
190 | 75
191 | 0
192 |
193 |
194 |
-
195 |
196 | 1
197 |
198 |
199 | -
200 |
201 | 1.5
202 |
203 |
204 | -
205 |
206 | 2
207 |
208 |
209 |
210 |
211 |
212 |
213 | -
214 |
215 |
-
216 |
217 |
218 | 数据位
219 |
220 |
221 |
222 | -
223 |
224 |
225 |
226 | 75
227 | 0
228 |
229 |
230 |
-
231 |
232 | 8
233 |
234 |
235 | -
236 |
237 | 7
238 |
239 |
240 | -
241 |
242 | 6
243 |
244 |
245 | -
246 |
247 | 5
248 |
249 |
250 |
251 |
252 |
253 |
254 | -
255 |
256 |
-
257 |
258 |
259 | 奇偶校验
260 |
261 |
262 |
263 | -
264 |
265 |
266 |
267 | 75
268 | 0
269 |
270 |
271 |
-
272 |
273 | 无
274 |
275 |
276 | -
277 |
278 | 奇校验
279 |
280 |
281 | -
282 |
283 | 偶校验
284 |
285 |
286 |
287 |
288 |
289 |
290 | -
291 |
292 |
-
293 |
294 |
295 | 流控制
296 |
297 |
298 |
299 | -
300 |
301 |
302 |
303 | 75
304 | 0
305 |
306 |
307 |
-
308 |
309 | OFF
310 |
311 |
312 | -
313 |
314 | ON
315 |
316 |
317 |
318 |
319 |
320 |
321 | -
322 |
323 |
-
324 |
325 |
326 | 串口操作
327 |
328 |
329 |
330 | -
331 |
332 |
333 |
334 | 70
335 | 0
336 |
337 |
338 |
339 | Open
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 | 170
352 | 20
353 | 371
354 | 221
355 |
356 |
357 |
358 |
359 | 16777215
360 | 16777215
361 |
362 |
363 |
364 | 日志
365 |
366 |
367 |
368 |
369 | 10
370 | 20
371 | 351
372 | 191
373 |
374 |
375 |
376 | -
377 |
378 |
379 |
380 | 16777215
381 | 16777215
382 |
383 |
384 |
385 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
386 | <html><head><meta name="qrichtext" content="1" /><style type="text/css">
387 | p, li { white-space: pre-wrap; }
388 | </style></head><body style=" font-family:'SimSun'; font-size:9pt; font-weight:400; font-style:normal;">
389 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt; font-weight:600;">PID_Regulator V1.2</span></p>
390 | <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-weight:600;"><br /></p>
391 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">南京理工大学</span></p>
392 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">Alliance战队</span></p>
393 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">我来!我见!我征服!</span></p>
394 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">作者:chenqingwu@njust.edu.cn</span></p>
395 | <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html>
396 |
397 |
398 |
399 | -
400 |
401 |
-
402 |
403 |
404 | 清除
405 |
406 |
407 |
408 | -
409 |
410 |
411 | true
412 |
413 |
414 | 查询板载PID参数
415 |
416 |
417 |
418 | -
419 |
420 |
421 | 设置PID参数
422 |
423 |
424 |
425 |
426 |
427 |
428 |
429 |
430 |
431 |
432 |
433 | 10
434 | 250
435 | 531
436 | 321
437 |
438 |
439 |
440 | PID Dynamic Reconfigure
441 |
442 |
443 |
444 |
445 | 10
446 | 60
447 | 511
448 | 81
449 |
450 |
451 |
452 | Proportion
453 |
454 |
455 |
456 |
457 | 10
458 | 20
459 | 498
460 | 56
461 |
462 |
463 |
464 | -
465 |
466 |
-
467 |
468 |
469 |
470 | 30
471 | 0
472 |
473 |
474 |
475 |
476 | 30
477 | 16777215
478 |
479 |
480 |
481 | -1.0
482 |
483 |
484 |
485 | -
486 |
487 |
488 |
489 | 0
490 | 0
491 |
492 |
493 |
494 |
495 | 400
496 | 0
497 |
498 |
499 |
500 | -10000
501 |
502 |
503 | 10000
504 |
505 |
506 | Qt::Horizontal
507 |
508 |
509 |
510 | -
511 |
512 |
513 |
514 | 30
515 | 0
516 |
517 |
518 |
519 |
520 | 30
521 | 16777215
522 |
523 |
524 |
525 | 1.0
526 |
527 |
528 |
529 |
530 |
531 | -
532 |
533 |
-
534 |
535 |
-
536 |
537 |
538 |
539 | 0
540 | 0
541 |
542 |
543 |
544 |
545 | 55
546 | 0
547 |
548 |
549 |
550 |
551 | 55
552 | 16777215
553 |
554 |
555 |
556 | Kp Scale
557 |
558 |
559 |
560 | -
561 |
562 |
563 |
564 | 0
565 | 0
566 |
567 |
568 |
569 |
570 | 80
571 | 0
572 |
573 |
574 |
575 |
576 | 80
577 | 16777215
578 |
579 |
580 |
581 | 100
582 |
583 |
584 |
585 |
586 |
587 | -
588 |
589 |
-
590 |
591 |
592 |
593 | 55
594 | 0
595 |
596 |
597 |
598 |
599 | 55
600 | 16777215
601 |
602 |
603 |
604 | Pout MAX
605 |
606 |
607 |
608 | -
609 |
610 |
611 |
612 | 80
613 | 0
614 |
615 |
616 |
617 |
618 | 80
619 | 16777215
620 |
621 |
622 |
623 | 0
624 |
625 |
626 |
627 |
628 |
629 | -
630 |
631 |
-
632 |
633 |
634 |
635 | 55
636 | 0
637 |
638 |
639 |
640 |
641 | 55
642 | 16777215
643 |
644 |
645 |
646 | Kp Value
647 |
648 |
649 |
650 | -
651 |
652 |
653 |
654 | 133
655 | 0
656 |
657 |
658 |
659 |
660 | 16777215
661 | 16777215
662 |
663 |
664 |
665 |
666 |
667 |
668 |
669 |
670 |
671 |
672 |
673 |
674 |
675 |
676 | 10
677 | 230
678 | 511
679 | 81
680 |
681 |
682 |
683 | Derivative
684 |
685 |
686 |
687 |
688 | 10
689 | 20
690 | 498
691 | 56
692 |
693 |
694 |
695 | -
696 |
697 |
-
698 |
699 |
700 |
701 | 30
702 | 0
703 |
704 |
705 |
706 |
707 | 30
708 | 16777215
709 |
710 |
711 |
712 | -1.0
713 |
714 |
715 |
716 | -
717 |
718 |
719 |
720 | 0
721 | 0
722 |
723 |
724 |
725 |
726 | 350
727 | 0
728 |
729 |
730 |
731 | -10000
732 |
733 |
734 | 10000
735 |
736 |
737 | Qt::Horizontal
738 |
739 |
740 |
741 | -
742 |
743 |
744 |
745 | 30
746 | 0
747 |
748 |
749 |
750 |
751 | 30
752 | 16777215
753 |
754 |
755 |
756 | 1.0
757 |
758 |
759 |
760 |
761 |
762 | -
763 |
764 |
-
765 |
766 |
-
767 |
768 |
769 |
770 | 55
771 | 0
772 |
773 |
774 |
775 |
776 | 55
777 | 16777215
778 |
779 |
780 |
781 | Kd Scale
782 |
783 |
784 |
785 | -
786 |
787 |
788 |
789 | 80
790 | 0
791 |
792 |
793 |
794 |
795 | 80
796 | 16777215
797 |
798 |
799 |
800 | 100
801 |
802 |
803 |
804 |
805 |
806 | -
807 |
808 |
-
809 |
810 |
811 |
812 | 55
813 | 0
814 |
815 |
816 |
817 |
818 | 55
819 | 16777215
820 |
821 |
822 |
823 | Dout MAX
824 |
825 |
826 |
827 | -
828 |
829 |
830 |
831 | 80
832 | 0
833 |
834 |
835 |
836 |
837 | 80
838 | 16777215
839 |
840 |
841 |
842 | 0
843 |
844 |
845 |
846 |
847 |
848 | -
849 |
850 |
-
851 |
852 |
853 |
854 | 55
855 | 0
856 |
857 |
858 |
859 |
860 | 55
861 | 16777215
862 |
863 |
864 |
865 | Kd Value
866 |
867 |
868 |
869 | -
870 |
871 |
872 |
873 |
874 |
875 |
876 |
877 |
878 |
879 |
880 |
881 |
882 | 20
883 | 30
884 | 498
885 | 24
886 |
887 |
888 |
889 | -
890 |
891 |
-
892 |
893 |
894 |
895 | 40
896 | 0
897 |
898 |
899 |
900 | PID Mode
901 |
902 |
903 |
904 | -
905 |
906 |
907 |
908 | 50
909 | 0
910 |
911 |
912 |
-
913 |
914 | 位置式
915 |
916 |
917 | -
918 |
919 | 增量式
920 |
921 |
922 |
923 |
924 |
925 |
926 | -
927 |
928 |
-
929 |
930 |
931 |
932 | 50
933 | 0
934 |
935 |
936 |
937 | Motor ID
938 |
939 |
940 |
941 | -
942 |
943 |
944 |
945 | 30
946 | 0
947 |
948 |
949 |
-
950 |
951 | 0
952 |
953 |
954 | -
955 |
956 | 1
957 |
958 |
959 | -
960 |
961 | 2
962 |
963 |
964 | -
965 |
966 | 3
967 |
968 |
969 | -
970 |
971 | 4
972 |
973 |
974 | -
975 |
976 | 5
977 |
978 |
979 | -
980 |
981 | 6
982 |
983 |
984 | -
985 |
986 | 7
987 |
988 |
989 | -
990 |
991 | 8
992 |
993 |
994 | -
995 |
996 | 9
997 |
998 |
999 |
1000 |
1001 |
1002 |
1003 | -
1004 |
1005 |
-
1006 |
1007 |
1008 |
1009 | 70
1010 | 0
1011 |
1012 |
1013 |
1014 |
1015 | 70
1016 | 16777215
1017 |
1018 |
1019 |
1020 | PIDout MAX
1021 |
1022 |
1023 |
1024 | -
1025 |
1026 |
1027 |
1028 | 100
1029 | 0
1030 |
1031 |
1032 |
1033 |
1034 | 16777215
1035 | 16777215
1036 |
1037 |
1038 |
1039 | 0
1040 |
1041 |
1042 |
1043 |
1044 |
1045 |
1046 |
1047 |
1048 |
1049 |
1050 | 10
1051 | 150
1052 | 511
1053 | 80
1054 |
1055 |
1056 |
1057 | Intergral
1058 |
1059 |
1060 |
1061 |
1062 | 10
1063 | 20
1064 | 498
1065 | 56
1066 |
1067 |
1068 |
1069 | -
1070 |
1071 |
-
1072 |
1073 |
1074 |
1075 | 30
1076 | 0
1077 |
1078 |
1079 |
1080 |
1081 | 30
1082 | 16777215
1083 |
1084 |
1085 |
1086 | -1.0
1087 |
1088 |
1089 |
1090 | -
1091 |
1092 |
1093 |
1094 | 0
1095 | 0
1096 |
1097 |
1098 |
1099 |
1100 | 350
1101 | 0
1102 |
1103 |
1104 |
1105 | -10000
1106 |
1107 |
1108 | 10000
1109 |
1110 |
1111 | Qt::Horizontal
1112 |
1113 |
1114 |
1115 | -
1116 |
1117 |
1118 |
1119 | 30
1120 | 0
1121 |
1122 |
1123 |
1124 |
1125 | 30
1126 | 16777215
1127 |
1128 |
1129 |
1130 | 1.0
1131 |
1132 |
1133 |
1134 |
1135 |
1136 | -
1137 |
1138 |
-
1139 |
1140 |
-
1141 |
1142 |
1143 |
1144 | 55
1145 | 0
1146 |
1147 |
1148 |
1149 |
1150 | 55
1151 | 16777215
1152 |
1153 |
1154 |
1155 | Ki Scale
1156 |
1157 |
1158 |
1159 | -
1160 |
1161 |
1162 |
1163 | 80
1164 | 0
1165 |
1166 |
1167 |
1168 |
1169 | 80
1170 | 16777215
1171 |
1172 |
1173 |
1174 | 100
1175 |
1176 |
1177 |
1178 |
1179 |
1180 | -
1181 |
1182 |
-
1183 |
1184 |
1185 |
1186 | 55
1187 | 0
1188 |
1189 |
1190 |
1191 |
1192 | 55
1193 | 16777215
1194 |
1195 |
1196 |
1197 | Iout MAX
1198 |
1199 |
1200 |
1201 | -
1202 |
1203 |
1204 |
1205 | 80
1206 | 0
1207 |
1208 |
1209 |
1210 |
1211 | 80
1212 | 16777215
1213 |
1214 |
1215 |
1216 | 0
1217 |
1218 |
1219 |
1220 |
1221 |
1222 | -
1223 |
1224 |
-
1225 |
1226 |
1227 |
1228 | 55
1229 | 0
1230 |
1231 |
1232 |
1233 |
1234 | 55
1235 | 16777215
1236 |
1237 |
1238 |
1239 | Ki Value
1240 |
1241 |
1242 |
1243 | -
1244 |
1245 |
1246 |
1247 |
1248 |
1249 |
1250 |
1251 |
1252 |
1253 | layoutWidget_5
1254 | groupBox_5
1255 | groupBox_7
1256 | groupBox_6
1257 |
1258 | groupBox_2
1259 | groupBox
1260 | groupBox_3
1261 |
1262 |
1263 |
1264 |
1265 |
1266 | comboBox_baudRate
1267 | currentTextChanged(QString)
1268 | PID_Regulator
1269 | setBaudRate()
1270 |
1271 |
1272 | 102
1273 | 90
1274 |
1275 |
1276 | 184
1277 | 90
1278 |
1279 |
1280 |
1281 |
1282 | comboBox_stopBits
1283 | currentTextChanged(QString)
1284 | PID_Regulator
1285 | setStopBits()
1286 |
1287 |
1288 | 118
1289 | 118
1290 |
1291 |
1292 | 191
1293 | 118
1294 |
1295 |
1296 |
1297 |
1298 | comboBox_wordLength
1299 | currentTextChanged(QString)
1300 | PID_Regulator
1301 | setDataBits()
1302 |
1303 |
1304 | 135
1305 | 148
1306 |
1307 |
1308 | 189
1309 | 146
1310 |
1311 |
1312 |
1313 |
1314 | comboBox_parity
1315 | currentTextChanged(QString)
1316 | PID_Regulator
1317 | setParity()
1318 |
1319 |
1320 | 133
1321 | 173
1322 |
1323 |
1324 | 189
1325 | 175
1326 |
1327 |
1328 |
1329 |
1330 | comboBox_flowCtl
1331 | editTextChanged(QString)
1332 | PID_Regulator
1333 | setFlowCtrl()
1334 |
1335 |
1336 | 121
1337 | 203
1338 |
1339 |
1340 | 189
1341 | 202
1342 |
1343 |
1344 |
1345 |
1346 | pushButton_serialSwitch
1347 | clicked()
1348 | PID_Regulator
1349 | serialSwitch()
1350 |
1351 |
1352 | 119
1353 | 224
1354 |
1355 |
1356 | 187
1357 | 230
1358 |
1359 |
1360 |
1361 |
1362 | horizontalSlider_Kp
1363 | valueChanged(int)
1364 | PID_Regulator
1365 | setKpValue()
1366 |
1367 |
1368 | 481
1369 | 379
1370 |
1371 |
1372 | 586
1373 | 376
1374 |
1375 |
1376 |
1377 |
1378 | lineEdit_KpScale
1379 | textChanged(QString)
1380 | PID_Regulator
1381 | setKpValue()
1382 |
1383 |
1384 | 151
1385 | 410
1386 |
1387 |
1388 | 17
1389 | 406
1390 |
1391 |
1392 |
1393 |
1394 | horizontalSlider_Ki
1395 | valueChanged(int)
1396 | PID_Regulator
1397 | setKiValue()
1398 |
1399 |
1400 | 456
1401 | 468
1402 |
1403 |
1404 | 582
1405 | 464
1406 |
1407 |
1408 |
1409 |
1410 | lineEdit_KiScale
1411 | textChanged(QString)
1412 | PID_Regulator
1413 | setKiValue()
1414 |
1415 |
1416 | 141
1417 | 500
1418 |
1419 |
1420 | 12
1421 | 499
1422 |
1423 |
1424 |
1425 |
1426 | horizontalSlider_Kd
1427 | valueChanged(int)
1428 | PID_Regulator
1429 | setKdValue()
1430 |
1431 |
1432 | 462
1433 | 546
1434 |
1435 |
1436 | 587
1437 | 545
1438 |
1439 |
1440 |
1441 |
1442 | lineEdit_KdScale
1443 | textChanged(QString)
1444 | PID_Regulator
1445 | setKdValue()
1446 |
1447 |
1448 | 145
1449 | 580
1450 |
1451 |
1452 | 14
1453 | 576
1454 |
1455 |
1456 |
1457 |
1458 | lineEdit_KdValue
1459 | textChanged(QString)
1460 | PID_Regulator
1461 | setKdSliderValue()
1462 |
1463 |
1464 | 512
1465 | 581
1466 |
1467 |
1468 | 591
1469 | 580
1470 |
1471 |
1472 |
1473 |
1474 | lineEdit_KiValue
1475 | textChanged(QString)
1476 | PID_Regulator
1477 | setKiSliderValue()
1478 |
1479 |
1480 | 492
1481 | 499
1482 |
1483 |
1484 | 596
1485 | 500
1486 |
1487 |
1488 |
1489 |
1490 | lineEdit_KpValue
1491 | textChanged(QString)
1492 | PID_Regulator
1493 | setKpSliderValue()
1494 |
1495 |
1496 | 478
1497 | 411
1498 |
1499 |
1500 | 586
1501 | 412
1502 |
1503 |
1504 |
1505 |
1506 | pushButton_setPIDParams
1507 | clicked()
1508 | PID_Regulator
1509 | setPIDParams()
1510 |
1511 |
1512 | 262
1513 | 264
1514 |
1515 |
1516 | 189
1517 | 263
1518 |
1519 |
1520 |
1521 |
1522 | pushButton_queryBoardPID
1523 | clicked()
1524 | PID_Regulator
1525 | queryPIDParams()
1526 |
1527 |
1528 | 427
1529 | 261
1530 |
1531 |
1532 | 516
1533 | 260
1534 |
1535 |
1536 |
1537 |
1538 | pushButton_clear
1539 | clicked()
1540 | textBrowser_log
1541 | clear()
1542 |
1543 |
1544 | 237
1545 | 217
1546 |
1547 |
1548 | 355
1549 | 119
1550 |
1551 |
1552 |
1553 |
1554 |
1555 | setBaudRate()
1556 | setStopBits()
1557 | setParity()
1558 | setDataBits()
1559 | setFlowCtrl()
1560 | serialSwitch()
1561 | setKpValue()
1562 | setKiValue()
1563 | setKdValue()
1564 | setKdSliderValue()
1565 | setKpSliderValue()
1566 | setKiSliderValue()
1567 | setPIDParams()
1568 | queryPIDParams()
1569 |
1570 |
1571 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PID_Regulator
2 |
3 | PID_Regulator是一个旨在为[RoboMaster机甲大师](https://www.robomaster.com/zh-CN)参赛队员提供能够进行PID实时无线调参的解决方案,由[南京理工大学Alliance战队](https://mp.weixin.qq.com/s/pjrncS_X0_DEQYoD6yQVOw)提供技术支持。
4 | # 概述
5 | PID_Regulator主要包含以下三个部分的内容:
6 |
7 | - PC端上位机
8 | - 蓝牙无线串口传输
9 | - 以STM32为开发平台的下位机DEMO
10 |
11 | 功能实现
12 |
13 | - V1.0 根据协议能够实现PID实时无线调参功能
14 | - V1.2 修复一些bug,与STM32通信demo测试通过
15 |
16 | TODO
17 |
18 | - PID曲线显示
19 | ## PC端上位机
20 |
21 |
22 |
23 | ### 开发环境
24 | - Windows 10
25 | - Qt Creator 4.0.3 Based on Qt 5.6.1(MSVC 2013, 32 bit)
26 | ### 操作说明
27 | - 硬件连接好PC和下位机
28 | - 打开PID_Regulator.exe,打开串口即可进行数据传输
29 | - 通过“串口设置”一栏可进行串口参数设置及操作
30 | - 通过“PID Dynamic Reconfigure”一栏可进行PID参数设置
31 | - 通过“日志”一栏可查看相关操作日志并进行PID参数设置与查询板载PID参数
32 | - 剩余的操作请自行摸索
33 | ### 通信协议
34 | 参考[PID_Regulator_Protocol.pdf](https://github.com/jackychen227/PID_Regulator/blob/master/DOC/PID_Regulator_Protocol.pdf)
35 | ## STM32_DEMO
36 | - 蓝牙串口通信
37 | - 根据指定好的通信协议进行信息传输、解码与打包
38 | - 参考[RoboMaster/RoboRTS-Firmware](https://github.com/RoboMaster/RoboRTS-Firmware)进行PID的参数结构体设计
39 | ## 蓝牙无线串口传输
40 | ### 硬件
41 | #### 有线方案
42 | - [USB转TTL CH340模块](https://s.taobao.com/search?q=USB%E8%BD%ACTTL+CH340%E6%A8%A1%E5%9D%97&imgfile=&js=1&stats_click=search_radio_all%3A1&initiative_id=staobaoz_20180527&ie=utf8)
43 | #### 无线方案
44 | - [无线蓝牙模块](https://s.taobao.com/search?q=%E6%97%A0%E7%BA%BF%E8%93%9D%E7%89%99%E6%A8%A1%E5%9D%97&imgfile=&commend=all&ssid=s5-e&search_type=item&sourceId=tb.index&spm=a21bo.2017.201856-taobao-item.1&ie=utf8&initiative_id=tbindexz_20170306)
45 | - [绿联 USB蓝牙适配器4.0版接收器](https://item.jd.com/11078472771.html)(PC若自带蓝牙硬件支持则不用)
46 |
47 | ### 软硬件部署
48 | 初始化车载无线蓝牙串口之后,蓝牙模块与PC端蓝牙配对,之后可用正常的串口发送读取相关函数进行数据的无线传输,详细说明(TODO)
49 |
50 | # 版权申明
51 | NJUST Alliance. All rights reserved.
52 |
53 | # Bless for NJUST Alliance!
54 | # Veni! Vedi! Vici!
55 |
56 |
--------------------------------------------------------------------------------
/STM32_DEMO/V1.0/CRC.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jackychen227/PID_Regulator/80aa3789602d16181f5fe85cbe94c8ff96396f2c/STM32_DEMO/V1.0/CRC.c
--------------------------------------------------------------------------------
/STM32_DEMO/V1.0/CRC.h:
--------------------------------------------------------------------------------
1 | #ifndef __CRC_H
2 | #define __CRC_H
3 | #include "main.h"
4 |
5 | #define CRC_Check_False 0
6 | #define CRC_Check_True 1
7 |
8 |
9 | unsigned char Get_CRC8_Check_Sum(unsigned char *pchMessage,unsigned int dwLength,unsigned char ucCRC8);
10 | unsigned int Verify_CRC8_Check_Sum(unsigned char *pchMessage, unsigned int dwLength);
11 | void Append_CRC8_Check_Sum(unsigned char *pchMessage, unsigned int dwLength);
12 |
13 | uint16_t Get_CRC16_Check_Sum(uint8_t *pchMessage,uint32_t dwLength,uint16_t wCRC);
14 | uint32_t Verify_CRC16_Check_Sum(uint8_t *pchMessage, uint32_t dwLength);
15 | void Append_CRC16_Check_Sum(uint8_t * pchMessage,uint32_t dwLength);
16 |
17 | #endif
18 |
19 |
--------------------------------------------------------------------------------
/STM32_DEMO/V1.0/usart.c:
--------------------------------------------------------------------------------
1 | #define __USART_GLOBALS
2 | #include "usart.h"
3 |
4 |
5 | #define USART3_Waiting 0
6 | #define USART3_Receiving 1
7 | #define USART3_Success 2
8 | #define USART3_Failed 3
9 | u8 USART3_state = USART3_Waiting;//接收状态标记
10 | int8_t USART3_Rx_index=0;
11 | int8_t USART3_Tx_index=0;
12 | u16 RxLength = 8;
13 | u8 UsartRx_Info[USART_Rx_LEN];
14 | u8 UsartTx_Info[USART_Tx_LEN];
15 |
16 |
17 |
18 | void PID_ParamsSet(MsgsFrame_struct *pidSet);
19 | void PID_ParamsUpload(char motor_ID);
20 | void PID_Regulator_Decode(void);
21 |
22 | void USART3_InitConfig(void)
23 | {
24 | GPIO_InitTypeDef GPIO_InitStruct;
25 | USART_InitTypeDef USART_InitStruct;
26 | NVIC_InitTypeDef NVIC_InitStruct;
27 |
28 | /*enabe clocks*/
29 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE);
30 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
31 |
32 | /*open the alternative function*/
33 | GPIO_PinAFConfig(GPIOD,GPIO_PinSource8,GPIO_AF_USART3);
34 | GPIO_PinAFConfig(GPIOD,GPIO_PinSource9,GPIO_AF_USART3);
35 |
36 | /*Configure PD8,PD9 as GPIO_InitStruct1 input*/
37 | GPIO_InitStruct.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9;
38 | GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
39 | GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;
40 | GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
41 | GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
42 | GPIO_Init(GPIOD,&GPIO_InitStruct);
43 |
44 | USART_InitStruct.USART_BaudRate = 115200;
45 | USART_InitStruct.USART_WordLength = USART_WordLength_8b;
46 | USART_InitStruct.USART_StopBits = USART_StopBits_1;
47 | USART_InitStruct.USART_Parity = USART_Parity_No;
48 | USART_InitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
49 | USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
50 | USART_Init(USART3,&USART_InitStruct);
51 |
52 | USART_Cmd(USART3,ENABLE);
53 | USART_ITConfig(USART3,USART_IT_RXNE,ENABLE);
54 | // USART_ITConfig(USART3,USART_IT_TC,ENABLE );
55 |
56 | NVIC_InitStruct.NVIC_IRQChannel = USART3_IRQn;
57 | NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;
58 | NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;
59 | NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE ;
60 | NVIC_Init(&NVIC_InitStruct);
61 | }
62 |
63 |
64 | void PID_ParamsSet(MsgsFrame_struct *pidSet)
65 | {
66 | unsigned char index = pidSet->PID.motor_ID;
67 | Motor_PID[index].pid_mode = pidSet->PID.PID_Mode;
68 | Motor_PID[index].p = pidSet->PID.Kp_value.tempFloat;
69 | Motor_PID[index].i = pidSet->PID.Ki_value.tempFloat;
70 | Motor_PID[index].d = pidSet->PID.Kd_value.tempFloat;
71 |
72 | Motor_PID[index].max_out = pidSet->PID.PID_out_max.tempFloat;
73 | }
74 |
75 | #define QUERY_CMD_ID 0X10
76 | #define SET_CMD_ID 0X01
77 | #define UPLOAD_PARAMS_CMD_ID 0x10
78 | #define DATA_LENGTH_UPLOAD_PID_PATAMS 30
79 | void PID_ParamsUpload(char motor_ID)
80 | {
81 | // if ( (PID_Regulator_Msg.cmd_ID == QUERY_CMD_ID) || (PID_Regulator_Msg.cmd_ID == SET_CMD_ID))
82 | // {
83 | //
84 | // }
85 | unsigned char i=0,j=0;
86 | static unsigned char seq = 0;
87 | u8 usart_tx[200];
88 | u8 crc8;
89 | uint16_t crc16;
90 | MsgsFrame_struct tempMsgs;
91 |
92 | tempMsgs.SOF = 0xA5;
93 | tempMsgs.Data_Length = DATA_LENGTH_UPLOAD_PID_PATAMS;
94 | tempMsgs.seq = seq;
95 | seq++;
96 | //tempMsgs.crc8 = 0;//
97 | tempMsgs.cmd_ID = UPLOAD_PARAMS_CMD_ID;
98 | tempMsgs.PID.motor_ID = motor_ID;
99 | tempMsgs.PID.Kp_value.tempFloat = Motor_PID[motor_ID].p;
100 | tempMsgs.PID.Ki_value.tempFloat = Motor_PID[motor_ID].i;
101 | tempMsgs.PID.Kd_value.tempFloat = Motor_PID[motor_ID].d;
102 | tempMsgs.PID.P_out_max.tempFloat = 111;//TODO
103 | tempMsgs.PID.I_out_max.tempFloat = 111;//TODO
104 | tempMsgs.PID.D_out_max.tempFloat = 111;//TODO
105 | tempMsgs.PID.PID_out_max.tempFloat = Motor_PID[motor_ID].max_out;
106 |
107 | usart_tx[i] = tempMsgs.SOF;
108 | usart_tx[i++] = tempMsgs.Data_Length;
109 | usart_tx[i++] = tempMsgs.seq;
110 |
111 | crc8 = Get_CRC8_Check_Sum(usart_tx,i,0xff);
112 | usart_tx[i++] = crc8;
113 | usart_tx[i++] = tempMsgs.cmd_ID;
114 | usart_tx[i++] = tempMsgs.PID.motor_ID;
115 | for(j=0;j<4;j++) usart_tx[i++] = tempMsgs.PID.Kp_value.tempChar[j];
116 | for(j=0;j<4;j++) usart_tx[i++] = tempMsgs.PID.Ki_value.tempChar[j];
117 | for(j=0;j<4;j++) usart_tx[i++] = tempMsgs.PID.Kd_value.tempChar[j];
118 | for(j=0;j<4;j++) usart_tx[i++] = tempMsgs.PID.P_out_max.tempChar[j];
119 | for(j=0;j<4;j++) usart_tx[i++] = tempMsgs.PID.I_out_max.tempChar[j];
120 | for(j=0;j<4;j++) usart_tx[i++] = tempMsgs.PID.D_out_max.tempChar[j];
121 | for(j=0;j<4;j++) usart_tx[i++] = tempMsgs.PID.PID_out_max.tempChar[j];
122 |
123 | crc16 = Get_CRC16_Check_Sum(usart_tx,i,0xff);
124 | usart_tx[i++] = crc16&0x00ff;
125 | usart_tx[i++] = (crc16>>8)&0x00ff;
126 |
127 | for (j=0;j下位机,查询板载PID参数
143 | {
144 | PID_Regulator_Msg.PID.motor_ID = UsartRx_Info[i++];
145 |
146 | for(j=0;j<2;j++) PID_Regulator_Msg.crc16.tempChar[j] = UsartRx_Info[i++];
147 | }
148 | else if ( PID_Regulator_Msg.cmd_ID == 0x01)//上位机->下位机,PID参数设置
149 | {
150 | PID_Regulator_Msg.PID.motor_ID = UsartRx_Info[i++];
151 | PID_Regulator_Msg.PID.PID_Mode = UsartRx_Info[i++];
152 | for(j=0;j<4;j++) PID_Regulator_Msg.PID.Kp_value.tempChar[j] = UsartRx_Info[i++];
153 | for(j=0;j<4;j++) PID_Regulator_Msg.PID.Ki_value.tempChar[j] = UsartRx_Info[i++];
154 | for(j=0;j<4;j++) PID_Regulator_Msg.PID.Kd_value.tempChar[j] = UsartRx_Info[i++];
155 | for(j=0;j<4;j++) PID_Regulator_Msg.PID.P_out_max.tempChar[j] = UsartRx_Info[i++];
156 | for(j=0;j<4;j++) PID_Regulator_Msg.PID.I_out_max.tempChar[j] = UsartRx_Info[i++];
157 | for(j=0;j<4;j++) PID_Regulator_Msg.PID.D_out_max.tempChar[j] = UsartRx_Info[i++];
158 | for(j=0;j<4;j++) PID_Regulator_Msg.PID.PID_out_max.tempChar[j] = UsartRx_Info[i++];
159 |
160 | for(j=0;j<2;j++) PID_Regulator_Msg.crc16.tempChar[j] = UsartRx_Info[i++];
161 |
162 | //参数赋值、存储操作
163 | PID_ParamsSet(&PID_Regulator_Msg);
164 | }
165 | }
166 | //串口接收上位机信息
167 | void USART3_IRQHandler(void)
168 | {
169 | u8 Res = 0;
170 | if(USART_GetITStatus(USART3, USART_IT_RXNE|USART_IT_ORE_RX) != RESET) //接收中断
171 | {
172 | Res =USART_ReceiveData(USART3);// //读取接收到的数据
173 | if( (USART3_state == USART3_Waiting)&&(Res == 0xA5) )
174 | {
175 | USART3_state = USART3_Receiving;
176 | USART3_Rx_index = 0; //接收数组的计数器
177 | UsartRx_Info[USART3_Rx_index] = Res;
178 | USART3_Rx_index++;
179 | }
180 | else if( USART3_state == USART3_Receiving )
181 | {
182 | if( USART3_Rx_index == 1 )//Data Length
183 | {
184 | UsartRx_Info[USART3_Rx_index] = Res;
185 | USART3_Rx_index++;
186 | RxLength = Res;
187 | }
188 | else if( USART3_Rx_index == 2 )//Seq
189 | {
190 | UsartRx_Info[USART3_Rx_index] = Res;
191 | USART3_Rx_index++;
192 | }
193 | else if( USART3_Rx_index == 3 )
194 | {
195 | if ( Verify_CRC8_Check_Sum(UsartRx_Info,4)) ;
196 | else //CRC校验错误,重新等待读取
197 | {
198 | RxLength=8 ;
199 | USART3_Rx_index = 0;
200 | USART3_state = USART3_Waiting;
201 | }
202 | }
203 | else if (USART3_Rx_index < RxLength)
204 | {
205 | UsartRx_Info[USART3_Rx_index]=Res ;
206 | USART3_Rx_index++;
207 | if (USART3_Rx_index == RxLength) //接收完成 ,结束了
208 | {
209 | //首先进行crc校验应该
210 | if (Verify_CRC16_Check_Sum(UsartRx_Info, RxLength )) PID_Regulator_Decode();
211 | RxLength=8 ;
212 | USART3_Rx_index = 0;
213 | USART3_state = USART3_Waiting;
214 | }
215 | }
216 |
217 | }
218 | USART_ClearFlag(USART3,USART_IT_RXNE|USART_IT_ORE_RX);
219 | }
220 | PID_ParamsUpload(PID_Regulator_Msg.PID.motor_ID);
221 | }
222 |
--------------------------------------------------------------------------------
/STM32_DEMO/V1.0/usart.h:
--------------------------------------------------------------------------------
1 | #ifndef __USART_H
2 | #define __USART_H
3 | #include "main.h"
4 |
5 | #define USART_Rx_LEN 200 //定义最大接收字节数 200
6 | #define USART_Tx_LEN 200
7 |
8 | #ifdef __USART_GLOBALS
9 | #define __USART_EXT
10 | #else
11 | #define __USART_EXT extern
12 | #endif
13 |
14 | typedef struct{
15 | unsigned char motor_ID;
16 | unsigned char PID_Mode;//增量式:1;位置式:0
17 | union{
18 | unsigned char tempChar[4];
19 | float tempFloat;
20 | }Kp_value;
21 | union{
22 | unsigned char tempChar[4];
23 | float tempFloat;
24 | }Ki_value;
25 | union{
26 | unsigned char tempChar[4];
27 | float tempFloat;
28 | }Kd_value;
29 | union{
30 | unsigned char tempChar[4];
31 | uint32_t tempFloat;
32 | }P_out_max;
33 | union{
34 | unsigned char tempChar[4];
35 | uint32_t tempFloat;
36 | }I_out_max;
37 | union{
38 | unsigned char tempChar[4];
39 | uint32_t tempFloat;
40 | }D_out_max;
41 | union{
42 | unsigned char tempChar[4];
43 | uint32_t tempFloat;
44 | }PID_out_max;
45 | }PID_struct;
46 |
47 | typedef struct{
48 | unsigned char SOF;
49 | unsigned char Data_Length;
50 | unsigned char seq;
51 | unsigned char crc8;
52 | unsigned char cmd_ID;
53 | PID_struct PID;
54 | union{
55 | unsigned char tempChar[2];
56 | int tempInt;
57 | }crc16;
58 | }MsgsFrame_struct;
59 |
60 | typedef struct pid_t
61 | {
62 | float p;
63 | float i;
64 | float d;
65 |
66 | float set;
67 | float get;
68 | float err[3];
69 |
70 | float pout;
71 | float iout;
72 | float dout;
73 | float out;
74 |
75 | float input_max_err; //input max err;
76 | float output_deadband; //output deadband;
77 |
78 | uint32_t pid_mode;
79 | uint32_t max_out;
80 | uint32_t integral_limit;
81 |
82 | void (*f_param_init)(struct pid_t *pid,
83 | uint32_t pid_mode,
84 | uint32_t max_output,
85 | uint32_t inte_limit,
86 | float p,
87 | float i,
88 | float d);
89 | void (*f_pid_reset)(struct pid_t *pid, float p, float i, float d);
90 |
91 | } pid_t;
92 |
93 |
94 | __USART_EXT pid_t Motor_PID[10];
95 | __USART_EXT MsgsFrame_struct PID_Regulator_Msg;
96 | void USART3_InitConfig(void);
97 |
98 | #endif
99 |
--------------------------------------------------------------------------------
/STM32_DEMO/V1.2/CRC.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jackychen227/PID_Regulator/80aa3789602d16181f5fe85cbe94c8ff96396f2c/STM32_DEMO/V1.2/CRC.c
--------------------------------------------------------------------------------
/STM32_DEMO/V1.2/CRC.h:
--------------------------------------------------------------------------------
1 | #ifndef __CRC_H
2 | #define __CRC_H
3 | #include "main.h"
4 |
5 | #define CRC_Check_False 0
6 | #define CRC_Check_True 1
7 |
8 |
9 | unsigned char Get_CRC8_Check_Sum(unsigned char *pchMessage,unsigned int dwLength,unsigned char ucCRC8);
10 | unsigned int Verify_CRC8_Check_Sum(unsigned char *pchMessage, unsigned int dwLength);
11 | void Append_CRC8_Check_Sum(unsigned char *pchMessage, unsigned int dwLength);
12 |
13 | uint16_t Get_CRC16_Check_Sum(uint8_t *pchMessage,uint32_t dwLength,uint16_t wCRC);
14 | uint32_t Verify_CRC16_Check_Sum(uint8_t *pchMessage, uint32_t dwLength);
15 | void Append_CRC16_Check_Sum(uint8_t * pchMessage,uint32_t dwLength);
16 |
17 | #endif
18 |
19 |
--------------------------------------------------------------------------------
/STM32_DEMO/V1.2/usart.c:
--------------------------------------------------------------------------------
1 | #define __USART6_GLOBALS
2 |
3 | #include "usart.h"
4 |
5 | #define USART6_Waiting 0
6 | #define USART6_Receiving 1
7 | #define USART6_Success 2
8 | #define USART6_Failed 3
9 |
10 | u8 USART6_state = USART6_Waiting;//接收状态标记
11 | u8 USART6_Rx_index=0;
12 | u8 USART6_Tx_index=0;
13 | unsigned char Usart6Rx_Info[USART_Rx_LEN];
14 | unsigned char Usart6Tx_Info[USART_Tx_LEN];
15 |
16 | /**
17 | * @brief 重定义fputc函数(禁用半主机模式)
18 | * @param
19 | * @retval
20 | */
21 |
22 | #if 1
23 | #pragma import(__use_no_semihosting)
24 | //标准库需要的支持函数
25 | struct __FILE
26 | {
27 | int handle;
28 | };
29 |
30 | FILE __stdout;
31 | //定义_sys_exit()以避免使用半主机模式
32 | _sys_exit(int x)
33 | {
34 | x = x;
35 | }
36 | //重定义fputc函数
37 | // 发送数据
38 | int fputc(int ch, FILE *f)
39 | {
40 | while (USART_GetFlagStatus(USART6,USART_FLAG_TC) == RESET);
41 | USART_SendData(USART6, (uint8_t)ch);
42 | return (ch);
43 | }
44 | #endif
45 |
46 | /**
47 | * @brief 初始化USART6
48 | * @param void
49 | * @retval void
50 | * @notes USART6_TX-->PG14 USART6_RX-->PG9---->YOLO信息接收 USART6_TX---->串口打印
51 | */
52 | void USART6_InitConfig(void)
53 | {
54 | GPIO_InitTypeDef GPIO_InitStruct;
55 | USART_InitTypeDef USART_InitStruct;
56 | NVIC_InitTypeDef NVIC_InitStruct;
57 |
58 | /*enabe clocks*/
59 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG,ENABLE);
60 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6,ENABLE);
61 |
62 | /*open the alternative function*/
63 | GPIO_PinAFConfig(GPIOG,GPIO_PinSource9,GPIO_AF_USART6);
64 | GPIO_PinAFConfig(GPIOG,GPIO_PinSource14,GPIO_AF_USART6);
65 |
66 | /*Configure PB10,PB11 as GPIO_InitStruct1 input*/
67 | GPIO_InitStruct.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_14;
68 | GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
69 | GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;
70 | GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
71 | GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
72 | GPIO_Init(GPIOG,&GPIO_InitStruct);
73 |
74 | USART_InitStruct.USART_BaudRate = 115200;
75 | USART_InitStruct.USART_WordLength = USART_WordLength_8b;
76 | USART_InitStruct.USART_StopBits = USART_StopBits_1;
77 | USART_InitStruct.USART_Parity = USART_Parity_No;
78 | USART_InitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
79 | USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
80 | USART_Init(USART6,&USART_InitStruct);
81 |
82 | USART_Cmd(USART6,ENABLE);
83 | USART_ITConfig(USART6,USART_IT_RXNE,ENABLE);
84 |
85 | NVIC_InitStruct.NVIC_IRQChannel = USART6_IRQn;
86 | NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 3;
87 | NVIC_InitStruct.NVIC_IRQChannelSubPriority = 3;
88 | NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE ;
89 | NVIC_Init(&NVIC_InitStruct);
90 | }
91 |
92 | u16 rxLength = 8;
93 | #define QUERY_CMD_ID 0X10
94 | #define SET_CMD_ID 0X01
95 | #define UPLOAD_PARAMS_CMD_ID 0x10
96 | #define DATA_LENGTH_UPLOAD_PID_PATAMS 30
97 | void PID_ParamsSet(MsgsFrame_struct *pidSet);
98 | void PID_ParamsUpload(char motor_ID);
99 | void PID_Regulator_Decode(void);
100 |
101 | void PID_ParamsSet(MsgsFrame_struct *pidSet)
102 | {
103 | unsigned char index = pidSet->PID.motor_ID;
104 | Motor_PID[index].pid_mode = pidSet->PID.PID_Mode;
105 | Motor_PID[index].p = pidSet->PID.Kp_value.tempFloat;
106 | Motor_PID[index].i = pidSet->PID.Ki_value.tempFloat;
107 | Motor_PID[index].d = pidSet->PID.Kd_value.tempFloat;
108 |
109 | Motor_PID[index].P_out_max = pidSet->PID.P_out_max.tempFloat;
110 | Motor_PID[index].I_out_max = pidSet->PID.I_out_max.tempFloat;
111 | Motor_PID[index].D_out_max = pidSet->PID.D_out_max.tempFloat;
112 | Motor_PID[index].PID_out_max = pidSet->PID.PID_out_max.tempFloat;
113 |
114 | Motor_PID[index].max_out = pidSet->PID.PID_out_max.tempFloat;
115 | }
116 |
117 | void PID_ParamsUpload(char motor_ID)
118 | {
119 | // if ( (PID_Regulator_Msg.cmd_ID == QUERY_CMD_ID) || (PID_Regulator_Msg.cmd_ID == SET_CMD_ID))
120 | // {
121 | //
122 | // }
123 | unsigned char i=0,j=0;
124 | static unsigned char seq = 0;
125 | u8 usart_tx[200];
126 | u8 crc8;
127 | uint16_t crc16;
128 | MsgsFrame_struct tempMsgs;
129 |
130 | tempMsgs.SOF = 0xA5;
131 | tempMsgs.Data_Length = DATA_LENGTH_UPLOAD_PID_PATAMS;
132 | tempMsgs.seq = seq;
133 | seq++;
134 | //tempMsgs.crc8 = 0;//
135 | tempMsgs.cmd_ID = UPLOAD_PARAMS_CMD_ID;
136 | tempMsgs.PID.motor_ID = motor_ID;
137 | tempMsgs.PID.PID_Mode = Motor_PID[motor_ID].pid_mode;
138 | tempMsgs.PID.Kp_value.tempFloat = Motor_PID[motor_ID].p;
139 | tempMsgs.PID.Ki_value.tempFloat = Motor_PID[motor_ID].i;
140 | tempMsgs.PID.Kd_value.tempFloat = Motor_PID[motor_ID].d;
141 | tempMsgs.PID.P_out_max.tempFloat = Motor_PID[motor_ID].P_out_max;//TODO
142 | tempMsgs.PID.I_out_max.tempFloat = Motor_PID[motor_ID].I_out_max;//TODO
143 | tempMsgs.PID.D_out_max.tempFloat = Motor_PID[motor_ID].D_out_max;//TODO
144 | tempMsgs.PID.PID_out_max.tempFloat = Motor_PID[motor_ID].PID_out_max;
145 | tempMsgs.PID.PID_out_max.tempFloat = Motor_PID[motor_ID].max_out;
146 |
147 | usart_tx[i++] = tempMsgs.SOF;
148 | usart_tx[i++] = tempMsgs.Data_Length;
149 | usart_tx[i++] = tempMsgs.seq;
150 |
151 | crc8 = Get_CRC8_Check_Sum(usart_tx,i,0xff);
152 | usart_tx[i++] = crc8;
153 | usart_tx[i++] = tempMsgs.cmd_ID;
154 | usart_tx[i++] = tempMsgs.PID.motor_ID;
155 | usart_tx[i++] = tempMsgs.PID.PID_Mode;
156 | for(j=0;j<4;j++) usart_tx[i++] = tempMsgs.PID.Kp_value.tempChar[j];
157 | for(j=0;j<4;j++) usart_tx[i++] = tempMsgs.PID.Ki_value.tempChar[j];
158 | for(j=0;j<4;j++) usart_tx[i++] = tempMsgs.PID.Kd_value.tempChar[j];
159 | for(j=0;j<4;j++) usart_tx[i++] = tempMsgs.PID.P_out_max.tempChar[j];
160 | for(j=0;j<4;j++) usart_tx[i++] = tempMsgs.PID.I_out_max.tempChar[j];
161 | for(j=0;j<4;j++) usart_tx[i++] = tempMsgs.PID.D_out_max.tempChar[j];
162 | for(j=0;j<4;j++) usart_tx[i++] = tempMsgs.PID.PID_out_max.tempChar[j];
163 |
164 | crc16 = Get_CRC16_Check_Sum(usart_tx,i,0xffff);
165 | usart_tx[i++] = crc16&0xff;
166 | usart_tx[i++] = (crc16>>8)&0xff;
167 |
168 | for (j=0;j下位机,查询板载PID参数
184 | {
185 | PID_Regulator_Msg.PID.motor_ID = Usart6Rx_Info[i++];
186 |
187 | for(j=0;j<2;j++) PID_Regulator_Msg.crc16.tempChar[j] = Usart6Rx_Info[i++];
188 | }
189 | else if ( PID_Regulator_Msg.cmd_ID == 0x01)//上位机->下位机,PID参数设置
190 | {
191 | PID_Regulator_Msg.PID.motor_ID = Usart6Rx_Info[i++];
192 | PID_Regulator_Msg.PID.PID_Mode = Usart6Rx_Info[i++];
193 | for(j=0;j<4;j++) PID_Regulator_Msg.PID.Kp_value.tempChar[j] = Usart6Rx_Info[i++];
194 | for(j=0;j<4;j++) PID_Regulator_Msg.PID.Ki_value.tempChar[j] = Usart6Rx_Info[i++];
195 | for(j=0;j<4;j++) PID_Regulator_Msg.PID.Kd_value.tempChar[j] = Usart6Rx_Info[i++];
196 | for(j=0;j<4;j++) PID_Regulator_Msg.PID.P_out_max.tempChar[j] = Usart6Rx_Info[i++];
197 | for(j=0;j<4;j++) PID_Regulator_Msg.PID.I_out_max.tempChar[j] = Usart6Rx_Info[i++];
198 | for(j=0;j<4;j++) PID_Regulator_Msg.PID.D_out_max.tempChar[j] = Usart6Rx_Info[i++];
199 | for(j=0;j<4;j++) PID_Regulator_Msg.PID.PID_out_max.tempChar[j] = Usart6Rx_Info[i++];
200 |
201 | for(j=0;j<2;j++) PID_Regulator_Msg.crc16.tempChar[j] = Usart6Rx_Info[i++];
202 |
203 | //参数赋值、存储操作
204 | PID_ParamsSet(&PID_Regulator_Msg);
205 | }
206 | }
207 |
208 | static uint8_t upload_flag=0;
209 | //串口接收上位机信息
210 | void USART6_IRQHandler(void)
211 | {
212 | u8 Res = 0;
213 | if(USART_GetITStatus(USART6, USART_IT_RXNE|USART_IT_ORE_RX) != RESET) //接收中断
214 | {
215 | Res =USART_ReceiveData(USART6);// //读取接收到的数据
216 | if( (USART6_state == USART6_Waiting)&&(Res == 0xA5) )
217 | {
218 | USART6_state = USART6_Receiving;
219 | USART6_Rx_index = 0; //接收数组的计数器
220 | Usart6Rx_Info[USART6_Rx_index] = Res;
221 | USART6_Rx_index++;
222 | }
223 | else if( USART6_state == USART6_Receiving )
224 | {
225 | if( USART6_Rx_index == 1 )//Data Length
226 | {
227 | Usart6Rx_Info[USART6_Rx_index] = Res;
228 | USART6_Rx_index++;
229 | rxLength = Res+7;
230 | }
231 | else if( USART6_Rx_index == 2 )//Seq
232 | {
233 | Usart6Rx_Info[USART6_Rx_index] = Res;
234 | USART6_Rx_index++;
235 | }
236 | else if( USART6_Rx_index == 3 )
237 | {
238 | Usart6Rx_Info[USART6_Rx_index] = Res;
239 | USART6_Rx_index++;
240 | if ( Verify_CRC8_Check_Sum(Usart6Rx_Info,4))
241 | {
242 | NULL ;
243 | }
244 | else //CRC校验错误,重新等待读取
245 | {
246 | rxLength=8 ;
247 | USART6_Rx_index = 0;
248 | USART6_state = USART6_Waiting;
249 | }
250 | }
251 | else if (USART6_Rx_index < rxLength)
252 | {
253 | Usart6Rx_Info[USART6_Rx_index]=Res ;
254 | USART6_Rx_index++;
255 | if (USART6_Rx_index == rxLength) //接收完成 ,结束了
256 | {
257 | //首先进行crc校验应该
258 | if (Verify_CRC16_Check_Sum(Usart6Rx_Info, rxLength ))
259 | {
260 | PID_Regulator_Decode();
261 | upload_flag = 1;
262 | }
263 | rxLength=8 ;
264 | USART6_Rx_index = 0;
265 | USART6_state = USART6_Waiting;
266 | }
267 | }
268 | }
269 | USART_ClearFlag(USART6,USART_IT_RXNE|USART_IT_ORE_RX);
270 | }
271 |
272 | if(upload_flag)
273 | {
274 | PID_ParamsUpload(PID_Regulator_Msg.PID.motor_ID);
275 | upload_flag=0;
276 | }
277 | }
278 |
--------------------------------------------------------------------------------
/STM32_DEMO/V1.2/usart.h:
--------------------------------------------------------------------------------
1 | #ifndef __USART6_H
2 | #define __USART6_H
3 | #include "stm32f4xx.h"
4 |
5 | #define USART_Rx_LEN 200 //定义最大接收字节数 200
6 | #define USART_Tx_LEN 200
7 |
8 | #ifdef __USART6_GLOBALS
9 | #define __USART6_EXT
10 | #else
11 | #define __USART6_EXT extern
12 | #endif
13 |
14 | typedef struct{
15 | unsigned char motor_ID;
16 | unsigned char PID_Mode;//增量式:1;位置式:0
17 | union{
18 | unsigned char tempChar[4];
19 | float tempFloat;
20 | }Kp_value;
21 | union{
22 | unsigned char tempChar[4];
23 | float tempFloat;
24 | }Ki_value;
25 | union{
26 | unsigned char tempChar[4];
27 | float tempFloat;
28 | }Kd_value;
29 | union{
30 | unsigned char tempChar[4];
31 | float tempFloat;
32 | }P_out_max;
33 | union{
34 | unsigned char tempChar[4];
35 | float tempFloat;
36 | }I_out_max;
37 | union{
38 | unsigned char tempChar[4];
39 | float tempFloat;
40 | }D_out_max;
41 | union{
42 | unsigned char tempChar[4];
43 | float tempFloat;
44 | }PID_out_max;
45 | }PID_struct;
46 |
47 | typedef struct{
48 | unsigned char SOF;
49 | unsigned char Data_Length;
50 | unsigned char seq;
51 | unsigned char crc8;
52 | unsigned char cmd_ID;
53 | PID_struct PID;
54 | union{
55 | unsigned char tempChar[2];
56 | int tempInt;
57 | }crc16;
58 | }MsgsFrame_struct;
59 |
60 | typedef struct pid_t
61 | {
62 | float p;
63 | float i;
64 | float d;
65 |
66 | float set;
67 | float get;
68 | float err[3];
69 |
70 | float pout;
71 | float iout;
72 | float dout;
73 | float out;
74 |
75 | float input_max_err; //input max err;
76 | float output_deadband; //output deadband;
77 |
78 | uint32_t pid_mode;
79 | uint32_t max_out;
80 | uint32_t integral_limit;
81 |
82 | float P_out_max, I_out_max, D_out_max,PID_out_max;
83 | void (*f_param_init)(struct pid_t *pid,
84 | uint32_t pid_mode,
85 | uint32_t max_output,
86 | uint32_t inte_limit,
87 | float p,
88 | float i,
89 | float d);
90 | void (*f_pid_reset)(struct pid_t *pid, float p, float i, float d);
91 |
92 | } pid_t;
93 |
94 | #define CHASSIS_MOTOR_MOTOR_LF 1
95 | #define CHASSIS_MOTOR_MOTOR_RF 2
96 | #define CHASSIS_MOTOR_MOTOR_RB 3
97 | #define CHASSIS_MOTOR_MOTOR_LB 4
98 | #define YAW_MOTOR_ID 5
99 | #define PITCH_MOTOR_ID 6
100 |
101 | __USART6_EXT pid_t Motor_PID[10];
102 | __USART6_EXT MsgsFrame_struct PID_Regulator_Msg;
103 | void USART6_InitConfig(void);
104 | void PID_ParamsUpload(char motor_ID);
105 |
106 | #endif
--------------------------------------------------------------------------------