Compare commits

..

41 Commits
0.13.1 ... main

Author SHA1 Message Date
55a9fe6f3e Fixed another calling signature bug 2025-06-18 08:25:39 +02:00
e618b39687 Fixed function call arguments in template 2025-06-18 08:15:34 +02:00
41dfd1de5a Fixed docs 2025-06-17 13:13:43 +02:00
07cab3ac2a Replaced sizeof with template parameter N 2025-06-17 10:22:13 +02:00
e194736206 Fixed bug in char array getter 2025-06-17 09:39:12 +02:00
30af284f5d Safer handling of reading bools from the param lib 2025-06-17 09:36:44 +02:00
6069aa9194 Fixed typo 2025-06-17 09:32:42 +02:00
c475beee66 Fixed char array getAxisParam function 2025-06-17 09:30:40 +02:00
b1fe452ed6 Added cast for specialized function 2025-06-17 09:24:20 +02:00
d395c7bbb7 Added getAxisParam variant for char arrays 2025-06-17 08:51:58 +02:00
a6f2890c76 Adjusted char[BUF] template 2025-06-17 08:43:51 +02:00
fef61bc804 Fixed template error 2025-06-17 08:40:35 +02:00
3d984f26bc Moved template functions to header to avoid linker errors 2025-06-17 08:33:18 +02:00
2f8ae23d57 Added static cast to force correct type 2025-06-16 16:15:24 +02:00
603b3e77af Revised version with adapted macros 2025-06-16 15:53:36 +02:00
31ff26cb78 Generalized getAxisParam 2025-06-16 15:24:28 +02:00
43df40aaea WIP 2025-06-16 13:32:49 +02:00
bdefc6090d Added getters and setters for wasMoving and targetPosition 2025-06-10 14:09:20 +02:00
c2eca33ce8 Ready for release 1.0 2025-05-23 12:25:48 +02:00
87980e403c Fixed bug regarding the poll period member variables 2025-05-23 11:17:34 +02:00
b95e782ea8 Added accessor for maxSubsequentTimeoutsExceeded flag 2025-05-23 10:10:54 +02:00
cd7cc75eb7 Added destructors for the classes in order to use the PIMPL idiom with
uniqe_ptr
2025-05-23 09:38:41 +02:00
83aa437b6b Applied PIMPL by moving members to internal struct sinqAxisImpl
This change makes sinqMotor ready for 1.x releases where ABI stability
and backwards compatibility is guaranteed.
2025-05-22 13:56:44 +02:00
275672aaef Removed lock in reset and replaced it with wakeupPoller call
Trying to lock the controller from one of its axes may lead to
segfaults, hence it is not advisable.
2025-05-16 15:50:26 +02:00
61c5ec749e Merge branch 'main' of gitea.psi.ch:lin-epics-modules/sinqMotor 2025-05-15 14:26:15 +02:00
1cf4b9ab25 Made some functions virtual so they can be overwritten 2025-05-15 14:26:00 +02:00
a0b674b26e Made some functions virtual so they can be overwritten 2025-05-15 14:24:53 +02:00
e088bfbbcb Added initial value for motorMessageText 2025-05-15 11:39:47 +02:00
3c345e37da Fixed char array undefined symbol bug 2025-05-15 11:25:56 +02:00
b267200039 Simplified paramLib access and show error messages for one poll cycle
Simplified getting and setting paramLib entries via a macro and created
a mechanism within poll() which makes sure that error messages are shown
for at least one poll cycle. Also moved MAXBUF_ to the SinqController
level.
2025-05-14 16:07:03 +02:00
9bc90cff61 Simplified paramLib access and show error messages for one poll cycle
Simplified getting and setting paramLib entries via a macro and created
a mechanism within poll() which makes sure that error messages are shown
for at least one poll cycle. Also moved MAXBUF_ to the SinqController
level.
2025-05-14 15:59:48 +02:00
9792697d03 Addes instructions how to use sinqMotor as static dependency. 2025-05-12 16:41:33 +02:00
4d1c21fd74 Added a license (GPL3) 2025-05-09 11:59:51 +02:00
dbcfebc6de Added function to set the number of forced fast polls. 2025-05-09 08:14:05 +02:00
b89fe41c6e Added macros for adding and retrieving paramlib entries in order to make
the code less cluttered. Also built in a mechanism which makes sure that
forced fast polls are not ignored anymore when adaptive polling is
enabled.
2025-05-08 17:04:23 +02:00
5689402375 Further clarified the error message in checkMaxSubsequentTimeouts. 2025-05-05 09:15:15 +02:00
2a7934b8d6 Fixed bug where arguments were given in the wrong order. 2025-05-05 08:51:34 +02:00
3071e402b2 Fixed bug in sinqMotor.db (bad field name) 2025-04-29 14:43:32 +02:00
dd0610fd99 Added connection assertion and moved msgPrintControl to key 2025-04-25 15:54:41 +02:00
c7936191d9 Added Connected PV 2025-04-25 13:17:41 +02:00
3ec83b115e Added further info on versioning to README.md 2025-04-24 09:17:05 +02:00
11 changed files with 1923 additions and 554 deletions

674
LICENSE.txt Normal file
View File

@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
{one line to give the program's name and a brief idea of what it does.}
Copyright (C) {year} {name of author}
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
{project} Copyright (C) {year} {fullname}
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

View File

@ -17,9 +17,48 @@ The full inheritance chain for two different motor drivers "a" and "b" looks lik
`asynController -> sinqController -> bController`
`asynAxis -> sinqAxis -> bAxis`
Those inheritance chains are created at runtime by loading shared libraries. Therefore, it is important to load compatible versions. At SINQ, the versioning numbers follow the SemVer standard (https://semver.org/lang/de/). For example, if driver "a" depends on version 2.1.0 of "sinqMotor", then it is safe to use "sinqMotor" 2.5.3 since 2.5.3 is backwards compatible to 2.1.0. However, it is not allowed to use e.g. version 1.9.0 or 2.0.0 or 3.0.1 instead. For more details on SemVer, please refer to the official documentation.
Those inheritance chains are created at runtime by loading shared libraries. These libraries must be compatible to each other (see next section).
To find out which version of sinqMotor is needed by driver "a", refer to its Makefile (line `sinqMotor_VERSION=x.x.x`, where x.x.x is the minimum required version).
### Versioning
In order to make sure the shared libraries are compatible to each other, we use the "require" framework extension for EPICS (https://github.com/paulscherrerinstitute/require). If a shared library has another library as a dependency, it is checked whether the latter is already loaded. If yes, the loaded version is considered compatible if:
1) no specific version was required by the former library
2) the already loaded version matches the required version exactly
3) major and minor numbers are the same and already loaded patch number is equal to the required one or higher
4) major numbers are the same and already loaded minor number is higher than the required one
5) the already loaded version is a test version and the required version is not a test version
These rules are in complicance with the SemVer standard (https://semver.org/lang/de/)
If the dependency hasn't been loaded yet, it is loaded now. In case no specific version is required, the latest numbered version is used.
Because these rules are checked sequentially for each required dependency and no unloading is performed, it is important to consider the order of required libraries. Consider the following example:
```
require "libDriverA" # sinqMotor 1.2 is specified as a dependency
require "libDriverB" # sinqMotor 1.0 is specified as a dependency
```
`require` first checks the dependencies of `libDriverA` and sees that `sinqMotor 1.2` is required. It therefore load `sinqMotor 1.2` and then `libDriverA`. Now the next `require` starts analyzing the dependencies of `libDriverB` and sees that `sinqMotor 1.0` is required. Since `sinqMotor 1.2` is already loaded, rule 4) is applied and `libDriverB` is assumed to be compatible with `sinqMotor 1.2` as well (which it should be according to SemVer).
When the order is inverted, the following happens:
```
require "libDriverB" # sinqMotor 1.0 is specified as a dependency
require "libDriverA" # sinqMotor 1.2 is specified as a dependency
```
`require` first checks the dependencies of `libDriverB` and sees that `sinqMotor 1.0` is required. It therefore load `sinqMotor 1.0` and then `libDriverB`. Now the next `require` starts analyzing the dependencies of `libDriverA` and sees that `sinqMotor 1.2` is required. Since `sinqMotor 1.0` is already loaded, `require` cannot load `sinqMotor 1.2`. Therefore the IOC startup is aborted with an error message.
In order to make the setup script more robust, it is therefore recommended to explicitly add a dependency version which is compatible to all required libraries:
```
require "sinqMotor", "1.2"
require "libDriverB" # sinqMotor 1.0 is specified as a dependency
require "libDriverA" # sinqMotor 1.2 is specified as a dependency
```
The IOC startup now succeeds because we made sure the higher version is loaded first.
Please see the README.md of https://github.com/paulscherrerinstitute/require for more details.
To find out which version of sinqMotor is needed by a driver, refer to its Makefile (line `sinqMotor_VERSION=x.x.x`, where x.x.x is the minimum required version).
### IOC startup script
@ -68,6 +107,11 @@ actualDriverAxis("$(DRIVER_PORT)",5);
# Set the number of subsequent timeouts
setMaxSubsequentTimeouts("$(DRIVER_PORT)", 20);
# Set the number of forced fast polls performed after the poller is "woken up".
# When the poller is "woken up", it performs the specified number of polls with
# the previously stated busy poll period.
setForcedFastPolls("$(DRIVER_PORT)", 10);
# Configure the timeout frequency watchdog: A maximum of 10 timeouts are allowed in 300 seconds before an alarm message is sent.
setThresholdComTimeout("$(DRIVER_PORT)", 300, 10);
@ -114,7 +158,7 @@ be further reduced by this offset in order to avoid errors due to slight oversho
on the motor controller. For example, if this value is 1.0 and the read-out limits
are [-10.0 10.0], the EPICS limits are set to [-9.0 9.0]. This parameter uses engineering units (EGU). Defaults to 0.0.
- `CANSETSPEED`: If set to 1, the motor speed can be modified by the user. Defaults to 0.
- `ADAPTPOLL`: If set to any value other than 0, adaptive polling is enabled for this particular axis. Adaptive polling is designed to reduce the communication load in case some axis is moving. By default, if at least one axis is moving, all axes are polled using the busy / moving poll period (see [IOC startup script](#ioc-startup-script)). Adaptive polling modifies this behaviour so that the affected axis is only polled with the busy / moving poll period if it itself is moving. Defaults to 1.
- `ADAPTPOLL`: If set to any value other than 0, adaptive polling is enabled for this particular axis. Adaptive polling is designed to reduce the communication load in case some axis is moving. By default, if at least one axis is moving, all axes are polled using the busy / moving poll period (see [IOC startup script](#ioc-startup-script)). Adaptive polling modifies this behaviour so that the affected axis is only polled with the busy / moving poll period if it itself is moving. This setting is ignored for "forced fast polls" (when the poller is woken up, e.g. after an axis received a move command). Defaults to 1.
### Motor record resolution MRES
@ -171,9 +215,10 @@ sinqMotor offers a variety of additional methods for children classes to standar
- `paramLibAccessFailed`: Write a standardized message if accessing the parameter library failed.
- `stringifyAsynStatus`: Convert the enum `asynStatus` into a human-readable string.
- `checkComTimeoutWatchdog`: Calculates the timeout frequency (number of timeouts in a given time) and informs the user if a specified limit has been exceeded.
- `setThresholdComTimeout`: Set the maximum number of timeouts and the time window size for the timeout frequency limit.
- `setThresholdComTimeout`: Set the maximum number of timeouts and the time window size for the timeout frequency limit. This function is also available in the IOC shell.
- `checkMaxSubsequentTimeouts`: Check if the number of subsequent timeouts exceeds a specified limit.
- `setMaxSubsequentTimeouts`: Set the limit for the number of subsequent timeouts before the user is informed.
- `setMaxSubsequentTimeouts`: Set the limit for the number of subsequent timeouts before the user is informed. This function is also available in the IOC shell.
- `setForcedFastPolls`: Set the number of forced fast polls which are performed after the poller has been "woken up" ( = after `wakePoller()` is called). This function is also available in the IOC shell.
#### sinqAxis.h
- `enable`: This function is called if the `$(INSTR)$(M):Enable` PV from db/sinqMotor.db is set.
@ -188,13 +233,14 @@ It calls `doReset` and performs some fast polls after `doReset` returns.
- `poll`: This is a wrapper around `doPoll` which performs some bookkeeping tasks before and after calling `doPoll`:
Before calling `doPoll`:
- Reset the status problem flag, the communication error flag and the error message.
- Check if the paramLib already contains an old error message. If so, put it into a temporary bufffer
After calling `doPoll`:
- Call `checkMovTimeoutWatchdog`. If the movement timed out, create an error message for the user
- Update the readback-value for the axis enablement.
- Reset `motorStatusProblem_`, `motorStatusCommsError_` and `motorMessageText_` if `doPoll` returned `asynSuccess`
- If `doPoll` returns anything other than `asynSuccess` or if an old error message is waiting in the temporary buffer, set `motorStatusProblem` to true, otherwise to false. If an old error message is waiting in the temporary buffer, but `doPoll` returned `asynSuccess`, overwrite the paramLib entry for `motorMessageText` with the old error message.
- Run `callParamCallbacks`
- Reset `motorMessageText` AFTER updating the PVs. This makes sure that the error message is shown for at least one poll cycle.
- Return the status of `doPoll`
- `motorPosition`: Returns the parameter library value of the motor position, accounted for the motor record resolution (see section "Motor record resolution MRES")
- `setMotorPosition`: Writes the given value into the parameter library, accounted for the motor record resolution (see section "Motor record resolution MRES")
@ -215,7 +261,7 @@ The versioning is done via git tags. Git tags are recognized by the PSI build sy
All existing tags can be listed with `git tag` in the sinqMotor directory. Detailed information (author, data, commit number, commit message) regarding a specific tag can be shown with `git show x.x.x`, where `x.x.x` is the name of your version. To create a new tag, use `git tag x.x.x`. If the tag `x.x.x` is already used by another commit, git will show a corresponding error.
### How to build it
### Dependencies
This library is based on the PSI version of the EPICS motor record, which can be found here: `https://git.psi.ch/epics_driver_modules/motorBase`. We use a branch with a bugfix which is currently not merged into master due to resistance of the PSI userbase: `https://git.psi.ch/epics_driver_modules/motorBase/-/tree/pick_fix-lockup-VAL-HOMF-VAL`. This library can be build with the following steps, assuming GCC and make are available:
- `git clone https://git.psi.ch/epics_driver_modules/motorBase/-/tree/pick_fix-lockup-VAL-HOMF-VAL`
@ -223,6 +269,26 @@ This library is based on the PSI version of the EPICS motor record, which can be
- `git tag 7.2.2`. The latest version on master is currently 7.2.1, hence we increment the bugfix version counter by one
- `make install`
To build sinqMotor itself, the makefile in the top directory includes all necessary steps for compiling a shared library together with the header files into `/ioc/modules` (using the PSI EPICS build system). Therefore it is sufficient to clone this repository to a suitable location (`git clone https://git.psi.ch/sinq-epics-modules/sinqmotor/-/tree/main`). Afterwards, switch to the directory (`cd sinqmotor`) and run `make install`.
### Usage as dynamic dependency
The makefile in the top directory includes all necessary steps for compiling a shared library of sinqMotor together with the header files into `/ioc/modules` (using the PSI EPICS build system). Therefore it is sufficient to clone this repository to a suitable location (`git clone https://git.psi.ch/sinq-epics-modules/sinqmotor/-/tree/main`). Afterwards, switch to the directory (`cd sinqmotor`) and run `make install`.
To use the library when writing a concrete motor driver, include it in the makefile of your application / library the same way as other libraries such as e.g. `asynMotor` by adding `REQUIRED+=sinqMotor` to your Makefile. The version can be specified with `sinqMotor_VERSION=x.x.x.`
### Usage as static dependency
This repository is included as a git submodule in some of the driver repositories depending upon sinqMotor. When installing via a Makefile (`make install`) using the PSI build system, the following git command is executed within `/ioc/tools/driver.makefile`:
`git submodule update --init --recursive`
This forces each submodule to be checked out at the latest commit hash stored in the remote repository. However, this is usually unwanted behaviour, since the higher-level drivers are usually designed to be compiled against a specific version of sinqMotor. In order to set the submodule to a specific version, the following steps need to be done BEFORE calling `make install`:
- `cd sinqMotor`
- `git checkout 0.1`
- `cd ..`
Then, the fixation of the version to 0.1 needs to be committed in the parent repository:
- `git commit -m "Update sinqMotor to 0.1"`
After this commit, running `make install` will use the correct driver version for compilation.

View File

@ -1,3 +1,5 @@
# SPDX-License-Identifier: GPL-3.0-only
record(asyn,"$(P)")
{
field(DTYP,"asynRecordDevice")

View File

@ -1,3 +1,5 @@
# SPDX-License-Identifier: GPL-3.0-only
# The main asyn motor record. Some fields are populated from the substitution
# files via macros:
# - INSTR: Name of the instrument, e.g. "SQ:SINQTEST:"
@ -54,6 +56,18 @@ record(calc, "$(INSTR)$(M):StatusProblem")
field(CALC, "A >> 9")
}
# If the value of this PV is 0, the according axis is currently disconnected from the controller.
# Trying to give commands to a disconnected axis will result in an error message in the IOC shell
# This record is coupled to the parameter library via motorConnected_ -> MOTOR_CONNECTED.
record(longin, "$(INSTR)$(M):Connected")
{
field(DTYP, "asynInt32")
field(INP, "@asyn($(CONTROLLER),$(AXIS)) MOTOR_CONNECTED")
field(SCAN, "I/O Intr")
field(PINI, "NO")
field(VAL, "1")
}
# Call the reset function of the corresponding sinqAxis
# This record is coupled to the parameter library via motorReset_ -> MOTOR_RESET.
record(longout, "$(INSTR)$(M):Reset") {

View File

@ -1,12 +1,16 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "msgPrintControl.h"
#include <unordered_map>
msgPrintControlKey::msgPrintControlKey(char *controller, int axisNo,
const char *functionName, int line) {
const char *functionName, int line,
size_t maxRepetitions) {
controller_ = controller;
axisNo_ = axisNo;
line_ = line;
functionName_ = functionName;
maxRepetitions_ = maxRepetitions;
}
void msgPrintControlKey::format(char *buffer, size_t bufferSize) {
@ -16,9 +20,7 @@ void msgPrintControlKey::format(char *buffer, size_t bufferSize) {
// =============================================================================
msgPrintControl::msgPrintControl(size_t maxRepetitions) {
maxRepetitions_ = maxRepetitions;
}
msgPrintControl::~msgPrintControl() = default;
bool msgPrintControl::shouldBePrinted(msgPrintControlKey &key, bool wantToPrint,
asynUser *pasynUser) {
@ -34,12 +36,12 @@ bool msgPrintControl::shouldBePrinted(msgPrintControlKey &key, bool wantToPrint,
*/
if (map_.find(key) != map_.end()) {
size_t repetitions = map_[key];
if (repetitions < maxRepetitions_) {
if (repetitions < key.maxRepetitions_) {
// Number of allowed repetitions not exceeded -> Printing the
// message is ok.
map_[key] = repetitions + 1;
return true;
} else if (repetitions == maxRepetitions_) {
} else if (repetitions == key.maxRepetitions_) {
// Reached number of allowed repetitions -> Printing the message
// is ok, but further trys are rejected.
char formattedKey[100] = {0};
@ -88,7 +90,8 @@ bool msgPrintControl::shouldBePrinted(msgPrintControlKey &key, bool wantToPrint,
bool msgPrintControl::shouldBePrinted(char *portName, int axisNo,
const char *functionName, int line,
bool wantToPrint, asynUser *pasynUser) {
bool wantToPrint, asynUser *pasynUser,
size_t maxRepetitions) {
msgPrintControlKey key =
msgPrintControlKey(portName, axisNo, functionName, __LINE__);
return shouldBePrinted(key, wantToPrint, pasynUser);

View File

@ -1,6 +1,10 @@
// SPDX-License-Identifier: GPL-3.0-only
#ifndef msgPrintControl_H
#define msgPrintControl_H
#define DefaultMaxRepetitions 4
#include <asynDriver.h>
#include <string.h>
#include <string>
@ -21,8 +25,15 @@ class msgPrintControlKey {
const char *functionName_;
int line_;
/**
* @brief Maximum number of times a message is printed before it is
* suppressed. This number is not used as part of the hash.
*
*/
size_t maxRepetitions_;
msgPrintControlKey(char *controller_, int axisNo, const char *fileName,
int line);
int line, size_t maxRepetitions = DefaultMaxRepetitions);
bool operator==(const msgPrintControlKey &other) const {
return axisNo_ == other.axisNo_ && line_ == other.line_ &&
@ -73,7 +84,11 @@ template <> struct hash<msgPrintControlKey> {
*/
class msgPrintControl {
public:
msgPrintControl(size_t maxRepetitions);
/**
* @brief Destroy the msgPrintControl object
*
*/
~msgPrintControl();
/**
* @brief Checks if the error message associated with "key" has been printed
@ -115,7 +130,8 @@ class msgPrintControl {
* @param pasynUser
*/
bool shouldBePrinted(char *controller, int axisNo, const char *functionName,
int line, bool wantToPrint, asynUser *pasynUser);
int line, bool wantToPrint, asynUser *pasynUser,
size_t maxRepetitions = DefaultMaxRepetitions);
/**
* @brief Reset the error message count incremented in `shouldBePrinted` for
@ -129,13 +145,6 @@ class msgPrintControl {
*/
void resetCount(msgPrintControlKey &key, asynUser *pasynUser);
/**
* @brief Maximum number of times a message is printed before it is
* suppressed.
*
*/
size_t maxRepetitions_;
char *getSuffix();
private:

View File

@ -1,27 +1,56 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "sinqAxis.h"
#include "epicsExport.h"
#include "iocsh.h"
#include "msgPrintControl.h"
#include "sinqController.h"
#include <epicsTime.h>
#include <errlog.h>
#include <math.h>
#include <unistd.h>
#define getControllerMethod pController
struct sinqAxisImpl {
// Internal variables used in the movement timeout watchdog
time_t expectedArrivalTime;
time_t offsetMovTimeout;
double scaleMovTimeout;
bool watchdogMovActive;
// Store the motor target position for the movement time calculation
double targetPosition;
bool wasMoving;
/*
Store the time since the last poll
*/
epicsTimeStamp lastPollTime;
};
sinqAxis::sinqAxis(class sinqController *pC, int axisNo)
: asynMotorAxis((asynMotorController *)pC, axisNo), pC_(pC) {
asynStatus status = asynSuccess;
watchdogMovActive_ = false;
scaleMovTimeout_ = 2.0;
offsetMovTimeout_ = 30;
targetPosition_ = 0.0;
wasMoving_ = false;
epicsTimeStamp lastPollTime;
epicsTimeGetCurrent(&lastPollTime);
epicsTimeGetCurrent(&lastPollTime_);
pSinqA_ = std::make_unique<sinqAxisImpl>(
(sinqAxisImpl){.expectedArrivalTime = 0,
.offsetMovTimeout = 30,
.scaleMovTimeout = 2.0,
.watchdogMovActive = false,
.targetPosition = 0.0,
.wasMoving = false,
.lastPollTime = lastPollTime});
// This check is also done in asynMotorAxis, but there the IOC continues
// running even though the configuration is incorrect. When failing this
// check, the IOC is stopped, since this is definitely a configuration
// problem.
/*
This check is also done in asynMotorAxis, but there the IOC continues
running even though the configuration is incorrect. When failing this check,
the IOC is stopped, since this is definitely a configuration problem.
*/
if ((axisNo < 0) || (axisNo >= pC->numAxes())) {
asynPrint(pC_->pasynUser(), ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line %d:\nFATAL ERROR "
@ -31,6 +60,21 @@ sinqAxis::sinqAxis(class sinqController *pC, int axisNo)
exit(-1);
}
/*
Initialize the parameter library entry for the motor message text, because
it is read during the first poll before it has been written to.
*/
status = setStringParam(pC_->motorMessageText(), "");
if (status != asynSuccess) {
asynPrint(pC_->pasynUser(), ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line %d:\nFATAL ERROR "
"(setting a parameter value failed "
"with %s)\n. Terminating IOC",
pC->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__,
pC_->stringifyAsynStatus(status));
exit(-1);
}
// Motor is assumed to be enabled
status = setIntegerParam(pC_->motorEnableRBV(), 1);
if (status != asynSuccess) {
@ -67,6 +111,18 @@ sinqAxis::sinqAxis(class sinqController *pC, int axisNo)
exit(-1);
}
// Assume that the motor is connected initially
status = setIntegerParam(pC_->motorConnected(), 1);
if (status != asynSuccess) {
asynPrint(pC_->pasynUser(), ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line %d:\nFATAL ERROR "
"(setting a parameter value failed "
"with %s)\n. Terminating IOC",
pC->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__,
pC_->stringifyAsynStatus(status));
exit(-1);
}
// We assume that the motor has no status problems initially
status = setIntegerParam(pC_->motorStatusProblem(), 0);
if (status != asynSuccess) {
@ -112,13 +168,17 @@ sinqAxis::sinqAxis(class sinqController *pC, int axisNo)
}
}
sinqAxis::~sinqAxis() = default;
asynStatus sinqAxis::poll(bool *moving) {
// Local variable declaration
asynStatus pl_status = asynSuccess;
asynStatus poll_status = asynSuccess;
int homing = 0;
int homed = 0;
int adaptivePolling = 0;
char waitingMessage[pC_->MAXBUF_] = {0};
char newMessage[pC_->MAXBUF_] = {0};
/*
If adaptive polling is enabled:
@ -128,13 +188,7 @@ asynStatus sinqAxis::poll(bool *moving) {
- If yes, perform the poll
- If no, skip it
*/
pl_status =
pC_->getIntegerParam(axisNo_, pC_->adaptivePolling(), &adaptivePolling);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "adaptivePolling", axisNo_,
__PRETTY_FUNCTION__, __LINE__);
};
getAxisParamChecked(this, adaptivePolling, &adaptivePolling);
// Using the EPICS timestamp here, see
// https://docs.epics-controls.org/projects/base/en/latest/epicsTime_h.html#_CPPv414epicsTimeStamp
@ -143,12 +197,16 @@ asynStatus sinqAxis::poll(bool *moving) {
epicsTimeStamp ts;
epicsTimeGetCurrent(&ts);
if (adaptivePolling != 0) {
/*
Check if both adaptive polling is enabled and no forced fast polls are still
required.
*/
if (adaptivePolling != 0 && pC_->outstandingForcedFastPolls() == 0) {
// Motor wasn't moving during the last poll
if (!wasMoving_) {
if (!pSinqA_->wasMoving) {
// Add the idle poll period
epicsTimeStamp earliestTimeNextPoll = lastPollTime_;
epicsTimeStamp earliestTimeNextPoll = pSinqA_->lastPollTime;
epicsTimeAddSeconds(&earliestTimeNextPoll, pC_->idlePollPeriod());
if (epicsTimeLessThanEqual(&earliestTimeNextPoll, &ts) == 0) {
@ -157,85 +215,68 @@ asynStatus sinqAxis::poll(bool *moving) {
}
}
}
// Update the start time of the last poll
lastPollTime_ = ts;
pSinqA_->lastPollTime = ts;
/*
At the beginning of the poll, it is assumed that the axis has no status
problems and therefore all error indicators are reset. This does not affect
the PVs until callParamCallbacks has been called!
The motorStatusProblem_ field changes the motor record fields SEVR and STAT.
If the "motorMessageText" record currently contains an error message, it
should be shown for at least one poll period. To assure this, it is read out
here from the paramLib into "waitingMessage". If no new error message was
added to the parameter library at the end of the poll cycle, the
"waitingMessage" is briefly put into the paramLib again, then the PVs are
updated and then the message text is cleared again.
*/
pl_status = setIntegerParam(pC_->motorStatusProblem(), false);
if (pl_status != asynSuccess) {
pC_->paramLibAccessFailed(pl_status, "motorStatusProblem_", axisNo_,
__PRETTY_FUNCTION__, __LINE__);
}
pl_status = setIntegerParam(pC_->motorStatusCommsError(), false);
if (pl_status != asynSuccess) {
pC_->paramLibAccessFailed(pl_status, "motorStatusCommsError_", axisNo_,
__PRETTY_FUNCTION__, __LINE__);
}
pl_status = setStringParam(pC_->motorMessageText(), "");
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorMessageText_",
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
}
getAxisParamChecked(this, motorMessageText,
static_cast<char *>(waitingMessage));
// The poll function is just a wrapper around doPoll and
// handles mainly the callParamCallbacks() function. This wrapper is used
// to make sure callParamCallbacks() is called in case of a premature
// return.
// Clear the communication
setAxisParamChecked(this, motorStatusCommsError, false);
/*
The poll function is just a wrapper around doPoll and handles mainly the
callParamCallbacks() function. This wrapper is used to make sure
callParamCallbacks() is called in case of a premature return.
*/
poll_status = doPoll(moving);
// Motor was moving during this poll
wasMoving_ = *moving;
// The poll did not succeed: Something went wrong and the motor has a status
// problem.
if (poll_status != asynSuccess) {
pl_status = setIntegerParam(pC_->motorStatusProblem(), true);
if (pl_status != asynSuccess) {
pC_->paramLibAccessFailed(pl_status, "motorStatusProblem_", axisNo_,
__PRETTY_FUNCTION__, __LINE__);
/*
If the poll did not succeed OR if an error message is waiting, something
went wrong and the motor has a status problem. Otherwise, delete the error
message entry which is currently in the paramLib.
*/
if (poll_status != asynSuccess || waitingMessage[0] != '\0') {
/*
If doPoll cleared the error message paramLib entry, but an old message
is still waiting, set the old message.
*/
getAxisParamChecked(this, motorMessageText,
static_cast<char *>(newMessage));
if (newMessage[0] == '\0') {
setAxisParamChecked(this, motorMessageText,
static_cast<char *>(waitingMessage));
}
setAxisParamChecked(this, motorStatusProblem, true);
} else {
// No errors are waiting -> Clear everything.
setAxisParamChecked(this, motorMessageText, "");
setAxisParamChecked(this, motorStatusProblem, false);
}
pl_status = pC_->getIntegerParam(axisNo_, pC_->motorStatusHomed(), &homed);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorStatusHomed_",
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
}
pl_status = pC_->getIntegerParam(axisNo_, pC_->motorStatusHome(), &homing);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorStatusHome_", axisNo_,
__PRETTY_FUNCTION__, __LINE__);
/*
Motor is in homing mode, was moving, but is not moving anymore -> It can be
assumed that the homing procedure is done.
*/
getAxisParamChecked(this, motorStatusHome, &homing);
if (homing == 1 && !(*moving) && pSinqA_->wasMoving) {
setAxisParamChecked(this, motorStatusHome, false);
setAxisParamChecked(this, motorStatusHomed, true);
setAxisParamChecked(this, motorStatusAtHome, true);
}
if (homing == 1 && !(*moving)) {
// Set the homing-related flags
pl_status = setIntegerParam(pC_->motorStatusHome(), 0);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorStatusHome_",
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
}
pl_status = setIntegerParam(pC_->motorStatusHomed(), 1);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorStatusHomed_",
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
}
pl_status = setIntegerParam(pC_->motorStatusAtHome(), 1);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorStatusAtHome_",
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
}
// Update the wasMoving status
if (pC_->outstandingForcedFastPolls() == 0) {
pSinqA_->wasMoving = *moving;
}
// Check and update the watchdog
@ -261,6 +302,12 @@ asynStatus sinqAxis::poll(bool *moving) {
poll_status = pl_status;
}
/*
Delete the error message AFTER updating the PVs so it is not there anymore
during the next poll.
*/
setAxisParamChecked(this, motorMessageText, "");
return poll_status;
}
@ -271,39 +318,31 @@ asynStatus sinqAxis::move(double position, int relative, double minVelocity,
// Status of parameter library operations
asynStatus status = asynSuccess;
double motorRecResolution = 0.0;
double motorRecRes = 0.0;
// =========================================================================
// Store the target position internally
targetPosition_ = position * motorRecResolution;
getAxisParamChecked(this, motorRecResolution, &motorRecRes);
pSinqA_->targetPosition = position * motorRecRes;
status = doMove(position, relative, minVelocity, maxVelocity, acceleration);
if (status != asynSuccess) {
return status;
}
// Since the move command was successfull, we assume that the motor has
// started its movement.
status = setIntegerParam(pC_->motorStatusHomed(), 0);
status = assertConnected();
if (status != asynSuccess) {
return pC_->paramLibAccessFailed(status, "motorStatusHomed_", axisNo_,
__PRETTY_FUNCTION__, __LINE__);
}
status = setIntegerParam(pC_->motorStatusAtHome(), 0);
if (status != asynSuccess) {
return pC_->paramLibAccessFailed(status, "motorStatusAtHome_", axisNo_,
__PRETTY_FUNCTION__, __LINE__);
}
status = pC_->getDoubleParam(axisNo_, pC_->motorRecResolution(),
&motorRecResolution);
if (status != asynSuccess) {
return pC_->paramLibAccessFailed(status, "motorRecResolution_", axisNo_,
__PRETTY_FUNCTION__, __LINE__);
return status;
}
// Since the move command was successfull, we assume that the motor has
// started its movement.
setAxisParamChecked(this, motorStatusHomed, false);
setAxisParamChecked(this, motorStatusAtHome, false);
// Needed for adaptive polling
wasMoving_ = true;
pSinqA_->wasMoving = true;
return pC_->callParamCallbacks();
}
@ -322,45 +361,25 @@ asynStatus sinqAxis::home(double minVelocity, double maxVelocity,
if (status == asynSuccess) {
status = setStringParam(pC_->motorMessageText(), "Homing");
if (status != asynSuccess) {
return pC_->paramLibAccessFailed(status, "motorMessageText_",
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
}
setAxisParamChecked(this, motorStatusHome, true);
setAxisParamChecked(this, motorStatusHomed, false);
setAxisParamChecked(this, motorStatusAtHome, false);
pSinqA_->wasMoving = true;
// Set the homing-related flags
status = setIntegerParam(pC_->motorStatusHome(), 1);
status = assertConnected();
if (status != asynSuccess) {
return pC_->paramLibAccessFailed(status, "motorStatusHome_",
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
return status;
}
// Set field ATHM to zero
status = setIntegerParam(pC_->motorStatusHomed(), 0);
if (status != asynSuccess) {
return pC_->paramLibAccessFailed(status, "motorStatusHomed_",
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
}
status = setIntegerParam(pC_->motorStatusAtHome(), 0);
if (status != asynSuccess) {
return pC_->paramLibAccessFailed(status, "motorStatusAtHome_",
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
}
// Update the motor record
return callParamCallbacks();
return pC_->wakeupPoller();
} else if (status == asynError) {
// asynError means that we tried to home an absolute encoder
status = setStringParam(pC_->motorMessageText(),
"Can't home a motor with absolute encoder");
setAxisParamChecked(this, motorMessageText,
"Can't home a motor with absolute encoder");
status = assertConnected();
if (status != asynSuccess) {
return pC_->paramLibAccessFailed(status, "motorMessageText_",
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
return status;
}
// Update the motor record
@ -378,18 +397,17 @@ asynStatus sinqAxis::doHome(double minVelocity, double maxVelocity,
asynStatus sinqAxis::reset() {
asynStatus status = doReset();
if (status == asynSuccess) {
// Perform some fast polls
pC_->lock();
bool moving = false;
for (int i = 0; i < 5; i++) {
epicsThreadSleep(pC_->movingPollPeriod());
if (poll(&moving) == asynSuccess) {
break;
}
}
pC_->unlock();
pC_->wakeupPoller();
}
status = assertConnected();
if (status != asynSuccess) {
return status;
}
return status;
}
@ -397,63 +415,56 @@ asynStatus sinqAxis::doReset() { return asynError; }
asynStatus sinqAxis::enable(bool on) { return asynSuccess; }
asynStatus sinqAxis::motorPosition(double *motorPosition) {
asynStatus sinqAxis::motorPosition(double *motorPos) {
asynStatus status = asynSuccess;
double motorRecResolution = 0.0;
double motorRecRes = 0.0;
status = pC_->getDoubleParam(axisNo(), pC_->motorRecResolution(),
&motorRecResolution);
getAxisParamChecked(this, motorRecResolution, &motorRecRes);
/*
We cannot use getAxisParamChecked checked here, since the name of the index
getter function of the controller and this function have the same name.
Therefore we implement this manually
*/
status = pC_->getDoubleParam(axisNo(), pC_->motorPosition(), motorPos);
if (status != asynSuccess) {
return pC_->paramLibAccessFailed(status, "motorRecResolution_",
axisNo(), __PRETTY_FUNCTION__,
__LINE__);
return pC_->paramLibAccessFailed(status, "motorPosition", axisNo(),
__PRETTY_FUNCTION__, __LINE__);
}
status = pC_->getDoubleParam(axisNo(), pC_->motorPosition(), motorPosition);
if (status != asynSuccess) {
return pC_->paramLibAccessFailed(status, "motorPosition_", axisNo(),
__PRETTY_FUNCTION__,
__LINE__);
}
*motorPosition = *motorPosition * motorRecResolution;
*motorPos = *motorPos * motorRecRes;
return status;
}
asynStatus sinqAxis::setMotorPosition(double motorPosition) {
asynStatus sinqAxis::setMotorPosition(double motorPos) {
asynStatus status = asynSuccess;
double motorRecResolution = 0.0;
double motorRecRes = 0.0;
status = pC_->getDoubleParam(axisNo(), pC_->motorRecResolution(),
&motorRecResolution);
if (status != asynSuccess) {
return pC_->paramLibAccessFailed(status, "motorRecResolution_",
axisNo(), __PRETTY_FUNCTION__,
__LINE__);
}
getAxisParamChecked(this, motorRecResolution, &motorRecRes);
setAxisParamChecked(this, motorPosition, motorPos / motorRecRes);
status = setDoubleParam(pC_->motorPosition(),
motorPosition / motorRecResolution);
if (status != asynSuccess) {
return pC_->paramLibAccessFailed(status, "motorPosition_", axisNo(),
__PRETTY_FUNCTION__,
__LINE__);
}
return status;
}
asynStatus sinqAxis::assertConnected() {
int connected = 0;
getAxisParamChecked(this, motorConnected, &connected);
if (connected == 0) {
asynPrint(pC_->pasynUser(), ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line "
"%d:\nAxis is not connected, all commands are ignored.\n",
pC_->portName, axisNo(), __PRETTY_FUNCTION__, __LINE__);
}
return asynSuccess;
}
asynStatus sinqAxis::setVeloFields(double velo, double vbas, double vmax) {
asynStatus status = asynSuccess;
int variableSpeed = 0;
// Can the speed of the motor be varied?
status =
pC_->getIntegerParam(axisNo_, pC_->motorCanSetSpeed(), &variableSpeed);
if (status != asynSuccess) {
return pC_->paramLibAccessFailed(status, "motorCanSetSpeed_", axisNo_,
__PRETTY_FUNCTION__, __LINE__);
}
getAxisParamChecked(this, motorCanSetSpeed, &variableSpeed);
if (variableSpeed == 1) {
// Check the inputs and create corresponding error messages
@ -464,15 +475,9 @@ asynStatus sinqAxis::setVeloFields(double velo, double vbas, double vmax) {
"vmax=%lf.\n",
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__,
vbas, vmax);
status = setStringParam(
pC_->motorMessageText(),
setAxisParamChecked(
this, motorMessageText,
"Lower speed limit must not be smaller than upper speed limit");
if (status != asynSuccess) {
return pC_->paramLibAccessFailed(status, "motorMessageText_",
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
}
return asynError;
}
if (velo < vbas || velo > vmax) {
@ -483,58 +488,19 @@ asynStatus sinqAxis::setVeloFields(double velo, double vbas, double vmax) {
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__,
velo, vbas, vmax);
status = setStringParam(pC_->motorMessageText(),
"Speed is not inside limits");
if (status != asynSuccess) {
return pC_->paramLibAccessFailed(status, "motorMessageText_",
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
}
setAxisParamChecked(this, motorMessageText,
"Speed is not inside limits");
return asynError;
}
status = pC_->setDoubleParam(axisNo_, pC_->motorVbasFromDriver(), vbas);
if (status != asynSuccess) {
return pC_->paramLibAccessFailed(status, "motorVbasFromDriver_",
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
}
status = pC_->setDoubleParam(axisNo_, pC_->motorVeloFromDriver(), velo);
if (status != asynSuccess) {
return pC_->paramLibAccessFailed(status, "motorVeloFromDriver_",
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
}
status = pC_->setDoubleParam(axisNo_, pC_->motorVmaxFromDriver(), vmax);
if (status != asynSuccess) {
return pC_->paramLibAccessFailed(status, "motorVmaxFromDriver_",
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
}
setAxisParamChecked(this, motorVbasFromDriver, vbas);
setAxisParamChecked(this, motorVeloFromDriver, velo);
setAxisParamChecked(this, motorVmaxFromDriver, vmax);
} else {
// Set minimum and maximum speed equal to the set speed
status = pC_->setDoubleParam(axisNo_, pC_->motorVbasFromDriver(), velo);
if (status != asynSuccess) {
return pC_->paramLibAccessFailed(status, "motorVbasFromDriver_",
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
}
status = pC_->setDoubleParam(axisNo_, pC_->motorVeloFromDriver(), velo);
if (status != asynSuccess) {
return pC_->paramLibAccessFailed(status, "motorVeloFromDriver_",
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
}
status = pC_->setDoubleParam(axisNo_, pC_->motorVmaxFromDriver(), velo);
if (status != asynSuccess) {
return pC_->paramLibAccessFailed(status, "motorVmaxFromDriver_",
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
}
setAxisParamChecked(this, motorVbasFromDriver, velo);
setAxisParamChecked(this, motorVeloFromDriver, velo);
setAxisParamChecked(this, motorVmaxFromDriver, velo);
}
return status;
}
@ -545,30 +511,20 @@ asynStatus sinqAxis::setAcclField(double accl) {
return asynError;
}
asynStatus status = setDoubleParam(pC_->motorAcclFromDriver(), accl);
if (status != asynSuccess) {
return pC_->paramLibAccessFailed(status, "motorAcclFromDriver_",
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
}
return status;
setAxisParamChecked(this, motorAcclFromDriver, accl);
return asynSuccess;
}
asynStatus sinqAxis::setWatchdogEnabled(bool enable) {
return setIntegerParam(pC_->motorEnableMovWatchdog(), enable);
setAxisParamChecked(this, motorEnableMovWatchdog, enable);
return asynSuccess;
}
asynStatus sinqAxis::startMovTimeoutWatchdog() {
asynStatus pl_status;
int enableMovWatchdog = 0;
pl_status = pC_->getIntegerParam(axisNo_, pC_->motorEnableMovWatchdog(),
&enableMovWatchdog);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorEnableMovWatchdog_",
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
}
getAxisParamChecked(this, motorEnableMovWatchdog, &enableMovWatchdog);
if (enableMovWatchdog == 1) {
// These parameters are only needed in this branch
@ -577,12 +533,12 @@ asynStatus sinqAxis::startMovTimeoutWatchdog() {
double motorVelocityRec = 0.0;
double motorAccel = 0.0;
double motorAccelRec = 0.0;
double motorRecResolution = 0.0;
double motorRecRes = 0.0;
time_t timeContSpeed = 0;
time_t timeAccel = 0;
// Activate the watchdog
watchdogMovActive_ = true;
pSinqA_->watchdogMovActive = true;
/*
NOTE: This function must not be called in the constructor (e.g. in order
@ -606,32 +562,25 @@ asynStatus sinqAxis::startMovTimeoutWatchdog() {
= VELO / MRES motorAccel = (motorVelocity - motorVelBase) / ACCL
Therefore, we need to correct the values from the parameter library.
*/
pl_status = pC_->getDoubleParam(axisNo_, pC_->motorRecResolution(),
&motorRecResolution);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorRecResolution_",
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
}
getAxisParamChecked(this, motorRecResolution, &motorRecRes);
// Read the velocity
pl_status = pC_->getDoubleParam(axisNo_, pC_->motorVelocity(),
&motorVelocityRec);
getAxisParamChecked(this, motorVelocity, &motorVelocityRec);
// Only calculate timeContSpeed if the motorVelocity has been populated
// with a sensible value (e.g. > 0)
if (pl_status == asynSuccess && motorVelocityRec > 0.0) {
// Convert back to the value in the VELO field
motorVelocity = motorVelocityRec * motorRecResolution;
motorVelocity = motorVelocityRec * motorRecRes;
if (pl_status == asynSuccess) {
timeContSpeed = std::ceil(
std::fabs(targetPosition_ - motorPos) / motorVelocity);
timeContSpeed =
std::ceil(std::fabs(pSinqA_->targetPosition - motorPos) /
motorVelocity);
}
}
pl_status =
pC_->getDoubleParam(axisNo_, pC_->motorAccel(), &motorAccelRec);
getAxisParamChecked(this, motorAccel, &motorAccelRec);
if (pl_status == asynSuccess && motorVelocityRec > 0.0 &&
motorAccelRec > 0.0) {
@ -643,30 +592,23 @@ asynStatus sinqAxis::startMovTimeoutWatchdog() {
}
// Calculate the expected arrival time
expectedArrivalTime_ =
time(NULL) + offsetMovTimeout_ +
scaleMovTimeout_ * (timeContSpeed + 2 * timeAccel);
pSinqA_->expectedArrivalTime =
time(NULL) + pSinqA_->offsetMovTimeout +
pSinqA_->scaleMovTimeout * (timeContSpeed + 2 * timeAccel);
} else {
watchdogMovActive_ = false;
pSinqA_->watchdogMovActive = false;
}
return asynSuccess;
}
asynStatus sinqAxis::checkMovTimeoutWatchdog(bool moving) {
asynStatus pl_status;
int enableMovWatchdog = 0;
pl_status = pC_->getIntegerParam(axisNo_, pC_->motorEnableMovWatchdog(),
&enableMovWatchdog);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorEnableMovWatchdog_",
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
}
getAxisParamChecked(this, motorEnableMovWatchdog, &enableMovWatchdog);
// Not moving or watchdog not active / enabled
if (enableMovWatchdog == 0 || !moving || !watchdogMovActive_) {
watchdogMovActive_ = false;
if (enableMovWatchdog == 0 || !moving || !pSinqA_->watchdogMovActive) {
pSinqA_->watchdogMovActive = false;
return asynSuccess;
}
@ -676,7 +618,7 @@ asynStatus sinqAxis::checkMovTimeoutWatchdog(bool moving) {
__PRETTY_FUNCTION__, __LINE__);
// Check if the expected time of arrival has been exceeded.
if (expectedArrivalTime_ < time(NULL)) {
if (pSinqA_->expectedArrivalTime < time(NULL)) {
// Check the watchdog
if (pC_->getMsgPrintControl().shouldBePrinted(key, true,
pC_->pasynUser())) {
@ -684,23 +626,13 @@ asynStatus sinqAxis::checkMovTimeoutWatchdog(bool moving) {
"Controller \"%s\", axis %d => %s, line %d:\nExceeded "
"expected arrival time %ld (current time is %ld).\n",
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__,
expectedArrivalTime_, time(NULL));
pSinqA_->expectedArrivalTime, time(NULL));
}
pl_status = setStringParam(
pC_->motorMessageText(),
setAxisParamChecked(
this, motorMessageText,
"Exceeded expected arrival time. Check if the axis is blocked.");
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorMessageText_",
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
}
pl_status = setIntegerParam(pC_->motorStatusProblem(), true);
if (pl_status != asynSuccess) {
pC_->paramLibAccessFailed(pl_status, "motorStatusProblem_", axisNo_,
__PRETTY_FUNCTION__, __LINE__);
}
setAxisParamChecked(this, motorStatusProblem, true);
} else {
pC_->getMsgPrintControl().resetCount(key, pC_->pasynUser());
}
@ -709,6 +641,26 @@ asynStatus sinqAxis::checkMovTimeoutWatchdog(bool moving) {
return asynSuccess;
}
asynStatus sinqAxis::setOffsetMovTimeout(time_t offsetMovTimeout) {
pSinqA_->offsetMovTimeout = offsetMovTimeout;
return asynSuccess;
}
asynStatus sinqAxis::setScaleMovTimeout(time_t scaleMovTimeout) {
pSinqA_->scaleMovTimeout = scaleMovTimeout;
return asynSuccess;
}
bool sinqAxis::wasMoving() { return pSinqA_->wasMoving; }
void sinqAxis::setWasMoving(bool wasMoving) { pSinqA_->wasMoving = wasMoving; }
double sinqAxis::targetPosition() { return pSinqA_->targetPosition; }
void sinqAxis::setTargetPosition(double targetPosition) {
pSinqA_->targetPosition = targetPosition;
}
// =============================================================================
// IOC shell functions
extern "C" {

View File

@ -1,3 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
This class extends asynMotorAxis by some features used in SINQ.
@ -7,7 +9,10 @@ Stefan Mathis, November 2024
#ifndef sinqAxis_H
#define sinqAxis_H
#include "asynMotorAxis.h"
#include <epicsTime.h>
#include <memory>
#include <type_traits>
struct sinqAxisImpl;
class epicsShareClass sinqAxis : public asynMotorAxis {
public:
@ -19,6 +24,13 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
*/
sinqAxis(class sinqController *pC_, int axisNo);
/**
* @brief Destroy the sinqAxis object
*
* This destructor is necessary in order to use the PIMPL idiom.
*/
~sinqAxis();
/**
* @brief Perform some standardized operations before and after the concrete
`doPoll` implementation.
@ -46,7 +58,7 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
the parameter library operation fails (in that case, returns the status of
the failed operation.
*/
asynStatus poll(bool *moving);
virtual asynStatus poll(bool *moving);
/**
* @brief Implementation of the "proper", device-specific poll method. This
@ -76,8 +88,8 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
the parameter library operation fails (in that case, returns the failed
operation status).
*/
asynStatus move(double position, int relative, double minVelocity,
double maxVelocity, double acceleration);
virtual asynStatus move(double position, int relative, double minVelocity,
double maxVelocity, double acceleration);
/**
* @brief Implementation of the "proper", device-specific move method. This
@ -140,8 +152,8 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
the parameter library operation fails (in that case, returns the failed
operation status).
*/
asynStatus home(double minVelocity, double maxVelocity, double acceleration,
int forwards);
virtual asynStatus home(double minVelocity, double maxVelocity,
double acceleration, int forwards);
/**
* @brief Implementation of the "proper", device-specific home method. This
@ -167,7 +179,7 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
*
* @return asynStatus
*/
asynStatus reset();
virtual asynStatus reset();
/**
* @brief Implementation of the "proper", device-specific `reset` method.
@ -237,7 +249,7 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
used to get the values for the timeout calculation failed, return that
status, otherwise return asynSuccess.
*/
asynStatus startMovTimeoutWatchdog();
virtual asynStatus startMovTimeoutWatchdog();
/**
* @brief Check if the watchdog timed out
@ -271,7 +283,7 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
* @return asynStatus Return asynError, if the watchdog timed out,
and asynSuccess otherwise.
*/
asynStatus checkMovTimeoutWatchdog(bool moving);
virtual asynStatus checkMovTimeoutWatchdog(bool moving);
/**
* @brief Enable / disable the watchdog. Also available in the IOC shell
@ -294,10 +306,7 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
* @param offsetMovTimeout Offset (in seconds)
* @return asynStatus
*/
virtual asynStatus setOffsetMovTimeout(time_t offsetMovTimeout) {
offsetMovTimeout_ = offsetMovTimeout;
return asynSuccess;
}
virtual asynStatus setOffsetMovTimeout(time_t offsetMovTimeout);
/**
* @brief Set the scaleMovTimeout. Also available in the IOC shell
@ -308,10 +317,7 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
* @param scaleMovTimeout Scaling factor (in seconds)
* @return asynStatus
*/
virtual asynStatus setScaleMovTimeout(time_t scaleMovTimeout) {
scaleMovTimeout_ = scaleMovTimeout;
return asynSuccess;
}
virtual asynStatus setScaleMovTimeout(time_t scaleMovTimeout);
/**
* @brief Return the axis number of this axis
@ -348,25 +354,405 @@ class epicsShareClass sinqAxis : public asynMotorAxis {
*/
asynStatus setMotorPosition(double motorPosition);
protected:
// Internal variables used in the movement timeout watchdog
time_t expectedArrivalTime_;
time_t offsetMovTimeout_;
/**
* @brief Check if the axis is not connected and print a corresponding error
* message
*
* This method is meant to be used at the end of "interactive" function
* calls such as move, home, stop etc which can be manually triggered from
* the IOC shell or from the channel access protocol.
*/
asynStatus assertConnected();
double scaleMovTimeout_;
bool watchdogMovActive_;
// Store the motor target position for the movement time calculation
double targetPosition_;
bool wasMoving_;
/**
* @brief Return a pointer to the axis controller.
*
* This function should be overriden in derived classes using the `override`
* keyword so the macros `getAxisParamChecked` and `setAxisParamChecked`
* work correctly:
*
* ```
* class mySpecialAxis : public sinqAxis {
public:
mySpecialController* getControllerMethod() override {
return mySpecialControllerPtr;
}
};
* ```
*/
virtual sinqController *pController() { return pC_; };
/*
Store the time since the last poll
*/
epicsTimeStamp lastPollTime_;
/**
* @brief Returns true, if the axis was moving in the last poll cycle, and
* false otherwise.
*
* @return true
* @return false
*/
bool wasMoving();
/**
* @brief Override the wasMoving flag (normally, it is automatically updated
* during each poll).
*
*/
void setWasMoving(bool wasMoving);
/**
* @brief Read out the last received target position in engineering units.
*
* @return double
*/
double targetPosition();
/**
* @brief Override the targetPosition value (normally, it is automatically
* updated at every call of the move() method).
*
*/
void setTargetPosition(double targetPosition);
private:
std::unique_ptr<sinqAxisImpl> pSinqA_;
sinqController *pC_;
};
#endif
// =============================================================================
// Helper functions and definitions for the macro setAxisParamChecked
template <typename T> struct TypeTag {};
// Generic fallback - if the compiler tries to compile this function, it fails.
template <typename A, typename C, typename T>
asynStatus setAxisParamImpl(A *axis, C *controller, const char *indexName,
int (C::*func)(), T writeValue,
const char *callerFunctionName, int lineNumber,
TypeTag<void>) {
static_assert(sizeof(T) == 0, "Unsupported type for setAxisParamImpl");
return asynError;
}
template <typename A, typename C>
asynStatus setAxisParamImpl(A *axis, C *controller, const char *indexName,
int (C::*func)(), int writeValue,
const char *callerFunctionName, int lineNumber,
TypeTag<int>) {
int indexValue = (controller->*func)();
asynStatus status = axis->setIntegerParam(indexValue, writeValue);
if (status != asynSuccess) {
return controller->paramLibAccessFailed(
status, indexName, axis->axisNo(), callerFunctionName, lineNumber);
}
return asynSuccess;
}
template <typename A, typename C>
asynStatus setAxisParamImpl(A *axis, C *controller, const char *indexName,
int (C::*func)(), bool writeValue,
const char *callerFunctionName, int lineNumber,
TypeTag<bool>) {
return setAxisParamImpl(axis, controller, indexName, func,
static_cast<int>(writeValue), callerFunctionName,
lineNumber, TypeTag<int>{});
}
template <typename A, typename C>
asynStatus setAxisParamImpl(A *axis, C *controller, const char *indexName,
int (C::*func)(), double writeValue,
const char *callerFunctionName, int lineNumber,
TypeTag<double>) {
int indexValue = (controller->*func)();
asynStatus status = axis->setDoubleParam(indexValue, writeValue);
if (status != asynSuccess) {
return controller->paramLibAccessFailed(
status, indexName, axis->axisNo(), callerFunctionName, lineNumber);
}
return asynSuccess;
}
template <typename A, typename C>
asynStatus setAxisParamImpl(A *axis, C *controller, const char *indexName,
int (C::*func)(), char *writeValue,
const char *callerFunctionName, int lineNumber,
TypeTag<char *>) {
int indexValue = (controller->*func)();
asynStatus status = axis->setStringParam(indexValue, writeValue);
if (status != asynSuccess) {
return controller->paramLibAccessFailed(
status, indexName, axis->axisNo(), callerFunctionName, lineNumber);
}
return asynSuccess;
}
template <typename A, typename C>
asynStatus setAxisParamImpl(A *axis, C *controller, const char *indexName,
int (C::*func)(), const char *writeValue,
const char *callerFunctionName, int lineNumber,
TypeTag<const char *>) {
int indexValue = (controller->*func)();
asynStatus status = axis->setStringParam(indexValue, writeValue);
if (status != asynSuccess) {
return controller->paramLibAccessFailed(
status, indexName, axis->axisNo(), callerFunctionName, lineNumber);
}
return asynSuccess;
}
/**
* @brief Helper function to set an integer / double / string parameter for an
* axis in the paramLib
*
* This function should not be used directly, but rather through its macro
* variant `setAxisParamChecked`.
*
* @tparam A
* @tparam C
* @tparam T
* @param axis
* @param controller
* @param indexName
* @param func
* @param writeValue
* @param callerFunctionName
* @param lineNumber
* @return asynStatus
*/
template <typename A, typename C, typename T>
asynStatus setAxisParam(A *axis, C *controller, const char *indexName,
int (C::*func)(), T writeValue,
const char *callerFunctionName, int lineNumber) {
return setAxisParamImpl(axis, controller, indexName, func, writeValue,
callerFunctionName, lineNumber, TypeTag<T>{});
}
/**
* @brief Macro to set an paramLib parameter and error checking the return value
*
* This macro is a wrapper around `setIntegerParam` / `setDoubleParam` /
* `setStringParam` which checks if the operation was successfull. If it wasn't,
* it returns by calling the paramLibAccessFailed function.
*
* For example, the following input:
* ```
* setAxisParamChecked(this, motorStatusProblem_, false)
* ```
* expands into the following code:
* ```
* {
* int indexValue = controller->motorStatusProblem_();
* asynStatus status = axis->setIntegerParam(indexValue, writeValue);
* if (status != asynSuccess) {
* return controller->paramLibAccessFailed(
* status, "motorStatusProblem_", axis->axisNo(), __PRETTY_FUNCTION__,
* __LINE__);
* }
* return asynSuccess;
* }
* ```
* =============================================================================
*/
#define setAxisParamChecked(axis, indexSetterFunction, writeValue) \
do { \
auto *ctrlPtr = (axis)->pController(); \
using ControllerType = \
typename std::remove_pointer<decltype(ctrlPtr)>::type; \
asynStatus setStatus = \
setAxisParam(axis, ctrlPtr, #indexSetterFunction, \
static_cast<int (ControllerType::*)()>( \
&ControllerType::indexSetterFunction), \
writeValue, __PRETTY_FUNCTION__, __LINE__); \
if (setStatus != asynSuccess) \
return setStatus; \
} while (0)
// =============================================================================
// Helper functions and definitions for the macro getAxisParamChecked
// Generic fallback - if the compiler tries to compile this function, it fails.
template <typename A, typename C, typename T>
asynStatus getAxisParamImpl(A *axis, C *controller, const char *indexName,
int (C::*func)(), T *readValue,
const char *callerFunctionName, int lineNumber,
size_t msgSize, TypeTag<void>) {
static_assert(
sizeof(T) == 0,
"no specialization of getAxisParam exists for the given type");
return asynError;
}
template <typename A, typename C>
asynStatus getAxisParamImpl(A *axis, C *controller, const char *indexName,
int (C::*func)(), int *readValue,
const char *callerFunctionName, int lineNumber,
size_t msgSize, TypeTag<int>) {
int indexValue = (controller->*func)();
asynStatus status =
controller->getIntegerParam(axis->axisNo(), indexValue, readValue);
if (status != asynSuccess) {
return controller->paramLibAccessFailed(
status, indexName, axis->axisNo(), callerFunctionName, lineNumber);
}
return asynSuccess;
}
template <typename A, typename C>
asynStatus getAxisParamImpl(A *axis, C *controller, const char *indexName,
int (C::*func)(), bool *readValue,
const char *callerFunctionName, int lineNumber,
size_t msgSize, TypeTag<bool>) {
int readValueInt = 0;
asynStatus status = getAxisParamImpl(axis, controller, indexName, func,
&readValueInt, callerFunctionName,
lineNumber, msgSize, TypeTag<int>{});
*readValue = readValueInt != 0;
return status;
}
template <typename A, typename C>
asynStatus getAxisParamImpl(A *axis, C *controller, const char *indexName,
int (C::*func)(), double *readValue,
const char *callerFunctionName, int lineNumber,
size_t msgSize, TypeTag<double>) {
int indexValue = (controller->*func)();
asynStatus status =
controller->getDoubleParam(axis->axisNo(), indexValue, readValue);
if (status != asynSuccess) {
return controller->paramLibAccessFailed(
status, indexName, axis->axisNo(), callerFunctionName, lineNumber);
}
return asynSuccess;
}
template <typename A, typename C>
asynStatus getAxisParamImpl(A *axis, C *controller, const char *indexName,
int (C::*func)(), char *readValue,
const char *callerFunctionName, int lineNumber,
size_t msgSize, TypeTag<char>) {
int indexValue = (controller->*func)();
asynStatus status = controller->getStringParam(axis->axisNo(), indexValue,
msgSize, readValue);
if (status != asynSuccess) {
return controller->paramLibAccessFailed(
status, indexName, axis->axisNo(), callerFunctionName, lineNumber);
}
return asynSuccess;
}
template <typename A, typename C>
asynStatus getAxisParamImpl(A *axis, C *controller, const char *indexName,
int (C::*func)(), std::string *readValue,
const char *callerFunctionName, int lineNumber,
size_t msgSize, TypeTag<std::string>) {
int indexValue = (controller->*func)();
// Convert the pointer to a reference, since getStringParam expects the
// latter.
std::string &rReadValue = *readValue;
asynStatus status =
controller->getStringParam(axis->axisNo(), indexValue, rReadValue);
if (status != asynSuccess) {
return controller->paramLibAccessFailed(
status, indexName, axis->axisNo(), callerFunctionName, lineNumber);
}
return asynSuccess;
}
/**
* @brief Helper function to get an integer / double / string parameter for an
* axis in the paramLib
*
* This function should not be used directly, but rather through its macro
* variant `getAxisParamChecked`.
*
* @tparam T
* @param axis
* @param controller
* @param indexName
* @param func
* @param readValue
* @param callerFunctionName
* @param lineNumber
* @param maxChars Only used when readValue is a char*. Specifies the maximum
* number of characters which can be placed into the buffer the pointer points
* to.
* @return asynStatus
*/
template <typename A, typename C, typename T>
asynStatus getAxisParam(A *axis, C *controller, const char *indexName,
int (C::*func)(), T *readValue,
const char *callerFunctionName, int lineNumber) {
return getAxisParamImpl(axis, controller, indexName, func, readValue,
callerFunctionName, lineNumber,
controller->msgSize(), TypeTag<T>{});
}
/**
* @brief Helper function to get a string parameter for an
* axis in the paramLib into a char array
*
* This function should not be used directly, but rather through its macro
* variant `getAxisParamChecked`. It is a specialized variant of the general
* getAxisParam defined above for char arrays.
*
* @tparam A
* @tparam C
* @tparam N
* @param axis
* @param controller
* @param indexName
* @param func
* @param callerFunctionName
* @param lineNumber
* @return asynStatus
*/
template <typename A, typename C, size_t N>
asynStatus getAxisParam(A *axis, C *controller, const char *indexName,
int (C::*func)(), char (*readValue)[N],
const char *callerFunctionName, int lineNumber) {
return getAxisParamImpl(axis, controller, indexName, func, *readValue,
callerFunctionName, lineNumber, N, TypeTag<char>{});
}
/**
* @brief Macro to get an paramLib parameter and error checking the return value
*
* This macro is a wrapper around `getIntegerParam` / `getDoubleParam` /
* `getStringParam` which checks if the operation was successfull. If it wasn't,
* it returns by calling the paramLibAccessFailed function. In order
*
* For example, the following input:
* ```
* getAxisParamChecked(this, motorStatusProblem_, &readValue)
* ```
* expands into the following code:
* ```
* {
* int indexValue = controller->motorStatusProblem_();
* asynStatus status = controller->getIntegerParam(axis->axisNo(),
* indexValue, readValue); if (status != asynSuccess) { return
* controller->paramLibAccessFailed( status, "motorStatusProblem_",
* axis->axisNo(), __PRETTY_FUNCTION__,
* __LINE__);
* }
* return asynSuccess;
* }
* ```
* =============================================================================
*/
#define getAxisParamChecked(axis, indexGetterFunction, readValue) \
do { \
auto *ctrlPtr = (axis)->pController(); \
using ControllerType = \
typename std::remove_pointer<decltype(ctrlPtr)>::type; \
asynStatus getStatus = \
getAxisParam(axis, ctrlPtr, #indexGetterFunction, \
static_cast<int (ControllerType::*)()>( \
&ControllerType::indexGetterFunction), \
readValue, __PRETTY_FUNCTION__, __LINE__); \
if (getStatus != asynSuccess) \
return getStatus; \
} while (0)
#endif

View File

@ -1,10 +1,16 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "sinqController.h"
#include "asynMotorController.h"
#include "asynOctetSyncIO.h"
#include "epicsExport.h"
#include "iocsh.h"
#include "msgPrintControl.h"
#include "sinqAxis.h"
#include <deque>
#include <errlog.h>
#include <initHooks.h>
#include <unordered_map>
#include <vector>
/*
@ -32,6 +38,65 @@ void sinqController::epicsInithookFunction(initHookState iState) {
}
}
struct sinqControllerImpl {
// Number of fast polls which still need to be performed before adaptive
// polling is active again.
int outstandingForcedFastPolls;
// Number of polls forced by wakeupPoller which are still
// Pointer to the port user which is specified by the char array
// `ipPortConfigName` in the constructor
asynUser *pasynOctetSyncIOipPort;
// Message print control
msgPrintControl msgPrintC;
// Internal variables used in the communication timeout frequency watchdog
time_t comTimeoutWindow; // Size of the time window
size_t maxNumberTimeouts; // Maximum acceptable number of events within the
// time window
// Deque holding the timestamps of the individual events
std::deque<time_t> timeoutEvents;
// Communicate a timeout to the user after it has happened this many times
// in a row
int maxSubsequentTimeouts;
bool maxSubsequentTimeoutsExceeded;
/*
These integers are indices to paramLib entries and are populated when the
parameters are created. See the documentation in db/sinqMotor.db.
*/
int motorMessageText;
int motorReset;
int motorEnable;
int motorEnableRBV;
int motorCanDisable;
int motorEnableMovWatchdog;
int motorCanSetSpeed;
int motorLimitsOffset;
int motorForceStop;
int motorConnected;
/*
These parameters are here to write values from the hardware to the EPICS
motor record. Using motorHighLimit_ / motorLowLimit_ does not work:
https://epics.anl.gov/tech-talk/2023/msg00576.php. Therefore, some
additional records are introduced which read from these parameters and write
into the motor record.
*/
int motorVeloFromDriver;
int motorVbasFromDriver;
int motorVmaxFromDriver;
int motorAcclFromDriver;
int motorHighLimitFromDriver;
int motorLowLimitFromDriver;
int adaptivePolling;
int encoderType;
};
#define NUM_SINQMOTOR_DRIVER_PARAMS 18
sinqController::sinqController(const char *portName,
const char *ipPortConfigName, int numAxes,
double movingPollPeriod, double idlePollPeriod,
@ -46,29 +111,22 @@ sinqController::sinqController(const char *portName,
0, // No additional interfaces beyond those in base class
0, // No additional callback interfaces beyond those in base class
ASYN_CANBLOCK | ASYN_MULTIDEVICE,
1, // autoconnect
0, 0), // Default priority and stack size
msgPrintControl_(4) {
1, // autoconnect
0, 0) // Default priority and stack size
{
asynStatus status = asynSuccess;
// Handle to the asynUser of the IP port asyn driver
pasynOctetSyncIOipPort_ = nullptr;
// Initial values for the average timeout mechanism, can be overwritten
// later by a FFI function
comTimeoutWindow_ = 3600; // seconds
// Number of timeouts which may occur before an error is forwarded to the
// user
maxNumberTimeouts_ = 60;
// Queue holding the timeout event timestamps
timeoutEvents_ = {};
// Inform the user after 10 timeouts in a row (default value)
maxSubsequentTimeouts_ = 10;
maxSubsequentTimeoutsExceeded_ = false;
// The paramLib indices are populated with the calls to createParam
pSinqC_ = std::make_unique<sinqControllerImpl>(
(sinqControllerImpl){.outstandingForcedFastPolls = 0,
.pasynOctetSyncIOipPort = nullptr,
.msgPrintC = msgPrintControl(),
.comTimeoutWindow = 3600,
.maxNumberTimeouts = 60,
.timeoutEvents = {},
.maxSubsequentTimeouts = 10,
.maxSubsequentTimeoutsExceeded = false});
// Store the poll period information. The poller itself will be started
// later (after the IOC is running in epicsInithookFunction)
@ -81,9 +139,9 @@ sinqController::sinqController(const char *portName,
We try to connect to the port via the port name provided by the constructor.
If this fails, the function is terminated via exit.
*/
pasynOctetSyncIO->connect(ipPortConfigName, 0, &pasynOctetSyncIOipPort_,
NULL);
if (status != asynSuccess || pasynOctetSyncIOipPort_ == nullptr) {
pasynOctetSyncIO->connect(ipPortConfigName, 0,
&pSinqC_->pasynOctetSyncIOipPort, NULL);
if (status != asynSuccess || pSinqC_->pasynOctetSyncIOipPort == nullptr) {
errlogPrintf("Controller \"%s\" => %s, line %d:\nFATAL ERROR (cannot "
"connect to MCU controller).\n"
"Terminating IOC",
@ -96,8 +154,8 @@ sinqController::sinqController(const char *portName,
// MOTOR_MESSAGE_TEXT corresponds to the PV definition inside sinqMotor.db.
// This text is used to forward status messages to NICOS and in turn to the
// user.
status =
createParam("MOTOR_MESSAGE_TEXT", asynParamOctet, &motorMessageText_);
status = createParam("MOTOR_MESSAGE_TEXT", asynParamOctet,
&pSinqC_->motorMessageText);
if (status != asynSuccess) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
@ -107,7 +165,7 @@ sinqController::sinqController(const char *portName,
exit(-1);
}
status = createParam("MOTOR_ENABLE", asynParamInt32, &motorEnable_);
status = createParam("MOTOR_ENABLE", asynParamInt32, &pSinqC_->motorEnable);
if (status != asynSuccess) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
@ -117,7 +175,7 @@ sinqController::sinqController(const char *portName,
exit(-1);
}
status = createParam("MOTOR_RESET", asynParamInt32, &motorReset_);
status = createParam("MOTOR_RESET", asynParamInt32, &pSinqC_->motorReset);
if (status != asynSuccess) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
@ -127,7 +185,8 @@ sinqController::sinqController(const char *portName,
exit(-1);
}
status = createParam("MOTOR_ENABLE_RBV", asynParamInt32, &motorEnableRBV_);
status = createParam("MOTOR_ENABLE_RBV", asynParamInt32,
&pSinqC_->motorEnableRBV);
if (status != asynSuccess) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
@ -137,8 +196,8 @@ sinqController::sinqController(const char *portName,
exit(-1);
}
status =
createParam("MOTOR_CAN_DISABLE", asynParamInt32, &motorCanDisable_);
status = createParam("MOTOR_CAN_DISABLE", asynParamInt32,
&pSinqC_->motorCanDisable);
if (status != asynSuccess) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
@ -148,8 +207,8 @@ sinqController::sinqController(const char *portName,
exit(-1);
}
status =
createParam("MOTOR_CAN_SET_SPEED", asynParamInt32, &motorCanSetSpeed_);
status = createParam("MOTOR_CAN_SET_SPEED", asynParamInt32,
&pSinqC_->motorCanSetSpeed);
if (status != asynSuccess) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
@ -160,7 +219,18 @@ sinqController::sinqController(const char *portName,
}
status = createParam("MOTOR_LIMITS_OFFSET", asynParamFloat64,
&motorLimitsOffset_);
&pSinqC_->motorLimitsOffset);
if (status != asynSuccess) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
"parameter failed with %s).\nTerminating IOC",
portName, __PRETTY_FUNCTION__, __LINE__,
stringifyAsynStatus(status));
exit(-1);
}
status = createParam("MOTOR_CONNECTED", asynParamInt32,
&pSinqC_->motorConnected);
if (status != asynSuccess) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
@ -176,7 +246,7 @@ sinqController::sinqController(const char *portName,
the declaration of motorHighLimitFromDriver_.
*/
status = createParam("MOTOR_HIGH_LIMIT_FROM_DRIVER", asynParamFloat64,
&motorHighLimitFromDriver_);
&pSinqC_->motorHighLimitFromDriver);
if (status != asynSuccess) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
@ -187,7 +257,7 @@ sinqController::sinqController(const char *portName,
}
status = createParam("MOTOR_LOW_LIMIT_FROM_DRIVER", asynParamFloat64,
&motorLowLimitFromDriver_);
&pSinqC_->motorLowLimitFromDriver);
if (status != asynSuccess) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
@ -198,7 +268,7 @@ sinqController::sinqController(const char *portName,
}
status = createParam("MOTOR_ENABLE_MOV_WATCHDOG", asynParamInt32,
&motorEnableMovWatchdog_);
&pSinqC_->motorEnableMovWatchdog);
if (status != asynSuccess) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
@ -209,7 +279,7 @@ sinqController::sinqController(const char *portName,
}
status = createParam("MOTOR_VELO_FROM_DRIVER", asynParamFloat64,
&motorVeloFromDriver_);
&pSinqC_->motorVeloFromDriver);
if (status != asynSuccess) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
@ -220,7 +290,7 @@ sinqController::sinqController(const char *portName,
}
status = createParam("MOTOR_VBAS_FROM_DRIVER", asynParamFloat64,
&motorVbasFromDriver_);
&pSinqC_->motorVbasFromDriver);
if (status != asynSuccess) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
@ -231,7 +301,7 @@ sinqController::sinqController(const char *portName,
}
status = createParam("MOTOR_VMAX_FROM_DRIVER", asynParamFloat64,
&motorVmaxFromDriver_);
&pSinqC_->motorVmaxFromDriver);
if (status != asynSuccess) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
@ -242,7 +312,7 @@ sinqController::sinqController(const char *portName,
}
status = createParam("MOTOR_ACCL_FROM_DRIVER", asynParamFloat64,
&motorAcclFromDriver_);
&pSinqC_->motorAcclFromDriver);
if (status != asynSuccess) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
@ -252,7 +322,8 @@ sinqController::sinqController(const char *portName,
exit(-1);
}
status = createParam("ADAPTIVE_POLLING", asynParamInt32, &adaptivePolling_);
status = createParam("ADAPTIVE_POLLING", asynParamInt32,
&pSinqC_->adaptivePolling);
if (status != asynSuccess) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
@ -262,7 +333,7 @@ sinqController::sinqController(const char *portName,
exit(-1);
}
status = createParam("ENCODER_TYPE", asynParamOctet, &encoderType_);
status = createParam("ENCODER_TYPE", asynParamOctet, &pSinqC_->encoderType);
if (status != asynSuccess) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
@ -272,7 +343,8 @@ sinqController::sinqController(const char *portName,
exit(-1);
}
status = createParam("MOTOR_FORCE_STOP", asynParamInt32, &motorForceStop_);
status = createParam("MOTOR_FORCE_STOP", asynParamInt32,
&pSinqC_->motorForceStop);
if (status != asynSuccess) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"Controller \"%s\" => %s, line %d:\nFATAL ERROR (creating a "
@ -304,8 +376,24 @@ sinqController::~sinqController(void) {
free(this->pAxes_);
}
msgPrintControl &sinqController::getMsgPrintControl() {
return msgPrintControl_;
/*
Access one of the axes of the controller via the axis adress stored in asynUser.
If the axis does not exist or is not an sinqAxis, the function returns a
nullptr.
*/
sinqAxis *sinqController::getSinqAxis(asynUser *pasynUser) {
asynMotorAxis *asynAxis = sinqController::getAxis(pasynUser);
return dynamic_cast<sinqAxis *>(asynAxis);
}
/*
Access one of the axes of the controller via the axis index.
If the axis does not exist or is not an sinqAxis, the function returns a
nullptr.
*/
sinqAxis *sinqController::getSinqAxis(int axisNo) {
asynMotorAxis *asynAxis = sinqController::getAxis(axisNo);
return dynamic_cast<sinqAxis *>(asynAxis);
}
asynStatus sinqController::writeInt32(asynUser *pasynUser, epicsInt32 value) {
@ -313,9 +401,7 @@ asynStatus sinqController::writeInt32(asynUser *pasynUser, epicsInt32 value) {
// =====================================================================
asynMotorAxis *asynAxis = getAxis(pasynUser);
sinqAxis *axis = dynamic_cast<sinqAxis *>(asynAxis);
sinqAxis *axis = getSinqAxis(pasynUser);
if (axis == nullptr) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line %d:\nAxis is not an "
@ -325,11 +411,11 @@ asynStatus sinqController::writeInt32(asynUser *pasynUser, epicsInt32 value) {
}
// Handle custom PVs
if (function == motorEnable_) {
if (function == motorEnable()) {
return axis->enable(value != 0);
} else if (function == motorReset_) {
} else if (function == motorReset()) {
return axis->reset();
} else if (function == motorForceStop_) {
} else if (function == motorForceStop()) {
return axis->stop(0.0);
} else {
return asynMotorController::writeInt32(pasynUser, value);
@ -338,22 +424,21 @@ asynStatus sinqController::writeInt32(asynUser *pasynUser, epicsInt32 value) {
asynStatus sinqController::readInt32(asynUser *pasynUser, epicsInt32 *value) {
// Casting into a sinqAxis is necessary to get access to the field axisNo()
asynMotorAxis *asynAxis = getAxis(pasynUser);
sinqAxis *axis = dynamic_cast<sinqAxis *>(asynAxis);
sinqAxis *axis = getSinqAxis(pasynUser);
if (axis == nullptr) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line %d:\nAxis is not an "
"instance of sinqAxis.\n",
"instance of sinqAxis",
portName, axis->axisNo(), __PRETTY_FUNCTION__, __LINE__);
return asynError;
}
if (pasynUser->reason == motorEnableRBV_) {
return getIntegerParam(axis->axisNo(), motorEnableRBV_, value);
} else if (pasynUser->reason == motorCanDisable_) {
return getIntegerParam(axis->axisNo(), motorCanDisable_, value);
if (pasynUser->reason == motorEnableRBV()) {
getAxisParamChecked(axis, motorEnableRBV, value);
return asynSuccess;
} else if (pasynUser->reason == motorCanDisable()) {
getAxisParamChecked(axis, motorCanDisable, value);
return asynSuccess;
} else {
return asynMotorController::readInt32(pasynUser, value);
}
@ -364,26 +449,24 @@ asynStatus sinqController::couldNotParseResponse(const char *command,
int axisNo,
const char *functionName,
int line) {
asynStatus pl_status = asynSuccess;
asynPrint(pasynOctetSyncIOipPort_, ASYN_TRACE_ERROR,
asynPrint(pasynOctetSyncIOipPort(), ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line %d:\nCould not interpret "
"response \"%s\" for command \"%s\".\n",
portName, axisNo, functionName, line, response, command);
pl_status = setStringParam(
motorMessageText_,
"Could not interpret controller response. Please call the support");
if (pl_status != asynSuccess) {
return paramLibAccessFailed(pl_status, "motorMessageText_", axisNo,
__PRETTY_FUNCTION__, __LINE__);
sinqAxis *axis = getSinqAxis(axisNo);
if (axis == nullptr) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line %d:\nAxis is not an "
"instance of sinqAxis",
portName, axis->axisNo(), __PRETTY_FUNCTION__, __LINE__);
return asynError;
}
pl_status = setIntegerParam(motorStatusCommsError_, 1);
if (pl_status != asynSuccess) {
return paramLibAccessFailed(pl_status, "motorStatusCommsError_", axisNo,
__PRETTY_FUNCTION__, __LINE__);
}
setAxisParamChecked(
axis, motorMessageText,
"Could not interpret controller response. Please call the support");
setAxisParamChecked(axis, motorStatusCommsError, true);
return asynError;
}
@ -395,7 +478,7 @@ asynStatus sinqController::paramLibAccessFailed(asynStatus status,
int line) {
if (status != asynSuccess) {
asynPrint(pasynOctetSyncIOipPort_, ASYN_TRACE_ERROR,
asynPrint(pasynOctetSyncIOipPort(), ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line %d:\n Accessing the "
"parameter library failed for parameter %s with error %s.\n",
portName, axisNo, functionName, line, parameter,
@ -403,7 +486,7 @@ asynStatus sinqController::paramLibAccessFailed(asynStatus status,
// Log the error message and try to propagate it. If propagating fails,
// there is nothing we can do here anyway.
setStringParam(motorMessageText_,
setStringParam(motorMessageText(),
"Accessing paramLib failed. Please call the support.");
}
@ -417,40 +500,42 @@ asynStatus sinqController::checkComTimeoutWatchdog(int axisNo,
asynStatus paramLibStatus = asynSuccess;
// Add a new timeout event to the queue
timeoutEvents_.push_back(time(NULL));
pSinqC_->timeoutEvents.push_back(time(NULL));
// Remove every event which is older than the time window from the deque
while (1) {
if (timeoutEvents_.empty()) {
if (pSinqC_->timeoutEvents.empty()) {
break;
}
if (timeoutEvents_[0] + comTimeoutWindow_ <= time(NULL)) {
timeoutEvents_.pop_front();
if (pSinqC_->timeoutEvents[0] + pSinqC_->comTimeoutWindow <=
time(NULL)) {
pSinqC_->timeoutEvents.pop_front();
} else {
break;
}
}
// Check if the maximum allowed number of events has been exceeded
bool wantToPrint = timeoutEvents_.size() > maxNumberTimeouts_;
bool wantToPrint =
pSinqC_->timeoutEvents.size() > pSinqC_->maxNumberTimeouts;
if (msgPrintControl_.shouldBePrinted(portName, axisNo, __PRETTY_FUNCTION__,
__LINE__, wantToPrint,
pasynUserSelf)) {
if (pSinqC_->msgPrintC.shouldBePrinted(portName, axisNo,
__PRETTY_FUNCTION__, __LINE__,
wantToPrint, pasynUserSelf)) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line %d:\nMore than %ld "
"communication timeouts in %ld "
"seconds.%s\n",
portName, axisNo, __PRETTY_FUNCTION__, __LINE__,
maxNumberTimeouts_, comTimeoutWindow_,
msgPrintControl_.getSuffix());
pSinqC_->maxNumberTimeouts, pSinqC_->comTimeoutWindow,
pSinqC_->msgPrintC.getSuffix());
}
if (wantToPrint) {
snprintf(motorMessage, motorMessageSize,
"More than %ld communication timeouts in %ld seconds. Please "
"call the support.",
maxNumberTimeouts_, comTimeoutWindow_);
pSinqC_->maxNumberTimeouts, pSinqC_->comTimeoutWindow);
paramLibStatus = setIntegerParam(motorStatusCommsError_, 1);
if (paramLibStatus != asynSuccess) {
@ -467,17 +552,12 @@ asynStatus sinqController::checkComTimeoutWatchdog(int axisNo,
asynStatus sinqController::checkComTimeoutWatchdog(sinqAxis *axis) {
char motorMessage[200] = {0};
char errorMessage[MAXBUF_] = {0};
asynStatus status =
checkComTimeoutWatchdog(axis->axisNo(), motorMessage, 200);
checkComTimeoutWatchdog(axis->axisNo(), errorMessage, MAXBUF_);
if (status == asynError) {
status = axis->setStringParam(motorMessageText_, motorMessage);
if (status != asynSuccess) {
return paramLibAccessFailed(status, "motorMessageText_",
axis->axisNo(), __PRETTY_FUNCTION__,
__LINE__);
}
setAxisParamChecked(axis, motorMessageText, errorMessage);
}
return status;
}
@ -487,18 +567,18 @@ asynStatus sinqController::checkMaxSubsequentTimeouts(int timeoutNo, int axisNo,
size_t motorMessageSize) {
asynStatus paramLibStatus = asynSuccess;
if (timeoutNo >= maxSubsequentTimeouts_) {
if (!maxSubsequentTimeoutsExceeded_) {
if (timeoutNo >= pSinqC_->maxSubsequentTimeouts) {
if (!pSinqC_->maxSubsequentTimeoutsExceeded) {
snprintf(motorMessage, motorMessageSize,
"Communication timeout between IOC and motor controller. "
"Trying to reconnect ...");
asynPrint(
this->pasynUserSelf, ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line %d:\nMore than %d "
"subsequent communication "
"timeouts\n",
"subsequent communication timeouts. Check whether the "
"controller is still running and connected to the network.\n",
this->portName, axisNo, __PRETTY_FUNCTION__, __LINE__,
maxSubsequentTimeouts_);
pSinqC_->maxSubsequentTimeouts);
paramLibStatus = setIntegerParam(motorStatusCommsError_, 1);
if (paramLibStatus != asynSuccess) {
@ -506,12 +586,12 @@ asynStatus sinqController::checkMaxSubsequentTimeouts(int timeoutNo, int axisNo,
"motorStatusCommsError_", axisNo,
__PRETTY_FUNCTION__, __LINE__);
}
maxSubsequentTimeoutsExceeded_ = true;
pSinqC_->maxSubsequentTimeoutsExceeded = true;
}
return asynError;
} else {
maxSubsequentTimeoutsExceeded_ = false;
pSinqC_->maxSubsequentTimeoutsExceeded = false;
motorMessage[0] = '\0';
return asynSuccess;
}
@ -520,21 +600,108 @@ asynStatus sinqController::checkMaxSubsequentTimeouts(int timeoutNo, int axisNo,
asynStatus sinqController::checkMaxSubsequentTimeouts(int timeoutNo,
sinqAxis *axis) {
char motorMessage[200] = {0};
char motorMessage[MAXBUF_] = {0};
asynStatus status = checkMaxSubsequentTimeouts(axis->axisNo(), timeoutNo,
motorMessage, 200);
asynStatus status = checkMaxSubsequentTimeouts(timeoutNo, axis->axisNo(),
motorMessage, MAXBUF_);
if (status == asynError) {
status = axis->setStringParam(motorMessageText_, motorMessage);
if (status != asynSuccess) {
return paramLibAccessFailed(status, "motorMessageText_",
axis->axisNo(), __PRETTY_FUNCTION__,
__LINE__);
}
setAxisParamChecked(axis, motorMessageText, motorMessage);
}
return status;
}
asynStatus sinqController::poll() {
// Decrement the number of outstanding forced fast polls, if they are not
// zero
if (pSinqC_->outstandingForcedFastPolls > 0) {
pSinqC_->outstandingForcedFastPolls--;
}
return asynMotorController::poll();
}
asynStatus sinqController::wakeupPoller() {
// + 1 since outstandingForcedFastPolls_ is reduced once at the start of
// a poll cycle
pSinqC_->outstandingForcedFastPolls = forcedFastPolls_ + 1;
return asynMotorController::wakeupPoller();
}
asynStatus sinqController::setMaxSubsequentTimeouts(int maxSubsequentTimeouts) {
pSinqC_->maxSubsequentTimeouts = maxSubsequentTimeouts;
return asynSuccess;
}
bool sinqController::maxSubsequentTimeoutsExceeded() {
return pSinqC_->maxSubsequentTimeoutsExceeded;
}
/**
* @brief Get a reference to the map used to control the maximum number of
* message repetitions. See the documentation of `printRepetitionWatchdog`
* in msgPrintControl.h for details.
*/
msgPrintControl &sinqController::getMsgPrintControl() {
return pSinqC_->msgPrintC;
}
/**
* @brief Read the number of outstanding forced fast polls currently
* specified
*
*/
int sinqController::outstandingForcedFastPolls() {
return pSinqC_->outstandingForcedFastPolls;
}
/**
* @brief Return a pointer to the low-level octet (string) IP Port
*
* @return asynUser*
*/
asynUser *sinqController::pasynOctetSyncIOipPort() {
return pSinqC_->pasynOctetSyncIOipPort;
}
asynStatus sinqController::setThresholdComTimeout(time_t comTimeoutWindow,
size_t maxNumberTimeouts) {
pSinqC_->comTimeoutWindow = comTimeoutWindow;
pSinqC_->maxNumberTimeouts = maxNumberTimeouts;
return asynSuccess;
}
int sinqController::motorMessageText() { return pSinqC_->motorMessageText; }
int sinqController::motorReset() { return pSinqC_->motorReset; }
int sinqController::motorEnable() { return pSinqC_->motorEnable; }
int sinqController::motorEnableRBV() { return pSinqC_->motorEnableRBV; }
int sinqController::motorCanDisable() { return pSinqC_->motorCanDisable; }
int sinqController::motorEnableMovWatchdog() {
return pSinqC_->motorEnableMovWatchdog;
}
int sinqController::motorCanSetSpeed() { return pSinqC_->motorCanSetSpeed; }
int sinqController::motorLimitsOffset() { return pSinqC_->motorLimitsOffset; }
int sinqController::motorForceStop() { return pSinqC_->motorForceStop; }
int sinqController::motorConnected() { return pSinqC_->motorConnected; }
int sinqController::motorVeloFromDriver() {
return pSinqC_->motorVeloFromDriver;
}
int sinqController::motorVbasFromDriver() {
return pSinqC_->motorVbasFromDriver;
}
int sinqController::motorVmaxFromDriver() {
return pSinqC_->motorVmaxFromDriver;
}
int sinqController::motorAcclFromDriver() {
return pSinqC_->motorAcclFromDriver;
}
int sinqController::motorHighLimitFromDriver() {
return pSinqC_->motorHighLimitFromDriver;
}
int sinqController::motorLowLimitFromDriver() {
return pSinqC_->motorLowLimitFromDriver;
}
int sinqController::adaptivePolling() { return pSinqC_->adaptivePolling; }
int sinqController::encoderType() { return pSinqC_->encoderType; }
// Static pointers (valid for the entire lifetime of the IOC). The number behind
// the strings gives the integer number of each variant (see also method
// stringifyAsynStatus)
@ -608,6 +775,8 @@ extern "C" {
* @brief Set the threshold for the communication timeout frequency (FFI
* implementation)
*
* @param portName Name of the low-level asyn port the controller is
* using.
* @param comTimeoutWindow Size of the time window used to calculate
* the moving average of timeout events in seconds. Set this value to 0 to
* deactivate the watchdog.
@ -651,11 +820,10 @@ static void setThresholdComTimeoutCallFunc(const iocshArgBuf *args) {
/**
* @brief Set the maximum number of subsequent timeouts (FFI implementation)
*
* @param comTimeoutWindow Size of the time window used to calculate
* the moving average of timeout events. Set this value to 0 to deactivate
* the watchdog.
* @param maxNumberTimeouts Maximum number of timeouts which may occur
* within the time window before the watchdog is triggered.
* @param portName Name of the low-level asyn port the controller is
* using.
* @param maxSubsequentTimeouts Maximum number of timeouts which may occur
* subsequently before an error is reported.
* @return asynStatus
*/
asynStatus setMaxSubsequentTimeouts(const char *portName,
@ -709,12 +877,73 @@ static void setMaxSubsequentTimeoutsCallFunc(const iocshArgBuf *args) {
// =============================================================================
/**
* @brief Set the number of forced fast polls which happen after a call to
* `wakePoller`.
*
* @param portName Name of the low-level asyn port the controller is
* using.
* @param forcedFastPolls Number of fast polls done after calling
* `wakePoller`.
* @return asynStatus
*/
asynStatus setForcedFastPolls(const char *portName, int forcedFastPolls) {
void *ptr = findAsynPortDriver(portName);
if (ptr == nullptr) {
/*
We can't use asynPrint here since this macro would require us
to get a pasynOctetSyncIOipPort_ from a pointer to an asynPortDriver.
However, the given pointer is a nullptr and therefore doesn't
have a pasynOctetSyncIOipPort_! printf is an EPICS alternative which
works w/o that, but doesn't offer the comfort provided
by the asynTrace-facility
*/
errlogPrintf("Controller \"%s\" => %s, line %d:\nPort %s not found.",
portName, __PRETTY_FUNCTION__, __LINE__, portName);
return asynError;
}
// Unsafe cast of the pointer to an asynPortDriver
asynPortDriver *apd = (asynPortDriver *)(ptr);
// Safe downcast
sinqController *pC = dynamic_cast<sinqController *>(apd);
if (pC == nullptr) {
errlogPrintf(
"Controller \"%s\" => %s, line %d:\ncontroller on port %s is not a "
"turboPmacController.",
portName, __PRETTY_FUNCTION__, __LINE__, portName);
return asynError;
}
// Set the new value
pC->setForcedFastPolls(forcedFastPolls);
return asynSuccess;
}
static const iocshArg SetForcedFastPollsArg0 = {"Controller name (e.g. mcu1)",
iocshArgString};
static const iocshArg SetForcedFastPollsArg1 = {
"Number of fast polls after \"waking\" the poller (e.g. after issueing a "
"move command).",
iocshArgInt};
static const iocshArg *const SetForcedFastPollsArgs[] = {
&SetForcedFastPollsArg0, &SetForcedFastPollsArg1};
static const iocshFuncDef setForcedFastPollsDef = {"setForcedFastPolls", 2,
SetForcedFastPollsArgs};
static void setForcedFastPollsCallFunc(const iocshArgBuf *args) {
setForcedFastPolls(args[0].sval, args[1].ival);
}
// =============================================================================
// This function is made known to EPICS in sinqMotor.dbd and is called by EPICS
// in order to register all functions in the IOC shell
static void sinqControllerRegister(void) {
iocshRegister(&setThresholdComTimeoutDef, setThresholdComTimeoutCallFunc);
iocshRegister(&setMaxSubsequentTimeoutsDef,
setMaxSubsequentTimeoutsCallFunc);
iocshRegister(&setForcedFastPollsDef, setForcedFastPollsCallFunc);
}
epicsExportRegistrar(sinqControllerRegister);

View File

@ -1,3 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
This class extends asynMotorController by some features used in SINQ. See the
README.md for details.
@ -9,9 +11,8 @@ Stefan Mathis, November 2024
#define sinqController_H
#include "asynMotorController.h"
#include "msgPrintControl.h"
#include <deque>
#include <initHooks.h>
#include <unordered_map>
#include <memory>
#define motorMessageIsFromDriverString "MOTOR_MESSAGE_DRIVER"
#define motorMessageTextString "MOTOR_MESSAGE_TEXT"
@ -19,6 +20,8 @@ Stefan Mathis, November 2024
#define AbsoluteEncoder "absolute"
#define NoEncoder "none"
struct sinqControllerImpl;
class epicsShareClass sinqController : public asynMotorController {
public:
/**
@ -173,11 +176,7 @@ class epicsShareClass sinqController : public asynMotorController {
* @return asynStatus
*/
virtual asynStatus setThresholdComTimeout(time_t comTimeoutWindow,
size_t maxNumberTimeouts) {
comTimeoutWindow_ = comTimeoutWindow;
maxNumberTimeouts_ = maxNumberTimeouts;
return asynSuccess;
}
size_t maxNumberTimeouts);
/**
* @brief Inform the user, if the number of timeouts exceeds the threshold
@ -209,10 +208,16 @@ class epicsShareClass sinqController : public asynMotorController {
* @param maxSubsequentTimeouts
* @return asynStatus
*/
asynStatus setMaxSubsequentTimeouts(int maxSubsequentTimeouts) {
maxSubsequentTimeouts_ = maxSubsequentTimeouts;
return asynSuccess;
}
asynStatus setMaxSubsequentTimeouts(int maxSubsequentTimeouts);
/**
* @brief If true, the maximum number of subsequent communication timeouts
* set in `setMaxSubsequentTimeouts` has been exceeded
*
* @return true
* @return false
*/
bool maxSubsequentTimeoutsExceeded();
/**
* @brief Get a reference to the map used to control the maximum number of
@ -221,6 +226,22 @@ class epicsShareClass sinqController : public asynMotorController {
*/
msgPrintControl &getMsgPrintControl();
/**
* @brief Get the axis object
*
* @param pasynUser Specify the axis via the asynUser
* @return sinqAxis* If no axis could be found, this is a nullptr
*/
sinqAxis *getSinqAxis(asynUser *pasynUser);
/**
* @brief Get the axis object
*
* @param axisNo Specify the axis via its index
* @return sinqAxis* If no axis could be found, this is a nullptr
*/
sinqAxis *getSinqAxis(int axisNo);
// =========================================================================
// Public getters for protected members
@ -275,24 +296,26 @@ class epicsShareClass sinqController : public asynMotorController {
int motorRecDirection() { return motorRecDirection_; }
int motorRecOffset() { return motorRecOffset_; }
// Accessors for additional PVs defined in sinqController
int motorMessageText() { return motorMessageText_; }
int motorReset() { return motorReset_; }
int motorEnable() { return motorEnable_; }
int motorEnableRBV() { return motorEnableRBV_; }
int motorCanDisable() { return motorCanDisable_; }
int motorEnableMovWatchdog() { return motorEnableMovWatchdog_; }
int motorCanSetSpeed() { return motorCanSetSpeed_; }
int motorLimitsOffset() { return motorLimitsOffset_; }
int motorForceStop() { return motorForceStop_; }
int motorVeloFromDriver() { return motorVeloFromDriver_; }
int motorVbasFromDriver() { return motorVbasFromDriver_; }
int motorVmaxFromDriver() { return motorVmaxFromDriver_; }
int motorAcclFromDriver() { return motorAcclFromDriver_; }
int motorHighLimitFromDriver() { return motorHighLimitFromDriver_; }
int motorLowLimitFromDriver() { return motorLowLimitFromDriver_; }
int adaptivePolling() { return adaptivePolling_; }
int encoderType() { return encoderType_; }
// Accessors for additional PVs defined in sinqController (which are hidden
// in pSinqC_)
int motorMessageText();
int motorReset();
int motorEnable();
int motorEnableRBV();
int motorCanDisable();
int motorEnableMovWatchdog();
int motorCanSetSpeed();
int motorLimitsOffset();
int motorForceStop();
int motorConnected();
int motorVeloFromDriver();
int motorVbasFromDriver();
int motorVmaxFromDriver();
int motorAcclFromDriver();
int motorHighLimitFromDriver();
int motorLowLimitFromDriver();
int adaptivePolling();
int encoderType();
// Additional members
int numAxes() { return numAxes_; }
@ -311,61 +334,70 @@ class epicsShareClass sinqController : public asynMotorController {
*
* @return asynUser*
*/
asynUser *pasynOctetSyncIOipPort() { return pasynOctetSyncIOipPort_; }
asynUser *pasynOctetSyncIOipPort();
/**
* @brief Overloaded version of `asynController::poll` which decreases
* `outstandingForcedFastPolls` and then defers to the base method
*/
asynStatus poll();
/**
* @brief Overloaded version of `asynController::wakeupPoller` which
* initializes the `outstandingForcedFastPolls` variable and then defers to
* the base class method.
*
* The `wakePoller` function of the base class `asynController` sends a
* signal to the poller thread which forces the latter to perform a number
* of fast / busy polls with the busy poll period regardless of whether the
* motor is moving or not. The number of polls is specified by
* "forcedFastPolls()" and can be set with `setForcedFastPolls()`.
*
* @return asynStatus
*/
asynStatus wakeupPoller();
/**
* @brief Set the number of forced fast polls which should be performed when
* `wakeupPoller` is called.
*
* @param forcedFastPolls
*/
void setForcedFastPolls(int forcedFastPolls) {
forcedFastPolls_ = forcedFastPolls;
}
/**
* @brief Read the number of forced fast polls currently specified
*
*/
int forcedFastPolls() { return forcedFastPolls_; }
/**
* @brief Read the number of outstanding forced fast polls currently
* specified
*
*/
int outstandingForcedFastPolls();
/**
* @brief Return the maximum error message buffer size
*
* This is an empirical value which must be large enough to avoid overflows
* for all commands to the device / responses from it.
*
* @return uint32_t
*/
uint32_t msgSize() { return MAXBUF_; }
// Maximum message size
static const uint32_t MAXBUF_ = 200;
// =========================================================================
protected:
// Pointer to the port user which is specified by the char array
// `ipPortConfigName` in the constructor
asynUser *pasynOctetSyncIOipPort_;
double movingPollPeriod_;
double idlePollPeriod_;
msgPrintControl msgPrintControl_;
// Internal variables used in the communication timeout frequency watchdog
time_t comTimeoutWindow_; // Size of the time window
size_t maxNumberTimeouts_; // Maximum acceptable number of events within the
// time window
std::deque<time_t>
timeoutEvents_; // Deque holding the timestamps of the individual events
// Communicate a timeout to the user after it has happened this many times
// in a row
int maxSubsequentTimeouts_;
bool maxSubsequentTimeoutsExceeded_;
#define FIRST_SINQMOTOR_PARAM motorMessageText_
int motorMessageText_;
int motorReset_;
int motorEnable_;
int motorEnableRBV_;
int motorCanDisable_;
int motorEnableMovWatchdog_;
int motorCanSetSpeed_;
int motorLimitsOffset_;
int motorForceStop_;
/*
These parameters are here to write values from the hardware to the EPICS
motor record. Using motorHighLimit_ / motorLowLimit_ does not work:
https://epics.anl.gov/tech-talk/2023/msg00576.php. Therefore, some
additional records are introduced which read from these parameters and write
into the motor record.
*/
int motorVeloFromDriver_;
int motorVbasFromDriver_;
int motorVmaxFromDriver_;
int motorAcclFromDriver_;
int motorHighLimitFromDriver_;
int motorLowLimitFromDriver_;
int adaptivePolling_;
int encoderType_;
#define LAST_SINQMOTOR_PARAM encoderType_
private:
std::unique_ptr<sinqControllerImpl> pSinqC_;
static void epicsInithookFunction(initHookState iState);
};
#define NUM_SINQMOTOR_DRIVER_PARAMS \
(&LAST_SINQMOTOR_PARAM - &FIRST_SINQMOTOR_PARAM + 1)
#endif

View File

@ -1,3 +1,5 @@
# SPDX-License-Identifier: GPL-3.0-only
#---------------------------------------------
# SINQ specific DB definitions
#---------------------------------------------