初始化提交
This commit is contained in:
23
arduino-cli/libraries/MPU6050/CHANGELOG
Normal file
23
arduino-cli/libraries/MPU6050/CHANGELOG
Normal file
@@ -0,0 +1,23 @@
|
||||
MPU6050 Arduino Library 1.0.3 / 03.03.2015
|
||||
======================================================================
|
||||
|
||||
* Added setDLPFMode(mpu6050_dlpf_t dlpf) function
|
||||
MPU6050_DLPF_0...6 (see datatsheet)
|
||||
|
||||
MPU6050 Arduino Library 1.0.2 / 10.02.2015
|
||||
======================================================================
|
||||
|
||||
* Adjustable i2c address
|
||||
mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G) - default 0x68
|
||||
mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G, 0x69) - use 0x69
|
||||
|
||||
MPU6050 Arduino Library 1.0.1 / 26.10.2014
|
||||
======================================================================
|
||||
|
||||
* Removing examples for Kalman Filter. Moved to KalmanFilter Git repo
|
||||
* Removing examples for HMC5883L. Moved to HMC5833L Git repo
|
||||
|
||||
MPU6050 Arduino Library 1.0.0 / 20.10.2014
|
||||
======================================================================
|
||||
|
||||
* First release
|
||||
674
arduino-cli/libraries/MPU6050/LICENSE
Normal file
674
arduino-cli/libraries/MPU6050/LICENSE
Normal 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>.
|
||||
749
arduino-cli/libraries/MPU6050/MPU6050.cpp
Normal file
749
arduino-cli/libraries/MPU6050/MPU6050.cpp
Normal file
@@ -0,0 +1,749 @@
|
||||
/*
|
||||
MPU6050.cpp - Class file for the MPU6050 Triple Axis Gyroscope & Accelerometer Arduino Library.
|
||||
|
||||
Version: 1.0.3
|
||||
(c) 2014-2015 Korneliusz Jarzebski
|
||||
www.jarzebski.pl
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the version 3 GNU General Public License as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#if ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
#include <Wire.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <MPU6050.h>
|
||||
|
||||
bool MPU6050::begin(mpu6050_dps_t scale, mpu6050_range_t range, int mpua)
|
||||
{
|
||||
// Set Address
|
||||
mpuAddress = mpua;
|
||||
|
||||
Wire.begin();
|
||||
|
||||
// Reset calibrate values
|
||||
dg.XAxis = 0;
|
||||
dg.YAxis = 0;
|
||||
dg.ZAxis = 0;
|
||||
useCalibrate = false;
|
||||
|
||||
// Reset threshold values
|
||||
tg.XAxis = 0;
|
||||
tg.YAxis = 0;
|
||||
tg.ZAxis = 0;
|
||||
actualThreshold = 0;
|
||||
|
||||
// Check MPU6050 Who Am I Register
|
||||
if (fastRegister8(MPU6050_REG_WHO_AM_I) != 0x68)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set Clock Source
|
||||
setClockSource(MPU6050_CLOCK_PLL_XGYRO);
|
||||
|
||||
// Set Scale & Range
|
||||
setScale(scale);
|
||||
setRange(range);
|
||||
|
||||
// Disable Sleep Mode
|
||||
setSleepEnabled(false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void MPU6050::setScale(mpu6050_dps_t scale)
|
||||
{
|
||||
uint8_t value;
|
||||
|
||||
switch (scale)
|
||||
{
|
||||
case MPU6050_SCALE_250DPS:
|
||||
dpsPerDigit = .007633f;
|
||||
break;
|
||||
case MPU6050_SCALE_500DPS:
|
||||
dpsPerDigit = .015267f;
|
||||
break;
|
||||
case MPU6050_SCALE_1000DPS:
|
||||
dpsPerDigit = .030487f;
|
||||
break;
|
||||
case MPU6050_SCALE_2000DPS:
|
||||
dpsPerDigit = .060975f;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
value = readRegister8(MPU6050_REG_GYRO_CONFIG);
|
||||
value &= 0b11100111;
|
||||
value |= (scale << 3);
|
||||
writeRegister8(MPU6050_REG_GYRO_CONFIG, value);
|
||||
}
|
||||
|
||||
mpu6050_dps_t MPU6050::getScale(void)
|
||||
{
|
||||
uint8_t value;
|
||||
value = readRegister8(MPU6050_REG_GYRO_CONFIG);
|
||||
value &= 0b00011000;
|
||||
value >>= 3;
|
||||
return (mpu6050_dps_t)value;
|
||||
}
|
||||
|
||||
void MPU6050::setRange(mpu6050_range_t range)
|
||||
{
|
||||
uint8_t value;
|
||||
|
||||
switch (range)
|
||||
{
|
||||
case MPU6050_RANGE_2G:
|
||||
rangePerDigit = .000061f;
|
||||
break;
|
||||
case MPU6050_RANGE_4G:
|
||||
rangePerDigit = .000122f;
|
||||
break;
|
||||
case MPU6050_RANGE_8G:
|
||||
rangePerDigit = .000244f;
|
||||
break;
|
||||
case MPU6050_RANGE_16G:
|
||||
rangePerDigit = .0004882f;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
value = readRegister8(MPU6050_REG_ACCEL_CONFIG);
|
||||
value &= 0b11100111;
|
||||
value |= (range << 3);
|
||||
writeRegister8(MPU6050_REG_ACCEL_CONFIG, value);
|
||||
}
|
||||
|
||||
mpu6050_range_t MPU6050::getRange(void)
|
||||
{
|
||||
uint8_t value;
|
||||
value = readRegister8(MPU6050_REG_ACCEL_CONFIG);
|
||||
value &= 0b00011000;
|
||||
value >>= 3;
|
||||
return (mpu6050_range_t)value;
|
||||
}
|
||||
|
||||
void MPU6050::setDHPFMode(mpu6050_dhpf_t dhpf)
|
||||
{
|
||||
uint8_t value;
|
||||
value = readRegister8(MPU6050_REG_ACCEL_CONFIG);
|
||||
value &= 0b11111000;
|
||||
value |= dhpf;
|
||||
writeRegister8(MPU6050_REG_ACCEL_CONFIG, value);
|
||||
}
|
||||
|
||||
void MPU6050::setDLPFMode(mpu6050_dlpf_t dlpf)
|
||||
{
|
||||
uint8_t value;
|
||||
value = readRegister8(MPU6050_REG_CONFIG);
|
||||
value &= 0b11111000;
|
||||
value |= dlpf;
|
||||
writeRegister8(MPU6050_REG_CONFIG, value);
|
||||
}
|
||||
|
||||
void MPU6050::setClockSource(mpu6050_clockSource_t source)
|
||||
{
|
||||
uint8_t value;
|
||||
value = readRegister8(MPU6050_REG_PWR_MGMT_1);
|
||||
value &= 0b11111000;
|
||||
value |= source;
|
||||
writeRegister8(MPU6050_REG_PWR_MGMT_1, value);
|
||||
}
|
||||
|
||||
mpu6050_clockSource_t MPU6050::getClockSource(void)
|
||||
{
|
||||
uint8_t value;
|
||||
value = readRegister8(MPU6050_REG_PWR_MGMT_1);
|
||||
value &= 0b00000111;
|
||||
return (mpu6050_clockSource_t)value;
|
||||
}
|
||||
|
||||
bool MPU6050::getSleepEnabled(void)
|
||||
{
|
||||
return readRegisterBit(MPU6050_REG_PWR_MGMT_1, 6);
|
||||
}
|
||||
|
||||
void MPU6050::setSleepEnabled(bool state)
|
||||
{
|
||||
writeRegisterBit(MPU6050_REG_PWR_MGMT_1, 6, state);
|
||||
}
|
||||
|
||||
bool MPU6050::getIntZeroMotionEnabled(void)
|
||||
{
|
||||
return readRegisterBit(MPU6050_REG_INT_ENABLE, 5);
|
||||
}
|
||||
|
||||
void MPU6050::setIntZeroMotionEnabled(bool state)
|
||||
{
|
||||
writeRegisterBit(MPU6050_REG_INT_ENABLE, 5, state);
|
||||
}
|
||||
|
||||
bool MPU6050::getIntMotionEnabled(void)
|
||||
{
|
||||
return readRegisterBit(MPU6050_REG_INT_ENABLE, 6);
|
||||
}
|
||||
|
||||
void MPU6050::setIntMotionEnabled(bool state)
|
||||
{
|
||||
writeRegisterBit(MPU6050_REG_INT_ENABLE, 6, state);
|
||||
}
|
||||
|
||||
bool MPU6050::getIntFreeFallEnabled(void)
|
||||
{
|
||||
return readRegisterBit(MPU6050_REG_INT_ENABLE, 7);
|
||||
}
|
||||
|
||||
void MPU6050::setIntFreeFallEnabled(bool state)
|
||||
{
|
||||
writeRegisterBit(MPU6050_REG_INT_ENABLE, 7, state);
|
||||
}
|
||||
|
||||
uint8_t MPU6050::getMotionDetectionThreshold(void)
|
||||
{
|
||||
return readRegister8(MPU6050_REG_MOT_THRESHOLD);
|
||||
}
|
||||
|
||||
void MPU6050::setMotionDetectionThreshold(uint8_t threshold)
|
||||
{
|
||||
writeRegister8(MPU6050_REG_MOT_THRESHOLD, threshold);
|
||||
}
|
||||
|
||||
uint8_t MPU6050::getMotionDetectionDuration(void)
|
||||
{
|
||||
return readRegister8(MPU6050_REG_MOT_DURATION);
|
||||
}
|
||||
|
||||
void MPU6050::setMotionDetectionDuration(uint8_t duration)
|
||||
{
|
||||
writeRegister8(MPU6050_REG_MOT_DURATION, duration);
|
||||
}
|
||||
|
||||
uint8_t MPU6050::getZeroMotionDetectionThreshold(void)
|
||||
{
|
||||
return readRegister8(MPU6050_REG_ZMOT_THRESHOLD);
|
||||
}
|
||||
|
||||
void MPU6050::setZeroMotionDetectionThreshold(uint8_t threshold)
|
||||
{
|
||||
writeRegister8(MPU6050_REG_ZMOT_THRESHOLD, threshold);
|
||||
}
|
||||
|
||||
uint8_t MPU6050::getZeroMotionDetectionDuration(void)
|
||||
{
|
||||
return readRegister8(MPU6050_REG_ZMOT_DURATION);
|
||||
}
|
||||
|
||||
void MPU6050::setZeroMotionDetectionDuration(uint8_t duration)
|
||||
{
|
||||
writeRegister8(MPU6050_REG_ZMOT_DURATION, duration);
|
||||
}
|
||||
|
||||
uint8_t MPU6050::getFreeFallDetectionThreshold(void)
|
||||
{
|
||||
return readRegister8(MPU6050_REG_FF_THRESHOLD);
|
||||
}
|
||||
|
||||
void MPU6050::setFreeFallDetectionThreshold(uint8_t threshold)
|
||||
{
|
||||
writeRegister8(MPU6050_REG_FF_THRESHOLD, threshold);
|
||||
}
|
||||
|
||||
uint8_t MPU6050::getFreeFallDetectionDuration(void)
|
||||
{
|
||||
return readRegister8(MPU6050_REG_FF_DURATION);
|
||||
}
|
||||
|
||||
void MPU6050::setFreeFallDetectionDuration(uint8_t duration)
|
||||
{
|
||||
writeRegister8(MPU6050_REG_FF_DURATION, duration);
|
||||
}
|
||||
|
||||
bool MPU6050::getI2CMasterModeEnabled(void)
|
||||
{
|
||||
return readRegisterBit(MPU6050_REG_USER_CTRL, 5);
|
||||
}
|
||||
|
||||
void MPU6050::setI2CMasterModeEnabled(bool state)
|
||||
{
|
||||
writeRegisterBit(MPU6050_REG_USER_CTRL, 5, state);
|
||||
}
|
||||
|
||||
void MPU6050::setI2CBypassEnabled(bool state)
|
||||
{
|
||||
return writeRegisterBit(MPU6050_REG_INT_PIN_CFG, 1, state);
|
||||
}
|
||||
|
||||
bool MPU6050::getI2CBypassEnabled(void)
|
||||
{
|
||||
return readRegisterBit(MPU6050_REG_INT_PIN_CFG, 1);
|
||||
}
|
||||
|
||||
void MPU6050::setAccelPowerOnDelay(mpu6050_onDelay_t delay)
|
||||
{
|
||||
uint8_t value;
|
||||
value = readRegister8(MPU6050_REG_MOT_DETECT_CTRL);
|
||||
value &= 0b11001111;
|
||||
value |= (delay << 4);
|
||||
writeRegister8(MPU6050_REG_MOT_DETECT_CTRL, value);
|
||||
}
|
||||
|
||||
mpu6050_onDelay_t MPU6050::getAccelPowerOnDelay(void)
|
||||
{
|
||||
uint8_t value;
|
||||
value = readRegister8(MPU6050_REG_MOT_DETECT_CTRL);
|
||||
value &= 0b00110000;
|
||||
return (mpu6050_onDelay_t)(value >> 4);
|
||||
}
|
||||
|
||||
uint8_t MPU6050::getIntStatus(void)
|
||||
{
|
||||
return readRegister8(MPU6050_REG_INT_STATUS);
|
||||
}
|
||||
|
||||
Activites MPU6050::readActivites(void)
|
||||
{
|
||||
uint8_t data = readRegister8(MPU6050_REG_INT_STATUS);
|
||||
|
||||
a.isOverflow = ((data >> 4) & 1);
|
||||
a.isFreeFall = ((data >> 7) & 1);
|
||||
a.isInactivity = ((data >> 5) & 1);
|
||||
a.isActivity = ((data >> 6) & 1);
|
||||
a.isDataReady = ((data >> 0) & 1);
|
||||
|
||||
data = readRegister8(MPU6050_REG_MOT_DETECT_STATUS);
|
||||
|
||||
a.isNegActivityOnX = ((data >> 7) & 1);
|
||||
a.isPosActivityOnX = ((data >> 6) & 1);
|
||||
|
||||
a.isNegActivityOnY = ((data >> 5) & 1);
|
||||
a.isPosActivityOnY = ((data >> 4) & 1);
|
||||
|
||||
a.isNegActivityOnZ = ((data >> 3) & 1);
|
||||
a.isPosActivityOnZ = ((data >> 2) & 1);
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
Vector MPU6050::readRawAccel(void)
|
||||
{
|
||||
Wire.beginTransmission(mpuAddress);
|
||||
#if ARDUINO >= 100
|
||||
Wire.write(MPU6050_REG_ACCEL_XOUT_H);
|
||||
#else
|
||||
Wire.send(MPU6050_REG_ACCEL_XOUT_H);
|
||||
#endif
|
||||
Wire.endTransmission();
|
||||
|
||||
Wire.beginTransmission(mpuAddress);
|
||||
Wire.requestFrom(mpuAddress, 6);
|
||||
|
||||
while (Wire.available() < 6);
|
||||
|
||||
#if ARDUINO >= 100
|
||||
uint8_t xha = Wire.read();
|
||||
uint8_t xla = Wire.read();
|
||||
uint8_t yha = Wire.read();
|
||||
uint8_t yla = Wire.read();
|
||||
uint8_t zha = Wire.read();
|
||||
uint8_t zla = Wire.read();
|
||||
#else
|
||||
uint8_t xha = Wire.receive();
|
||||
uint8_t xla = Wire.receive();
|
||||
uint8_t yha = Wire.receive();
|
||||
uint8_t yla = Wire.receive();
|
||||
uint8_t zha = Wire.receive();
|
||||
uint8_t zla = Wire.receive();
|
||||
#endif
|
||||
|
||||
ra.XAxis = xha << 8 | xla;
|
||||
ra.YAxis = yha << 8 | yla;
|
||||
ra.ZAxis = zha << 8 | zla;
|
||||
|
||||
return ra;
|
||||
}
|
||||
|
||||
Vector MPU6050::readNormalizeAccel(void)
|
||||
{
|
||||
readRawAccel();
|
||||
|
||||
na.XAxis = ra.XAxis * rangePerDigit * 9.80665f;
|
||||
na.YAxis = ra.YAxis * rangePerDigit * 9.80665f;
|
||||
na.ZAxis = ra.ZAxis * rangePerDigit * 9.80665f;
|
||||
|
||||
return na;
|
||||
}
|
||||
|
||||
Vector MPU6050::readScaledAccel(void)
|
||||
{
|
||||
readRawAccel();
|
||||
|
||||
na.XAxis = ra.XAxis * rangePerDigit;
|
||||
na.YAxis = ra.YAxis * rangePerDigit;
|
||||
na.ZAxis = ra.ZAxis * rangePerDigit;
|
||||
|
||||
return na;
|
||||
}
|
||||
|
||||
|
||||
Vector MPU6050::readRawGyro(void)
|
||||
{
|
||||
Wire.beginTransmission(mpuAddress);
|
||||
#if ARDUINO >= 100
|
||||
Wire.write(MPU6050_REG_GYRO_XOUT_H);
|
||||
#else
|
||||
Wire.send(MPU6050_REG_GYRO_XOUT_H);
|
||||
#endif
|
||||
Wire.endTransmission();
|
||||
|
||||
Wire.beginTransmission(mpuAddress);
|
||||
Wire.requestFrom(mpuAddress, 6);
|
||||
|
||||
while (Wire.available() < 6);
|
||||
|
||||
#if ARDUINO >= 100
|
||||
uint8_t xha = Wire.read();
|
||||
uint8_t xla = Wire.read();
|
||||
uint8_t yha = Wire.read();
|
||||
uint8_t yla = Wire.read();
|
||||
uint8_t zha = Wire.read();
|
||||
uint8_t zla = Wire.read();
|
||||
#else
|
||||
uint8_t xha = Wire.receive();
|
||||
uint8_t xla = Wire.receive();
|
||||
uint8_t yha = Wire.receive();
|
||||
uint8_t yla = Wire.receive();
|
||||
uint8_t zha = Wire.receive();
|
||||
uint8_t zla = Wire.receive();
|
||||
#endif
|
||||
|
||||
rg.XAxis = xha << 8 | xla;
|
||||
rg.YAxis = yha << 8 | yla;
|
||||
rg.ZAxis = zha << 8 | zla;
|
||||
|
||||
return rg;
|
||||
}
|
||||
|
||||
Vector MPU6050::readNormalizeGyro(void)
|
||||
{
|
||||
readRawGyro();
|
||||
|
||||
if (useCalibrate)
|
||||
{
|
||||
ng.XAxis = (rg.XAxis - dg.XAxis) * dpsPerDigit;
|
||||
ng.YAxis = (rg.YAxis - dg.YAxis) * dpsPerDigit;
|
||||
ng.ZAxis = (rg.ZAxis - dg.ZAxis) * dpsPerDigit;
|
||||
} else
|
||||
{
|
||||
ng.XAxis = rg.XAxis * dpsPerDigit;
|
||||
ng.YAxis = rg.YAxis * dpsPerDigit;
|
||||
ng.ZAxis = rg.ZAxis * dpsPerDigit;
|
||||
}
|
||||
|
||||
if (actualThreshold)
|
||||
{
|
||||
if (abs(ng.XAxis) < tg.XAxis) ng.XAxis = 0;
|
||||
if (abs(ng.YAxis) < tg.YAxis) ng.YAxis = 0;
|
||||
if (abs(ng.ZAxis) < tg.ZAxis) ng.ZAxis = 0;
|
||||
}
|
||||
|
||||
return ng;
|
||||
}
|
||||
|
||||
float MPU6050::readTemperature(void)
|
||||
{
|
||||
int16_t T;
|
||||
T = readRegister16(MPU6050_REG_TEMP_OUT_H);
|
||||
return (float)T/340 + 36.53;
|
||||
}
|
||||
|
||||
int16_t MPU6050::getGyroOffsetX(void)
|
||||
{
|
||||
return readRegister16(MPU6050_REG_GYRO_XOFFS_H);
|
||||
}
|
||||
|
||||
int16_t MPU6050::getGyroOffsetY(void)
|
||||
{
|
||||
return readRegister16(MPU6050_REG_GYRO_YOFFS_H);
|
||||
}
|
||||
|
||||
int16_t MPU6050::getGyroOffsetZ(void)
|
||||
{
|
||||
return readRegister16(MPU6050_REG_GYRO_ZOFFS_H);
|
||||
}
|
||||
|
||||
void MPU6050::setGyroOffsetX(int16_t offset)
|
||||
{
|
||||
writeRegister16(MPU6050_REG_GYRO_XOFFS_H, offset);
|
||||
}
|
||||
|
||||
void MPU6050::setGyroOffsetY(int16_t offset)
|
||||
{
|
||||
writeRegister16(MPU6050_REG_GYRO_YOFFS_H, offset);
|
||||
}
|
||||
|
||||
void MPU6050::setGyroOffsetZ(int16_t offset)
|
||||
{
|
||||
writeRegister16(MPU6050_REG_GYRO_ZOFFS_H, offset);
|
||||
}
|
||||
|
||||
int16_t MPU6050::getAccelOffsetX(void)
|
||||
{
|
||||
return readRegister16(MPU6050_REG_ACCEL_XOFFS_H);
|
||||
}
|
||||
|
||||
int16_t MPU6050::getAccelOffsetY(void)
|
||||
{
|
||||
return readRegister16(MPU6050_REG_ACCEL_YOFFS_H);
|
||||
}
|
||||
|
||||
int16_t MPU6050::getAccelOffsetZ(void)
|
||||
{
|
||||
return readRegister16(MPU6050_REG_ACCEL_ZOFFS_H);
|
||||
}
|
||||
|
||||
void MPU6050::setAccelOffsetX(int16_t offset)
|
||||
{
|
||||
writeRegister16(MPU6050_REG_ACCEL_XOFFS_H, offset);
|
||||
}
|
||||
|
||||
void MPU6050::setAccelOffsetY(int16_t offset)
|
||||
{
|
||||
writeRegister16(MPU6050_REG_ACCEL_YOFFS_H, offset);
|
||||
}
|
||||
|
||||
void MPU6050::setAccelOffsetZ(int16_t offset)
|
||||
{
|
||||
writeRegister16(MPU6050_REG_ACCEL_ZOFFS_H, offset);
|
||||
}
|
||||
|
||||
// Calibrate algorithm
|
||||
void MPU6050::calibrateGyro(uint8_t samples)
|
||||
{
|
||||
// Set calibrate
|
||||
useCalibrate = true;
|
||||
|
||||
// Reset values
|
||||
float sumX = 0;
|
||||
float sumY = 0;
|
||||
float sumZ = 0;
|
||||
float sigmaX = 0;
|
||||
float sigmaY = 0;
|
||||
float sigmaZ = 0;
|
||||
|
||||
// Read n-samples
|
||||
for (uint8_t i = 0; i < samples; ++i)
|
||||
{
|
||||
readRawGyro();
|
||||
sumX += rg.XAxis;
|
||||
sumY += rg.YAxis;
|
||||
sumZ += rg.ZAxis;
|
||||
|
||||
sigmaX += rg.XAxis * rg.XAxis;
|
||||
sigmaY += rg.YAxis * rg.YAxis;
|
||||
sigmaZ += rg.ZAxis * rg.ZAxis;
|
||||
|
||||
delay(5);
|
||||
}
|
||||
|
||||
// Calculate delta vectors
|
||||
dg.XAxis = sumX / samples;
|
||||
dg.YAxis = sumY / samples;
|
||||
dg.ZAxis = sumZ / samples;
|
||||
|
||||
// Calculate threshold vectors
|
||||
th.XAxis = sqrt((sigmaX / 50) - (dg.XAxis * dg.XAxis));
|
||||
th.YAxis = sqrt((sigmaY / 50) - (dg.YAxis * dg.YAxis));
|
||||
th.ZAxis = sqrt((sigmaZ / 50) - (dg.ZAxis * dg.ZAxis));
|
||||
|
||||
// If already set threshold, recalculate threshold vectors
|
||||
if (actualThreshold > 0)
|
||||
{
|
||||
setThreshold(actualThreshold);
|
||||
}
|
||||
}
|
||||
|
||||
// Get current threshold value
|
||||
uint8_t MPU6050::getThreshold(void)
|
||||
{
|
||||
return actualThreshold;
|
||||
}
|
||||
|
||||
// Set treshold value
|
||||
void MPU6050::setThreshold(uint8_t multiple)
|
||||
{
|
||||
if (multiple > 0)
|
||||
{
|
||||
// If not calibrated, need calibrate
|
||||
if (!useCalibrate)
|
||||
{
|
||||
calibrateGyro();
|
||||
}
|
||||
|
||||
// Calculate threshold vectors
|
||||
tg.XAxis = th.XAxis * multiple;
|
||||
tg.YAxis = th.YAxis * multiple;
|
||||
tg.ZAxis = th.ZAxis * multiple;
|
||||
} else
|
||||
{
|
||||
// No threshold
|
||||
tg.XAxis = 0;
|
||||
tg.YAxis = 0;
|
||||
tg.ZAxis = 0;
|
||||
}
|
||||
|
||||
// Remember old threshold value
|
||||
actualThreshold = multiple;
|
||||
}
|
||||
|
||||
// Fast read 8-bit from register
|
||||
uint8_t MPU6050::fastRegister8(uint8_t reg)
|
||||
{
|
||||
uint8_t value;
|
||||
|
||||
Wire.beginTransmission(mpuAddress);
|
||||
#if ARDUINO >= 100
|
||||
Wire.write(reg);
|
||||
#else
|
||||
Wire.send(reg);
|
||||
#endif
|
||||
Wire.endTransmission();
|
||||
|
||||
Wire.beginTransmission(mpuAddress);
|
||||
Wire.requestFrom(mpuAddress, 1);
|
||||
#if ARDUINO >= 100
|
||||
value = Wire.read();
|
||||
#else
|
||||
value = Wire.receive();
|
||||
#endif;
|
||||
Wire.endTransmission();
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
// Read 8-bit from register
|
||||
uint8_t MPU6050::readRegister8(uint8_t reg)
|
||||
{
|
||||
uint8_t value;
|
||||
|
||||
Wire.beginTransmission(mpuAddress);
|
||||
#if ARDUINO >= 100
|
||||
Wire.write(reg);
|
||||
#else
|
||||
Wire.send(reg);
|
||||
#endif
|
||||
Wire.endTransmission();
|
||||
|
||||
Wire.beginTransmission(mpuAddress);
|
||||
Wire.requestFrom(mpuAddress, 1);
|
||||
while(!Wire.available()) {};
|
||||
#if ARDUINO >= 100
|
||||
value = Wire.read();
|
||||
#else
|
||||
value = Wire.receive();
|
||||
#endif;
|
||||
Wire.endTransmission();
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
// Write 8-bit to register
|
||||
void MPU6050::writeRegister8(uint8_t reg, uint8_t value)
|
||||
{
|
||||
Wire.beginTransmission(mpuAddress);
|
||||
|
||||
#if ARDUINO >= 100
|
||||
Wire.write(reg);
|
||||
Wire.write(value);
|
||||
#else
|
||||
Wire.send(reg);
|
||||
Wire.send(value);
|
||||
#endif
|
||||
Wire.endTransmission();
|
||||
}
|
||||
|
||||
int16_t MPU6050::readRegister16(uint8_t reg)
|
||||
{
|
||||
int16_t value;
|
||||
Wire.beginTransmission(mpuAddress);
|
||||
#if ARDUINO >= 100
|
||||
Wire.write(reg);
|
||||
#else
|
||||
Wire.send(reg);
|
||||
#endif
|
||||
Wire.endTransmission();
|
||||
|
||||
Wire.beginTransmission(mpuAddress);
|
||||
Wire.requestFrom(mpuAddress, 2);
|
||||
while(!Wire.available()) {};
|
||||
#if ARDUINO >= 100
|
||||
uint8_t vha = Wire.read();
|
||||
uint8_t vla = Wire.read();
|
||||
#else
|
||||
uint8_t vha = Wire.receive();
|
||||
uint8_t vla = Wire.receive();
|
||||
#endif;
|
||||
Wire.endTransmission();
|
||||
|
||||
value = vha << 8 | vla;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void MPU6050::writeRegister16(uint8_t reg, int16_t value)
|
||||
{
|
||||
Wire.beginTransmission(mpuAddress);
|
||||
|
||||
#if ARDUINO >= 100
|
||||
Wire.write(reg);
|
||||
Wire.write((uint8_t)(value >> 8));
|
||||
Wire.write((uint8_t)value);
|
||||
#else
|
||||
Wire.send(reg);
|
||||
Wire.send((uint8_t)(value >> 8));
|
||||
Wire.send((uint8_t)value);
|
||||
#endif
|
||||
Wire.endTransmission();
|
||||
}
|
||||
|
||||
// Read register bit
|
||||
bool MPU6050::readRegisterBit(uint8_t reg, uint8_t pos)
|
||||
{
|
||||
uint8_t value;
|
||||
value = readRegister8(reg);
|
||||
return ((value >> pos) & 1);
|
||||
}
|
||||
|
||||
// Write register bit
|
||||
void MPU6050::writeRegisterBit(uint8_t reg, uint8_t pos, bool state)
|
||||
{
|
||||
uint8_t value;
|
||||
value = readRegister8(reg);
|
||||
|
||||
if (state)
|
||||
{
|
||||
value |= (1 << pos);
|
||||
} else
|
||||
{
|
||||
value &= ~(1 << pos);
|
||||
}
|
||||
|
||||
writeRegister8(reg, value);
|
||||
}
|
||||
258
arduino-cli/libraries/MPU6050/MPU6050.h
Normal file
258
arduino-cli/libraries/MPU6050/MPU6050.h
Normal file
@@ -0,0 +1,258 @@
|
||||
/*
|
||||
MPU6050.h - Header file for the MPU6050 Triple Axis Gyroscope & Accelerometer Arduino Library.
|
||||
|
||||
Version: 1.0.3
|
||||
(c) 2014-2015 Korneliusz Jarzebski
|
||||
www.jarzebski.pl
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the version 3 GNU General Public License as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef MPU6050_h
|
||||
#define MPU6050_h
|
||||
|
||||
#if ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
#define MPU6050_ADDRESS (0x68) // 0x69 when AD0 pin to Vcc
|
||||
|
||||
#define MPU6050_REG_ACCEL_XOFFS_H (0x06)
|
||||
#define MPU6050_REG_ACCEL_XOFFS_L (0x07)
|
||||
#define MPU6050_REG_ACCEL_YOFFS_H (0x08)
|
||||
#define MPU6050_REG_ACCEL_YOFFS_L (0x09)
|
||||
#define MPU6050_REG_ACCEL_ZOFFS_H (0x0A)
|
||||
#define MPU6050_REG_ACCEL_ZOFFS_L (0x0B)
|
||||
#define MPU6050_REG_GYRO_XOFFS_H (0x13)
|
||||
#define MPU6050_REG_GYRO_XOFFS_L (0x14)
|
||||
#define MPU6050_REG_GYRO_YOFFS_H (0x15)
|
||||
#define MPU6050_REG_GYRO_YOFFS_L (0x16)
|
||||
#define MPU6050_REG_GYRO_ZOFFS_H (0x17)
|
||||
#define MPU6050_REG_GYRO_ZOFFS_L (0x18)
|
||||
#define MPU6050_REG_CONFIG (0x1A)
|
||||
#define MPU6050_REG_GYRO_CONFIG (0x1B) // Gyroscope Configuration
|
||||
#define MPU6050_REG_ACCEL_CONFIG (0x1C) // Accelerometer Configuration
|
||||
#define MPU6050_REG_FF_THRESHOLD (0x1D)
|
||||
#define MPU6050_REG_FF_DURATION (0x1E)
|
||||
#define MPU6050_REG_MOT_THRESHOLD (0x1F)
|
||||
#define MPU6050_REG_MOT_DURATION (0x20)
|
||||
#define MPU6050_REG_ZMOT_THRESHOLD (0x21)
|
||||
#define MPU6050_REG_ZMOT_DURATION (0x22)
|
||||
#define MPU6050_REG_INT_PIN_CFG (0x37) // INT Pin. Bypass Enable Configuration
|
||||
#define MPU6050_REG_INT_ENABLE (0x38) // INT Enable
|
||||
#define MPU6050_REG_INT_STATUS (0x3A)
|
||||
#define MPU6050_REG_ACCEL_XOUT_H (0x3B)
|
||||
#define MPU6050_REG_ACCEL_XOUT_L (0x3C)
|
||||
#define MPU6050_REG_ACCEL_YOUT_H (0x3D)
|
||||
#define MPU6050_REG_ACCEL_YOUT_L (0x3E)
|
||||
#define MPU6050_REG_ACCEL_ZOUT_H (0x3F)
|
||||
#define MPU6050_REG_ACCEL_ZOUT_L (0x40)
|
||||
#define MPU6050_REG_TEMP_OUT_H (0x41)
|
||||
#define MPU6050_REG_TEMP_OUT_L (0x42)
|
||||
#define MPU6050_REG_GYRO_XOUT_H (0x43)
|
||||
#define MPU6050_REG_GYRO_XOUT_L (0x44)
|
||||
#define MPU6050_REG_GYRO_YOUT_H (0x45)
|
||||
#define MPU6050_REG_GYRO_YOUT_L (0x46)
|
||||
#define MPU6050_REG_GYRO_ZOUT_H (0x47)
|
||||
#define MPU6050_REG_GYRO_ZOUT_L (0x48)
|
||||
#define MPU6050_REG_MOT_DETECT_STATUS (0x61)
|
||||
#define MPU6050_REG_MOT_DETECT_CTRL (0x69)
|
||||
#define MPU6050_REG_USER_CTRL (0x6A) // User Control
|
||||
#define MPU6050_REG_PWR_MGMT_1 (0x6B) // Power Management 1
|
||||
#define MPU6050_REG_WHO_AM_I (0x75) // Who Am I
|
||||
|
||||
#ifndef VECTOR_STRUCT_H
|
||||
#define VECTOR_STRUCT_H
|
||||
struct Vector
|
||||
{
|
||||
float XAxis;
|
||||
float YAxis;
|
||||
float ZAxis;
|
||||
};
|
||||
#endif
|
||||
|
||||
struct Activites
|
||||
{
|
||||
bool isOverflow;
|
||||
bool isFreeFall;
|
||||
bool isInactivity;
|
||||
bool isActivity;
|
||||
bool isPosActivityOnX;
|
||||
bool isPosActivityOnY;
|
||||
bool isPosActivityOnZ;
|
||||
bool isNegActivityOnX;
|
||||
bool isNegActivityOnY;
|
||||
bool isNegActivityOnZ;
|
||||
bool isDataReady;
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MPU6050_CLOCK_KEEP_RESET = 0b111,
|
||||
MPU6050_CLOCK_EXTERNAL_19MHZ = 0b101,
|
||||
MPU6050_CLOCK_EXTERNAL_32KHZ = 0b100,
|
||||
MPU6050_CLOCK_PLL_ZGYRO = 0b011,
|
||||
MPU6050_CLOCK_PLL_YGYRO = 0b010,
|
||||
MPU6050_CLOCK_PLL_XGYRO = 0b001,
|
||||
MPU6050_CLOCK_INTERNAL_8MHZ = 0b000
|
||||
} mpu6050_clockSource_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MPU6050_SCALE_2000DPS = 0b11,
|
||||
MPU6050_SCALE_1000DPS = 0b10,
|
||||
MPU6050_SCALE_500DPS = 0b01,
|
||||
MPU6050_SCALE_250DPS = 0b00
|
||||
} mpu6050_dps_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MPU6050_RANGE_16G = 0b11,
|
||||
MPU6050_RANGE_8G = 0b10,
|
||||
MPU6050_RANGE_4G = 0b01,
|
||||
MPU6050_RANGE_2G = 0b00,
|
||||
} mpu6050_range_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MPU6050_DELAY_3MS = 0b11,
|
||||
MPU6050_DELAY_2MS = 0b10,
|
||||
MPU6050_DELAY_1MS = 0b01,
|
||||
MPU6050_NO_DELAY = 0b00,
|
||||
} mpu6050_onDelay_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MPU6050_DHPF_HOLD = 0b111,
|
||||
MPU6050_DHPF_0_63HZ = 0b100,
|
||||
MPU6050_DHPF_1_25HZ = 0b011,
|
||||
MPU6050_DHPF_2_5HZ = 0b010,
|
||||
MPU6050_DHPF_5HZ = 0b001,
|
||||
MPU6050_DHPF_RESET = 0b000,
|
||||
} mpu6050_dhpf_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MPU6050_DLPF_6 = 0b110,
|
||||
MPU6050_DLPF_5 = 0b101,
|
||||
MPU6050_DLPF_4 = 0b100,
|
||||
MPU6050_DLPF_3 = 0b011,
|
||||
MPU6050_DLPF_2 = 0b010,
|
||||
MPU6050_DLPF_1 = 0b001,
|
||||
MPU6050_DLPF_0 = 0b000,
|
||||
} mpu6050_dlpf_t;
|
||||
|
||||
class MPU6050
|
||||
{
|
||||
public:
|
||||
|
||||
bool begin(mpu6050_dps_t scale = MPU6050_SCALE_2000DPS, mpu6050_range_t range = MPU6050_RANGE_2G, int mpua = MPU6050_ADDRESS);
|
||||
|
||||
void setClockSource(mpu6050_clockSource_t source);
|
||||
void setScale(mpu6050_dps_t scale);
|
||||
void setRange(mpu6050_range_t range);
|
||||
mpu6050_clockSource_t getClockSource(void);
|
||||
mpu6050_dps_t getScale(void);
|
||||
mpu6050_range_t getRange(void);
|
||||
void setDHPFMode(mpu6050_dhpf_t dhpf);
|
||||
void setDLPFMode(mpu6050_dlpf_t dlpf);
|
||||
mpu6050_onDelay_t getAccelPowerOnDelay();
|
||||
void setAccelPowerOnDelay(mpu6050_onDelay_t delay);
|
||||
|
||||
uint8_t getIntStatus(void);
|
||||
|
||||
bool getIntZeroMotionEnabled(void);
|
||||
void setIntZeroMotionEnabled(bool state);
|
||||
bool getIntMotionEnabled(void);
|
||||
void setIntMotionEnabled(bool state);
|
||||
bool getIntFreeFallEnabled(void);
|
||||
void setIntFreeFallEnabled(bool state);
|
||||
|
||||
uint8_t getMotionDetectionThreshold(void);
|
||||
void setMotionDetectionThreshold(uint8_t threshold);
|
||||
uint8_t getMotionDetectionDuration(void);
|
||||
void setMotionDetectionDuration(uint8_t duration);
|
||||
|
||||
uint8_t getZeroMotionDetectionThreshold(void);
|
||||
void setZeroMotionDetectionThreshold(uint8_t threshold);
|
||||
uint8_t getZeroMotionDetectionDuration(void);
|
||||
void setZeroMotionDetectionDuration(uint8_t duration);
|
||||
|
||||
uint8_t getFreeFallDetectionThreshold(void);
|
||||
void setFreeFallDetectionThreshold(uint8_t threshold);
|
||||
uint8_t getFreeFallDetectionDuration(void);
|
||||
void setFreeFallDetectionDuration(uint8_t duration);
|
||||
|
||||
bool getSleepEnabled(void);
|
||||
void setSleepEnabled(bool state);
|
||||
bool getI2CMasterModeEnabled(void);
|
||||
void setI2CMasterModeEnabled(bool state);
|
||||
bool getI2CBypassEnabled(void);
|
||||
void setI2CBypassEnabled(bool state);
|
||||
|
||||
float readTemperature(void);
|
||||
Activites readActivites(void);
|
||||
|
||||
int16_t getGyroOffsetX(void);
|
||||
void setGyroOffsetX(int16_t offset);
|
||||
int16_t getGyroOffsetY(void);
|
||||
void setGyroOffsetY(int16_t offset);
|
||||
int16_t getGyroOffsetZ(void);
|
||||
void setGyroOffsetZ(int16_t offset);
|
||||
|
||||
int16_t getAccelOffsetX(void);
|
||||
void setAccelOffsetX(int16_t offset);
|
||||
int16_t getAccelOffsetY(void);
|
||||
void setAccelOffsetY(int16_t offset);
|
||||
int16_t getAccelOffsetZ(void);
|
||||
void setAccelOffsetZ(int16_t offset);
|
||||
|
||||
void calibrateGyro(uint8_t samples = 50);
|
||||
void setThreshold(uint8_t multiple = 1);
|
||||
uint8_t getThreshold(void);
|
||||
|
||||
Vector readRawGyro(void);
|
||||
Vector readNormalizeGyro(void);
|
||||
|
||||
Vector readRawAccel(void);
|
||||
Vector readNormalizeAccel(void);
|
||||
Vector readScaledAccel(void);
|
||||
|
||||
private:
|
||||
Vector ra, rg; // Raw vectors
|
||||
Vector na, ng; // Normalized vectors
|
||||
Vector tg, dg; // Threshold and Delta for Gyro
|
||||
Vector th; // Threshold
|
||||
Activites a; // Activities
|
||||
|
||||
float dpsPerDigit, rangePerDigit;
|
||||
float actualThreshold;
|
||||
bool useCalibrate;
|
||||
int mpuAddress;
|
||||
|
||||
uint8_t fastRegister8(uint8_t reg);
|
||||
|
||||
uint8_t readRegister8(uint8_t reg);
|
||||
void writeRegister8(uint8_t reg, uint8_t value);
|
||||
|
||||
int16_t readRegister16(uint8_t reg);
|
||||
void writeRegister16(uint8_t reg, int16_t value);
|
||||
|
||||
bool readRegisterBit(uint8_t reg, uint8_t pos);
|
||||
void writeRegisterBit(uint8_t reg, uint8_t pos, bool state);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
747
arduino-cli/libraries/MPU6050/MPU6050_6Axis_MotionApps20.h
Normal file
747
arduino-cli/libraries/MPU6050/MPU6050_6Axis_MotionApps20.h
Normal file
@@ -0,0 +1,747 @@
|
||||
// I2Cdev library collection - MPU6050 I2C device class, 6-axis MotionApps 2.0 implementation
|
||||
// Based on InvenSense MPU-6050 register map document rev. 2.0, 5/19/2011 (RM-MPU-6000A-00)
|
||||
// 5/20/2013 by Jeff Rowberg <jeff@rowberg.net>
|
||||
// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
|
||||
//
|
||||
// Changelog:
|
||||
// ... - ongoing debug release
|
||||
|
||||
/* ============================================
|
||||
I2Cdev device library code is placed under the MIT license
|
||||
Copyright (c) 2012 Jeff Rowberg
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
===============================================
|
||||
*/
|
||||
|
||||
#ifndef _MPU6050_6AXIS_MOTIONAPPS20_H_
|
||||
#define _MPU6050_6AXIS_MOTIONAPPS20_H_
|
||||
|
||||
#include "I2Cdev.h"
|
||||
#include "helper_3dmath.h"
|
||||
|
||||
// MotionApps 2.0 DMP implementation, built using the MPU-6050EVB evaluation board
|
||||
#define MPU6050_INCLUDE_DMP_MOTIONAPPS20
|
||||
|
||||
#include "MPU6050.h"
|
||||
|
||||
// Tom Carpenter's conditional PROGMEM code
|
||||
// http://forum.arduino.cc/index.php?topic=129407.0
|
||||
#ifdef __AVR__
|
||||
#include <avr/pgmspace.h>
|
||||
#else
|
||||
// Teensy 3.0 library conditional PROGMEM code from Paul Stoffregen
|
||||
#ifndef __PGMSPACE_H_
|
||||
#define __PGMSPACE_H_ 1
|
||||
#include <inttypes.h>
|
||||
|
||||
#define PROGMEM
|
||||
#define PGM_P const char *
|
||||
#define PSTR(str) (str)
|
||||
#define F(x) x
|
||||
|
||||
typedef void prog_void;
|
||||
typedef char prog_char;
|
||||
typedef unsigned char prog_uchar;
|
||||
typedef int8_t prog_int8_t;
|
||||
typedef uint8_t prog_uint8_t;
|
||||
typedef int16_t prog_int16_t;
|
||||
typedef uint16_t prog_uint16_t;
|
||||
typedef int32_t prog_int32_t;
|
||||
typedef uint32_t prog_uint32_t;
|
||||
|
||||
#define strcpy_P(dest, src) strcpy((dest), (src))
|
||||
#define strcat_P(dest, src) strcat((dest), (src))
|
||||
#define strcmp_P(a, b) strcmp((a), (b))
|
||||
|
||||
#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
|
||||
#define pgm_read_word(addr) (*(const unsigned short *)(addr))
|
||||
#define pgm_read_dword(addr) (*(const unsigned long *)(addr))
|
||||
#define pgm_read_float(addr) (*(const float *)(addr))
|
||||
|
||||
#define pgm_read_byte_near(addr) pgm_read_byte(addr)
|
||||
#define pgm_read_word_near(addr) pgm_read_word(addr)
|
||||
#define pgm_read_dword_near(addr) pgm_read_dword(addr)
|
||||
#define pgm_read_float_near(addr) pgm_read_float(addr)
|
||||
#define pgm_read_byte_far(addr) pgm_read_byte(addr)
|
||||
#define pgm_read_word_far(addr) pgm_read_word(addr)
|
||||
#define pgm_read_dword_far(addr) pgm_read_dword(addr)
|
||||
#define pgm_read_float_far(addr) pgm_read_float(addr)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Source is from the InvenSense MotionApps v2 demo code. Original source is
|
||||
* unavailable, unless you happen to be amazing as decompiling binary by
|
||||
* hand (in which case, please contact me, and I'm totally serious).
|
||||
*
|
||||
* Also, I'd like to offer many, many thanks to Noah Zerkin for all of the
|
||||
* DMP reverse-engineering he did to help make this bit of wizardry
|
||||
* possible.
|
||||
*/
|
||||
|
||||
// NOTE! Enabling DEBUG adds about 3.3kB to the flash program size.
|
||||
// Debug output is now working even on ATMega328P MCUs (e.g. Arduino Uno)
|
||||
// after moving string constants to flash memory storage using the F()
|
||||
// compiler macro (Arduino IDE 1.0+ required).
|
||||
|
||||
//#define DEBUG
|
||||
#ifdef DEBUG
|
||||
#define DEBUG_PRINT(x) Serial.print(x)
|
||||
#define DEBUG_PRINTF(x, y) Serial.print(x, y)
|
||||
#define DEBUG_PRINTLN(x) Serial.println(x)
|
||||
#define DEBUG_PRINTLNF(x, y) Serial.println(x, y)
|
||||
#else
|
||||
#define DEBUG_PRINT(x)
|
||||
#define DEBUG_PRINTF(x, y)
|
||||
#define DEBUG_PRINTLN(x)
|
||||
#define DEBUG_PRINTLNF(x, y)
|
||||
#endif
|
||||
|
||||
#define MPU6050_DMP_CODE_SIZE 1929 // dmpMemory[]
|
||||
#define MPU6050_DMP_CONFIG_SIZE 192 // dmpConfig[]
|
||||
#define MPU6050_DMP_UPDATES_SIZE 47 // dmpUpdates[]
|
||||
|
||||
/* ================================================================================================ *
|
||||
| Default MotionApps v2.0 42-byte FIFO packet structure: |
|
||||
| |
|
||||
| [QUAT W][ ][QUAT X][ ][QUAT Y][ ][QUAT Z][ ][GYRO X][ ][GYRO Y][ ] |
|
||||
| 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
||||
| |
|
||||
| [GYRO Z][ ][ACC X ][ ][ACC Y ][ ][ACC Z ][ ][ ] |
|
||||
| 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
||||
* ================================================================================================ */
|
||||
|
||||
// this block of memory gets written to the MPU on start-up, and it seems
|
||||
// to be volatile memory, so it has to be done each time (it only takes ~1
|
||||
// second though)
|
||||
const unsigned char dmpMemory[MPU6050_DMP_CODE_SIZE] PROGMEM = {
|
||||
// bank 0, 256 bytes
|
||||
0xFB, 0x00, 0x00, 0x3E, 0x00, 0x0B, 0x00, 0x36, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00,
|
||||
0x00, 0x65, 0x00, 0x54, 0xFF, 0xEF, 0x00, 0x00, 0xFA, 0x80, 0x00, 0x0B, 0x12, 0x82, 0x00, 0x01,
|
||||
0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x28, 0x00, 0x00, 0xFF, 0xFF, 0x45, 0x81, 0xFF, 0xFF, 0xFA, 0x72, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x03, 0xE8, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x7F, 0xFF, 0xFF, 0xFE, 0x80, 0x01,
|
||||
0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x3E, 0x03, 0x30, 0x40, 0x00, 0x00, 0x00, 0x02, 0xCA, 0xE3, 0x09, 0x3E, 0x80, 0x00, 0x00,
|
||||
0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00,
|
||||
0x41, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x0B, 0x2A, 0x00, 0x00, 0x16, 0x55, 0x00, 0x00, 0x21, 0x82,
|
||||
0xFD, 0x87, 0x26, 0x50, 0xFD, 0x80, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x05, 0x80, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
|
||||
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x6F, 0x00, 0x02, 0x65, 0x32, 0x00, 0x00, 0x5E, 0xC0,
|
||||
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xFB, 0x8C, 0x6F, 0x5D, 0xFD, 0x5D, 0x08, 0xD9, 0x00, 0x7C, 0x73, 0x3B, 0x00, 0x6C, 0x12, 0xCC,
|
||||
0x32, 0x00, 0x13, 0x9D, 0x32, 0x00, 0xD0, 0xD6, 0x32, 0x00, 0x08, 0x00, 0x40, 0x00, 0x01, 0xF4,
|
||||
0xFF, 0xE6, 0x80, 0x79, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD0, 0xD6, 0x00, 0x00, 0x27, 0x10,
|
||||
|
||||
// bank 1, 256 bytes
|
||||
0xFB, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0xFA, 0x36, 0xFF, 0xBC, 0x30, 0x8E, 0x00, 0x05, 0xFB, 0xF0, 0xFF, 0xD9, 0x5B, 0xC8,
|
||||
0xFF, 0xD0, 0x9A, 0xBE, 0x00, 0x00, 0x10, 0xA9, 0xFF, 0xF4, 0x1E, 0xB2, 0x00, 0xCE, 0xBB, 0xF7,
|
||||
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x02, 0x00, 0x02, 0x02, 0x00, 0x00, 0x0C,
|
||||
0xFF, 0xC2, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0xCF, 0x80, 0x00, 0x40, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x14,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x03, 0x3F, 0x68, 0xB6, 0x79, 0x35, 0x28, 0xBC, 0xC6, 0x7E, 0xD1, 0x6C,
|
||||
0x80, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB2, 0x6A, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xF0, 0x00, 0x00, 0x00, 0x30,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x25, 0x4D, 0x00, 0x2F, 0x70, 0x6D, 0x00, 0x00, 0x05, 0xAE, 0x00, 0x0C, 0x02, 0xD0,
|
||||
|
||||
// bank 2, 256 bytes
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x54, 0xFF, 0xEF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x01, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x01, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0xFF, 0xEF, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
|
||||
0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00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0xDA, 0xDE, 0xD8, 0xA8, 0x60,
|
||||
0xAA, 0xDA, 0xD0, 0xDF, 0xD8, 0xF1, 0x97, 0x86, 0xA8, 0x31, 0x9B, 0x06, 0x99, 0x07, 0xAB, 0x97,
|
||||
0x28, 0x88, 0x9B, 0xF0, 0x0C, 0x20, 0x14, 0x40, 0xB8, 0xB0, 0xB4, 0xA8, 0x8C, 0x9C, 0xF0, 0x04,
|
||||
0x28, 0x51, 0x79, 0x1D, 0x30, 0x14, 0x38, 0xB2, 0x82, 0xAB, 0xD0, 0x98, 0x2C, 0x50, 0x50, 0x78,
|
||||
0x78, 0x9B, 0xF1, 0x1A, 0xB0, 0xF0, 0x8A, 0x9C, 0xA8, 0x29, 0x51, 0x79, 0x8B, 0x29, 0x51, 0x79,
|
||||
0x8A, 0x24, 0x70, 0x59, 0x8B, 0x20, 0x58, 0x71, 0x8A, 0x44, 0x69, 0x38, 0x8B, 0x39, 0x40, 0x68,
|
||||
0x8A, 0x64, 0x48, 0x31, 0x8B, 0x30, 0x49, 0x60, 0xA5, 0x88, 0x20, 0x09, 0x71, 0x58, 0x44, 0x68,
|
||||
|
||||
// bank 6, 256 bytes
|
||||
0x11, 0x39, 0x64, 0x49, 0x30, 0x19, 0xF1, 0xAC, 0x00, 0x2C, 0x54, 0x7C, 0xF0, 0x8C, 0xA8, 0x04,
|
||||
0x28, 0x50, 0x78, 0xF1, 0x88, 0x97, 0x26, 0xA8, 0x59, 0x98, 0xAC, 0x8C, 0x02, 0x26, 0x46, 0x66,
|
||||
0xF0, 0x89, 0x9C, 0xA8, 0x29, 0x51, 0x79, 0x24, 0x70, 0x59, 0x44, 0x69, 0x38, 0x64, 0x48, 0x31,
|
||||
0xA9, 0x88, 0x09, 0x20, 0x59, 0x70, 0xAB, 0x11, 0x38, 0x40, 0x69, 0xA8, 0x19, 0x31, 0x48, 0x60,
|
||||
0x8C, 0xA8, 0x3C, 0x41, 0x5C, 0x20, 0x7C, 0x00, 0xF1, 0x87, 0x98,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x9B, 0x2D, 0xD9, 0xD8, 0xD8, 0x51, 0xD9, 0xD8, 0xD8, 0x79,
|
||||
|
||||
// bank 7, 138 bytes (remainder)
|
||||
0xD9, 0xD8, 0xD8, 0xF1, 0x9E, 0x88, 0xA3, 0x31, 0xDA, 0xD8, 0xD8, 0x91, 0x2D, 0xD9, 0x28, 0xD8,
|
||||
0x4D, 0xD9, 0x48, 0xD8, 0x6D, 0xD9, 0x68, 0xD8, 0xB1, 0x83, 0x93, 0x35, 0x3D, 0x80, 0x25, 0xDA,
|
||||
0xD8, 0xD8, 0x85, 0x69, 0xDA, 0xD8, 0xD8, 0xB4, 0x93, 0x81, 0xA3, 0x28, 0x34, 0x3C, 0xF3, 0xAB,
|
||||
0x8B, 0xF8, 0xA3, 0x91, 0xB6, 0x09, 0xB4, 0xD9, 0xAB, 0xDE, 0xFA, 0xB0, 0x87, 0x9C, 0xB9, 0xA3,
|
||||
0xDD, 0xF1, 0xA3, 0xA3, 0xA3, 0xA3, 0x95, 0xF1, 0xA3, 0xA3, 0xA3, 0x9D, 0xF1, 0xA3, 0xA3, 0xA3,
|
||||
0xA3, 0xF2, 0xA3, 0xB4, 0x90, 0x80, 0xF2, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3,
|
||||
0xA3, 0xB2, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xB0, 0x87, 0xB5, 0x99, 0xF1, 0xA3, 0xA3, 0xA3,
|
||||
0x98, 0xF1, 0xA3, 0xA3, 0xA3, 0xA3, 0x97, 0xA3, 0xA3, 0xA3, 0xA3, 0xF3, 0x9B, 0xA3, 0xA3, 0xDC,
|
||||
0xB9, 0xA7, 0xF1, 0x26, 0x26, 0x26, 0xD8, 0xD8, 0xFF
|
||||
};
|
||||
|
||||
// thanks to Noah Zerkin for piecing this stuff together!
|
||||
const unsigned char dmpConfig[MPU6050_DMP_CONFIG_SIZE] PROGMEM = {
|
||||
// BANK OFFSET LENGTH [DATA]
|
||||
0x03, 0x7B, 0x03, 0x4C, 0xCD, 0x6C, // FCFG_1 inv_set_gyro_calibration
|
||||
0x03, 0xAB, 0x03, 0x36, 0x56, 0x76, // FCFG_3 inv_set_gyro_calibration
|
||||
0x00, 0x68, 0x04, 0x02, 0xCB, 0x47, 0xA2, // D_0_104 inv_set_gyro_calibration
|
||||
0x02, 0x18, 0x04, 0x00, 0x05, 0x8B, 0xC1, // D_0_24 inv_set_gyro_calibration
|
||||
0x01, 0x0C, 0x04, 0x00, 0x00, 0x00, 0x00, // D_1_152 inv_set_accel_calibration
|
||||
0x03, 0x7F, 0x06, 0x0C, 0xC9, 0x2C, 0x97, 0x97, 0x97, // FCFG_2 inv_set_accel_calibration
|
||||
0x03, 0x89, 0x03, 0x26, 0x46, 0x66, // FCFG_7 inv_set_accel_calibration
|
||||
0x00, 0x6C, 0x02, 0x20, 0x00, // D_0_108 inv_set_accel_calibration
|
||||
0x02, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_00 inv_set_compass_calibration
|
||||
0x02, 0x44, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_01
|
||||
0x02, 0x48, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_02
|
||||
0x02, 0x4C, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_10
|
||||
0x02, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_11
|
||||
0x02, 0x54, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_12
|
||||
0x02, 0x58, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_20
|
||||
0x02, 0x5C, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_21
|
||||
0x02, 0xBC, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_22
|
||||
0x01, 0xEC, 0x04, 0x00, 0x00, 0x40, 0x00, // D_1_236 inv_apply_endian_accel
|
||||
0x03, 0x7F, 0x06, 0x0C, 0xC9, 0x2C, 0x97, 0x97, 0x97, // FCFG_2 inv_set_mpu_sensors
|
||||
0x04, 0x02, 0x03, 0x0D, 0x35, 0x5D, // CFG_MOTION_BIAS inv_turn_on_bias_from_no_motion
|
||||
0x04, 0x09, 0x04, 0x87, 0x2D, 0x35, 0x3D, // FCFG_5 inv_set_bias_update
|
||||
0x00, 0xA3, 0x01, 0x00, // D_0_163 inv_set_dead_zone
|
||||
// SPECIAL 0x01 = enable interrupts
|
||||
0x00, 0x00, 0x00, 0x01, // SET INT_ENABLE at i=22, SPECIAL INSTRUCTION
|
||||
0x07, 0x86, 0x01, 0xFE, // CFG_6 inv_set_fifo_interupt
|
||||
0x07, 0x41, 0x05, 0xF1, 0x20, 0x28, 0x30, 0x38, // CFG_8 inv_send_quaternion
|
||||
0x07, 0x7E, 0x01, 0x30, // CFG_16 inv_set_footer
|
||||
0x07, 0x46, 0x01, 0x9A, // CFG_GYRO_SOURCE inv_send_gyro
|
||||
0x07, 0x47, 0x04, 0xF1, 0x28, 0x30, 0x38, // CFG_9 inv_send_gyro -> inv_construct3_fifo
|
||||
0x07, 0x6C, 0x04, 0xF1, 0x28, 0x30, 0x38, // CFG_12 inv_send_accel -> inv_construct3_fifo
|
||||
0x02, 0x16, 0x02, 0x00, 0x01 // D_0_22 inv_set_fifo_rate
|
||||
|
||||
// This very last 0x01 WAS a 0x09, which drops the FIFO rate down to 20 Hz. 0x07 is 25 Hz,
|
||||
// 0x01 is 100Hz. Going faster than 100Hz (0x00=200Hz) tends to result in very noisy data.
|
||||
// DMP output frequency is calculated easily using this equation: (200Hz / (1 + value))
|
||||
|
||||
// It is important to make sure the host processor can keep up with reading and processing
|
||||
// the FIFO output at the desired rate. Handling FIFO overflow cleanly is also a good idea.
|
||||
};
|
||||
|
||||
const unsigned char dmpUpdates[MPU6050_DMP_UPDATES_SIZE] PROGMEM = {
|
||||
0x01, 0xB2, 0x02, 0xFF, 0xFF,
|
||||
0x01, 0x90, 0x04, 0x09, 0x23, 0xA1, 0x35,
|
||||
0x01, 0x6A, 0x02, 0x06, 0x00,
|
||||
0x01, 0x60, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x60, 0x04, 0x40, 0x00, 0x00, 0x00,
|
||||
0x01, 0x62, 0x02, 0x00, 0x00,
|
||||
0x00, 0x60, 0x04, 0x00, 0x40, 0x00, 0x00
|
||||
};
|
||||
|
||||
uint8_t MPU6050::dmpInitialize() {
|
||||
// reset device
|
||||
DEBUG_PRINTLN(F("\n\nResetting MPU6050..."));
|
||||
reset();
|
||||
delay(30); // wait after reset
|
||||
|
||||
// enable sleep mode and wake cycle
|
||||
/*Serial.println(F("Enabling sleep mode..."));
|
||||
setSleepEnabled(true);
|
||||
Serial.println(F("Enabling wake cycle..."));
|
||||
setWakeCycleEnabled(true);*/
|
||||
|
||||
// disable sleep mode
|
||||
DEBUG_PRINTLN(F("Disabling sleep mode..."));
|
||||
setSleepEnabled(false);
|
||||
|
||||
// get MPU hardware revision
|
||||
DEBUG_PRINTLN(F("Selecting user bank 16..."));
|
||||
setMemoryBank(0x10, true, true);
|
||||
DEBUG_PRINTLN(F("Selecting memory byte 6..."));
|
||||
setMemoryStartAddress(0x06);
|
||||
DEBUG_PRINTLN(F("Checking hardware revision..."));
|
||||
DEBUG_PRINT(F("Revision @ user[16][6] = "));
|
||||
DEBUG_PRINTLNF(readMemoryByte(), HEX);
|
||||
DEBUG_PRINTLN(F("Resetting memory bank selection to 0..."));
|
||||
setMemoryBank(0, false, false);
|
||||
|
||||
// check OTP bank valid
|
||||
DEBUG_PRINTLN(F("Reading OTP bank valid flag..."));
|
||||
DEBUG_PRINT(F("OTP bank is "));
|
||||
DEBUG_PRINTLN(getOTPBankValid() ? F("valid!") : F("invalid!"));
|
||||
|
||||
// get X/Y/Z gyro offsets
|
||||
DEBUG_PRINTLN(F("Reading gyro offset TC values..."));
|
||||
int8_t xgOffsetTC = getXGyroOffsetTC();
|
||||
int8_t ygOffsetTC = getYGyroOffsetTC();
|
||||
int8_t zgOffsetTC = getZGyroOffsetTC();
|
||||
DEBUG_PRINT(F("X gyro offset = "));
|
||||
DEBUG_PRINTLN(xgOffsetTC);
|
||||
DEBUG_PRINT(F("Y gyro offset = "));
|
||||
DEBUG_PRINTLN(ygOffsetTC);
|
||||
DEBUG_PRINT(F("Z gyro offset = "));
|
||||
DEBUG_PRINTLN(zgOffsetTC);
|
||||
|
||||
// setup weird slave stuff (?)
|
||||
DEBUG_PRINTLN(F("Setting slave 0 address to 0x7F..."));
|
||||
setSlaveAddress(0, 0x7F);
|
||||
DEBUG_PRINTLN(F("Disabling I2C Master mode..."));
|
||||
setI2CMasterModeEnabled(false);
|
||||
DEBUG_PRINTLN(F("Setting slave 0 address to 0x68 (self)..."));
|
||||
setSlaveAddress(0, 0x68);
|
||||
DEBUG_PRINTLN(F("Resetting I2C Master control..."));
|
||||
resetI2CMaster();
|
||||
delay(20);
|
||||
|
||||
// load DMP code into memory banks
|
||||
DEBUG_PRINT(F("Writing DMP code to MPU memory banks ("));
|
||||
DEBUG_PRINT(MPU6050_DMP_CODE_SIZE);
|
||||
DEBUG_PRINTLN(F(" bytes)"));
|
||||
if (writeProgMemoryBlock(dmpMemory, MPU6050_DMP_CODE_SIZE)) {
|
||||
DEBUG_PRINTLN(F("Success! DMP code written and verified."));
|
||||
|
||||
// write DMP configuration
|
||||
DEBUG_PRINT(F("Writing DMP configuration to MPU memory banks ("));
|
||||
DEBUG_PRINT(MPU6050_DMP_CONFIG_SIZE);
|
||||
DEBUG_PRINTLN(F(" bytes in config def)"));
|
||||
if (writeProgDMPConfigurationSet(dmpConfig, MPU6050_DMP_CONFIG_SIZE)) {
|
||||
DEBUG_PRINTLN(F("Success! DMP configuration written and verified."));
|
||||
|
||||
DEBUG_PRINTLN(F("Setting clock source to Z Gyro..."));
|
||||
setClockSource(MPU6050_CLOCK_PLL_ZGYRO);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting DMP and FIFO_OFLOW interrupts enabled..."));
|
||||
setIntEnabled(0x12);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting sample rate to 200Hz..."));
|
||||
setRate(4); // 1khz / (1 + 4) = 200 Hz
|
||||
|
||||
DEBUG_PRINTLN(F("Setting external frame sync to TEMP_OUT_L[0]..."));
|
||||
setExternalFrameSync(MPU6050_EXT_SYNC_TEMP_OUT_L);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting DLPF bandwidth to 42Hz..."));
|
||||
setDLPFMode(MPU6050_DLPF_BW_42);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting gyro sensitivity to +/- 2000 deg/sec..."));
|
||||
setFullScaleGyroRange(MPU6050_GYRO_FS_2000);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting DMP programm start address"));
|
||||
//write start address MSB into register
|
||||
setDMPConfig1(0x03);
|
||||
//write start address LSB into register
|
||||
setDMPConfig2(0x00);
|
||||
|
||||
DEBUG_PRINTLN(F("Clearing OTP Bank flag..."));
|
||||
setOTPBankValid(false);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting X/Y/Z gyro offset TCs to previous values..."));
|
||||
setXGyroOffsetTC(xgOffsetTC);
|
||||
setYGyroOffsetTC(ygOffsetTC);
|
||||
setZGyroOffsetTC(zgOffsetTC);
|
||||
|
||||
//DEBUG_PRINTLN(F("Setting X/Y/Z gyro user offsets to zero..."));
|
||||
//setXGyroOffset(0);
|
||||
//setYGyroOffset(0);
|
||||
//setZGyroOffset(0);
|
||||
|
||||
DEBUG_PRINTLN(F("Writing final memory update 1/7 (function unknown)..."));
|
||||
uint8_t dmpUpdate[16], j;
|
||||
uint16_t pos = 0;
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
|
||||
DEBUG_PRINTLN(F("Writing final memory update 2/7 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
|
||||
DEBUG_PRINTLN(F("Resetting FIFO..."));
|
||||
resetFIFO();
|
||||
|
||||
DEBUG_PRINTLN(F("Reading FIFO count..."));
|
||||
uint16_t fifoCount = getFIFOCount();
|
||||
uint8_t fifoBuffer[128];
|
||||
|
||||
DEBUG_PRINT(F("Current FIFO count="));
|
||||
DEBUG_PRINTLN(fifoCount);
|
||||
getFIFOBytes(fifoBuffer, fifoCount);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting motion detection threshold to 2..."));
|
||||
setMotionDetectionThreshold(2);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting zero-motion detection threshold to 156..."));
|
||||
setZeroMotionDetectionThreshold(156);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting motion detection duration to 80..."));
|
||||
setMotionDetectionDuration(80);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting zero-motion detection duration to 0..."));
|
||||
setZeroMotionDetectionDuration(0);
|
||||
|
||||
DEBUG_PRINTLN(F("Resetting FIFO..."));
|
||||
resetFIFO();
|
||||
|
||||
DEBUG_PRINTLN(F("Enabling FIFO..."));
|
||||
setFIFOEnabled(true);
|
||||
|
||||
DEBUG_PRINTLN(F("Enabling DMP..."));
|
||||
setDMPEnabled(true);
|
||||
|
||||
DEBUG_PRINTLN(F("Resetting DMP..."));
|
||||
resetDMP();
|
||||
|
||||
DEBUG_PRINTLN(F("Writing final memory update 3/7 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
|
||||
DEBUG_PRINTLN(F("Writing final memory update 4/7 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
|
||||
DEBUG_PRINTLN(F("Writing final memory update 5/7 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
|
||||
DEBUG_PRINTLN(F("Waiting for FIFO count > 2..."));
|
||||
while ((fifoCount = getFIFOCount()) < 3);
|
||||
|
||||
DEBUG_PRINT(F("Current FIFO count="));
|
||||
DEBUG_PRINTLN(fifoCount);
|
||||
DEBUG_PRINTLN(F("Reading FIFO data..."));
|
||||
getFIFOBytes(fifoBuffer, fifoCount);
|
||||
|
||||
DEBUG_PRINTLN(F("Reading interrupt status..."));
|
||||
|
||||
DEBUG_PRINT(F("Current interrupt status="));
|
||||
DEBUG_PRINTLNF(getIntStatus(), HEX);
|
||||
|
||||
DEBUG_PRINTLN(F("Reading final memory update 6/7 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
readMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
|
||||
DEBUG_PRINTLN(F("Waiting for FIFO count > 2..."));
|
||||
while ((fifoCount = getFIFOCount()) < 3);
|
||||
|
||||
DEBUG_PRINT(F("Current FIFO count="));
|
||||
DEBUG_PRINTLN(fifoCount);
|
||||
|
||||
DEBUG_PRINTLN(F("Reading FIFO data..."));
|
||||
getFIFOBytes(fifoBuffer, fifoCount);
|
||||
|
||||
DEBUG_PRINTLN(F("Reading interrupt status..."));
|
||||
|
||||
DEBUG_PRINT(F("Current interrupt status="));
|
||||
DEBUG_PRINTLNF(getIntStatus(), HEX);
|
||||
|
||||
DEBUG_PRINTLN(F("Writing final memory update 7/7 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
|
||||
DEBUG_PRINTLN(F("DMP is good to go! Finally."));
|
||||
|
||||
DEBUG_PRINTLN(F("Disabling DMP (you turn it on later)..."));
|
||||
setDMPEnabled(false);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting up internal 42-byte (default) DMP packet buffer..."));
|
||||
dmpPacketSize = 42;
|
||||
/*if ((dmpPacketBuffer = (uint8_t *)malloc(42)) == 0) {
|
||||
return 3; // TODO: proper error code for no memory
|
||||
}*/
|
||||
|
||||
DEBUG_PRINTLN(F("Resetting FIFO and clearing INT status one last time..."));
|
||||
resetFIFO();
|
||||
getIntStatus();
|
||||
} else {
|
||||
DEBUG_PRINTLN(F("ERROR! DMP configuration verification failed."));
|
||||
return 2; // configuration block loading failed
|
||||
}
|
||||
} else {
|
||||
DEBUG_PRINTLN(F("ERROR! DMP code verification failed."));
|
||||
return 1; // main binary block loading failed
|
||||
}
|
||||
return 0; // success
|
||||
}
|
||||
|
||||
bool MPU6050::dmpPacketAvailable() {
|
||||
return getFIFOCount() >= dmpGetFIFOPacketSize();
|
||||
}
|
||||
|
||||
// uint8_t MPU6050::dmpSetFIFORate(uint8_t fifoRate);
|
||||
// uint8_t MPU6050::dmpGetFIFORate();
|
||||
// uint8_t MPU6050::dmpGetSampleStepSizeMS();
|
||||
// uint8_t MPU6050::dmpGetSampleFrequency();
|
||||
// int32_t MPU6050::dmpDecodeTemperature(int8_t tempReg);
|
||||
|
||||
//uint8_t MPU6050::dmpRegisterFIFORateProcess(inv_obj_func func, int16_t priority);
|
||||
//uint8_t MPU6050::dmpUnregisterFIFORateProcess(inv_obj_func func);
|
||||
//uint8_t MPU6050::dmpRunFIFORateProcesses();
|
||||
|
||||
// uint8_t MPU6050::dmpSendQuaternion(uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendGyro(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendAccel(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendLinearAccel(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendLinearAccelInWorld(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendControlData(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendSensorData(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendExternalSensorData(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendGravity(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendPacketNumber(uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendQuantizedAccel(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendEIS(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
|
||||
uint8_t MPU6050::dmpGetAccel(int32_t *data, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
if (packet == 0) packet = dmpPacketBuffer;
|
||||
data[0] = (((uint32_t)packet[28] << 24) | ((uint32_t)packet[29] << 16) | ((uint32_t)packet[30] << 8) | packet[31]);
|
||||
data[1] = (((uint32_t)packet[32] << 24) | ((uint32_t)packet[33] << 16) | ((uint32_t)packet[34] << 8) | packet[35]);
|
||||
data[2] = (((uint32_t)packet[36] << 24) | ((uint32_t)packet[37] << 16) | ((uint32_t)packet[38] << 8) | packet[39]);
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpGetAccel(int16_t *data, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
if (packet == 0) packet = dmpPacketBuffer;
|
||||
data[0] = (packet[28] << 8) | packet[29];
|
||||
data[1] = (packet[32] << 8) | packet[33];
|
||||
data[2] = (packet[36] << 8) | packet[37];
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpGetAccel(VectorInt16 *v, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
if (packet == 0) packet = dmpPacketBuffer;
|
||||
v -> x = (packet[28] << 8) | packet[29];
|
||||
v -> y = (packet[32] << 8) | packet[33];
|
||||
v -> z = (packet[36] << 8) | packet[37];
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpGetQuaternion(int32_t *data, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
if (packet == 0) packet = dmpPacketBuffer;
|
||||
data[0] = (((uint32_t)packet[0] << 24) | ((uint32_t)packet[1] << 16) | ((uint32_t)packet[2] << 8) | packet[3]);
|
||||
data[1] = (((uint32_t)packet[4] << 24) | ((uint32_t)packet[5] << 16) | ((uint32_t)packet[6] << 8) | packet[7]);
|
||||
data[2] = (((uint32_t)packet[8] << 24) | ((uint32_t)packet[9] << 16) | ((uint32_t)packet[10] << 8) | packet[11]);
|
||||
data[3] = (((uint32_t)packet[12] << 24) | ((uint32_t)packet[13] << 16) | ((uint32_t)packet[14] << 8) | packet[15]);
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpGetQuaternion(int16_t *data, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
if (packet == 0) packet = dmpPacketBuffer;
|
||||
data[0] = ((packet[0] << 8) | packet[1]);
|
||||
data[1] = ((packet[4] << 8) | packet[5]);
|
||||
data[2] = ((packet[8] << 8) | packet[9]);
|
||||
data[3] = ((packet[12] << 8) | packet[13]);
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpGetQuaternion(Quaternion *q, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
int16_t qI[4];
|
||||
uint8_t status = dmpGetQuaternion(qI, packet);
|
||||
if (status == 0) {
|
||||
q -> w = (float)qI[0] / 16384.0f;
|
||||
q -> x = (float)qI[1] / 16384.0f;
|
||||
q -> y = (float)qI[2] / 16384.0f;
|
||||
q -> z = (float)qI[3] / 16384.0f;
|
||||
return 0;
|
||||
}
|
||||
return status; // int16 return value, indicates error if this line is reached
|
||||
}
|
||||
// uint8_t MPU6050::dmpGet6AxisQuaternion(long *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetRelativeQuaternion(long *data, const uint8_t* packet);
|
||||
uint8_t MPU6050::dmpGetGyro(int32_t *data, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
if (packet == 0) packet = dmpPacketBuffer;
|
||||
data[0] = (((uint32_t)packet[16] << 24) | ((uint32_t)packet[17] << 16) | ((uint32_t)packet[18] << 8) | packet[19]);
|
||||
data[1] = (((uint32_t)packet[20] << 24) | ((uint32_t)packet[21] << 16) | ((uint32_t)packet[22] << 8) | packet[23]);
|
||||
data[2] = (((uint32_t)packet[24] << 24) | ((uint32_t)packet[25] << 16) | ((uint32_t)packet[26] << 8) | packet[27]);
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpGetGyro(int16_t *data, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
if (packet == 0) packet = dmpPacketBuffer;
|
||||
data[0] = (packet[16] << 8) | packet[17];
|
||||
data[1] = (packet[20] << 8) | packet[21];
|
||||
data[2] = (packet[24] << 8) | packet[25];
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpGetGyro(VectorInt16 *v, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
if (packet == 0) packet = dmpPacketBuffer;
|
||||
v -> x = (packet[16] << 8) | packet[17];
|
||||
v -> y = (packet[20] << 8) | packet[21];
|
||||
v -> z = (packet[24] << 8) | packet[25];
|
||||
return 0;
|
||||
}
|
||||
// uint8_t MPU6050::dmpSetLinearAccelFilterCoefficient(float coef);
|
||||
// uint8_t MPU6050::dmpGetLinearAccel(long *data, const uint8_t* packet);
|
||||
uint8_t MPU6050::dmpGetLinearAccel(VectorInt16 *v, VectorInt16 *vRaw, VectorFloat *gravity) {
|
||||
// get rid of the gravity component (+1g = +8192 in standard DMP FIFO packet, sensitivity is 2g)
|
||||
v -> x = vRaw -> x - gravity -> x*8192;
|
||||
v -> y = vRaw -> y - gravity -> y*8192;
|
||||
v -> z = vRaw -> z - gravity -> z*8192;
|
||||
return 0;
|
||||
}
|
||||
// uint8_t MPU6050::dmpGetLinearAccelInWorld(long *data, const uint8_t* packet);
|
||||
uint8_t MPU6050::dmpGetLinearAccelInWorld(VectorInt16 *v, VectorInt16 *vReal, Quaternion *q) {
|
||||
// rotate measured 3D acceleration vector into original state
|
||||
// frame of reference based on orientation quaternion
|
||||
memcpy(v, vReal, sizeof(VectorInt16));
|
||||
v -> rotate(q);
|
||||
return 0;
|
||||
}
|
||||
// uint8_t MPU6050::dmpGetGyroAndAccelSensor(long *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetGyroSensor(long *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetControlData(long *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetTemperature(long *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetGravity(long *data, const uint8_t* packet);
|
||||
uint8_t MPU6050::dmpGetGravity(VectorFloat *v, Quaternion *q) {
|
||||
v -> x = 2 * (q -> x*q -> z - q -> w*q -> y);
|
||||
v -> y = 2 * (q -> w*q -> x + q -> y*q -> z);
|
||||
v -> z = q -> w*q -> w - q -> x*q -> x - q -> y*q -> y + q -> z*q -> z;
|
||||
return 0;
|
||||
}
|
||||
// uint8_t MPU6050::dmpGetUnquantizedAccel(long *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetQuantizedAccel(long *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetExternalSensorData(long *data, int size, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetEIS(long *data, const uint8_t* packet);
|
||||
|
||||
uint8_t MPU6050::dmpGetEuler(float *data, Quaternion *q) {
|
||||
data[0] = atan2(2*q -> x*q -> y - 2*q -> w*q -> z, 2*q -> w*q -> w + 2*q -> x*q -> x - 1); // psi
|
||||
data[1] = -asin(2*q -> x*q -> z + 2*q -> w*q -> y); // theta
|
||||
data[2] = atan2(2*q -> y*q -> z - 2*q -> w*q -> x, 2*q -> w*q -> w + 2*q -> z*q -> z - 1); // phi
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpGetYawPitchRoll(float *data, Quaternion *q, VectorFloat *gravity) {
|
||||
// yaw: (about Z axis)
|
||||
data[0] = atan2(2*q -> x*q -> y - 2*q -> w*q -> z, 2*q -> w*q -> w + 2*q -> x*q -> x - 1);
|
||||
// pitch: (nose up/down, about Y axis)
|
||||
data[1] = atan(gravity -> x / sqrt(gravity -> y*gravity -> y + gravity -> z*gravity -> z));
|
||||
// roll: (tilt left/right, about X axis)
|
||||
data[2] = atan(gravity -> y / sqrt(gravity -> x*gravity -> x + gravity -> z*gravity -> z));
|
||||
return 0;
|
||||
}
|
||||
|
||||
// uint8_t MPU6050::dmpGetAccelFloat(float *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetQuaternionFloat(float *data, const uint8_t* packet);
|
||||
|
||||
uint8_t MPU6050::dmpProcessFIFOPacket(const unsigned char *dmpData) {
|
||||
/*for (uint8_t k = 0; k < dmpPacketSize; k++) {
|
||||
if (dmpData[k] < 0x10) Serial.print("0");
|
||||
Serial.print(dmpData[k], HEX);
|
||||
Serial.print(" ");
|
||||
}
|
||||
Serial.print("\n");*/
|
||||
//Serial.println((uint16_t)dmpPacketBuffer);
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpReadAndProcessFIFOPacket(uint8_t numPackets, uint8_t *processed) {
|
||||
uint8_t status;
|
||||
uint8_t buf[dmpPacketSize];
|
||||
for (uint8_t i = 0; i < numPackets; i++) {
|
||||
// read packet from FIFO
|
||||
getFIFOBytes(buf, dmpPacketSize);
|
||||
|
||||
// process packet
|
||||
if ((status = dmpProcessFIFOPacket(buf)) > 0) return status;
|
||||
|
||||
// increment external process count variable, if supplied
|
||||
if (processed != 0) (*processed)++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// uint8_t MPU6050::dmpSetFIFOProcessedCallback(void (*func) (void));
|
||||
|
||||
// uint8_t MPU6050::dmpInitFIFOParam();
|
||||
// uint8_t MPU6050::dmpCloseFIFO();
|
||||
// uint8_t MPU6050::dmpSetGyroDataSource(uint_fast8_t source);
|
||||
// uint8_t MPU6050::dmpDecodeQuantizedAccel();
|
||||
// uint32_t MPU6050::dmpGetGyroSumOfSquare();
|
||||
// uint32_t MPU6050::dmpGetAccelSumOfSquare();
|
||||
// void MPU6050::dmpOverrideQuaternion(long *q);
|
||||
uint16_t MPU6050::dmpGetFIFOPacketSize() {
|
||||
return dmpPacketSize;
|
||||
}
|
||||
|
||||
#endif /* _MPU6050_6AXIS_MOTIONAPPS20_H_ */
|
||||
852
arduino-cli/libraries/MPU6050/MPU6050_9Axis_MotionApps41.h
Normal file
852
arduino-cli/libraries/MPU6050/MPU6050_9Axis_MotionApps41.h
Normal file
@@ -0,0 +1,852 @@
|
||||
// I2Cdev library collection - MPU6050 I2C device class, 9-axis MotionApps 4.1 implementation
|
||||
// Based on InvenSense MPU-6050 register map document rev. 2.0, 5/19/2011 (RM-MPU-6000A-00)
|
||||
// 6/18/2012 by Jeff Rowberg <jeff@rowberg.net>
|
||||
// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
|
||||
//
|
||||
// Changelog:
|
||||
// ... - ongoing debug release
|
||||
|
||||
/* ============================================
|
||||
I2Cdev device library code is placed under the MIT license
|
||||
Copyright (c) 2012 Jeff Rowberg
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
===============================================
|
||||
*/
|
||||
|
||||
#ifndef _MPU6050_9AXIS_MOTIONAPPS41_H_
|
||||
#define _MPU6050_9AXIS_MOTIONAPPS41_H_
|
||||
|
||||
#include "I2Cdev.h"
|
||||
#include "helper_3dmath.h"
|
||||
|
||||
// MotionApps 4.1 DMP implementation, built using the MPU-9150 "MotionFit" board
|
||||
#define MPU6050_INCLUDE_DMP_MOTIONAPPS41
|
||||
|
||||
#include "MPU6050.h"
|
||||
|
||||
// Tom Carpenter's conditional PROGMEM code
|
||||
// http://forum.arduino.cc/index.php?topic=129407.0
|
||||
#ifdef __AVR__
|
||||
#include <avr/pgmspace.h>
|
||||
#else
|
||||
// Teensy 3.0 library conditional PROGMEM code from Paul Stoffregen
|
||||
#ifndef __PGMSPACE_H_
|
||||
#define __PGMSPACE_H_ 1
|
||||
#include <inttypes.h>
|
||||
|
||||
#define PROGMEM
|
||||
#define PGM_P const char *
|
||||
#define PSTR(str) (str)
|
||||
#define F(x) x
|
||||
|
||||
typedef void prog_void;
|
||||
typedef char prog_char;
|
||||
//typedef unsigned char prog_uchar;
|
||||
typedef int8_t prog_int8_t;
|
||||
typedef uint8_t prog_uint8_t;
|
||||
typedef int16_t prog_int16_t;
|
||||
typedef uint16_t prog_uint16_t;
|
||||
typedef int32_t prog_int32_t;
|
||||
typedef uint32_t prog_uint32_t;
|
||||
|
||||
#define strcpy_P(dest, src) strcpy((dest), (src))
|
||||
#define strcat_P(dest, src) strcat((dest), (src))
|
||||
#define strcmp_P(a, b) strcmp((a), (b))
|
||||
|
||||
#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
|
||||
#define pgm_read_word(addr) (*(const unsigned short *)(addr))
|
||||
#define pgm_read_dword(addr) (*(const unsigned long *)(addr))
|
||||
#define pgm_read_float(addr) (*(const float *)(addr))
|
||||
|
||||
#define pgm_read_byte_near(addr) pgm_read_byte(addr)
|
||||
#define pgm_read_word_near(addr) pgm_read_word(addr)
|
||||
#define pgm_read_dword_near(addr) pgm_read_dword(addr)
|
||||
#define pgm_read_float_near(addr) pgm_read_float(addr)
|
||||
#define pgm_read_byte_far(addr) pgm_read_byte(addr)
|
||||
#define pgm_read_word_far(addr) pgm_read_word(addr)
|
||||
#define pgm_read_dword_far(addr) pgm_read_dword(addr)
|
||||
#define pgm_read_float_far(addr) pgm_read_float(addr)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// NOTE! Enabling DEBUG adds about 3.3kB to the flash program size.
|
||||
// Debug output is now working even on ATMega328P MCUs (e.g. Arduino Uno)
|
||||
// after moving string constants to flash memory storage using the F()
|
||||
// compiler macro (Arduino IDE 1.0+ required).
|
||||
|
||||
//#define DEBUG
|
||||
#ifdef DEBUG
|
||||
#define DEBUG_PRINT(x) Serial.print(x)
|
||||
#define DEBUG_PRINTF(x, y) Serial.print(x, y)
|
||||
#define DEBUG_PRINTLN(x) Serial.println(x)
|
||||
#define DEBUG_PRINTLNF(x, y) Serial.println(x, y)
|
||||
#else
|
||||
#define DEBUG_PRINT(x)
|
||||
#define DEBUG_PRINTF(x, y)
|
||||
#define DEBUG_PRINTLN(x)
|
||||
#define DEBUG_PRINTLNF(x, y)
|
||||
#endif
|
||||
|
||||
#define MPU6050_DMP_CODE_SIZE 1962 // dmpMemory[]
|
||||
#define MPU6050_DMP_CONFIG_SIZE 232 // dmpConfig[]
|
||||
#define MPU6050_DMP_UPDATES_SIZE 140 // dmpUpdates[]
|
||||
|
||||
/* ================================================================================================ *
|
||||
| Default MotionApps v4.1 48-byte FIFO packet structure: |
|
||||
| |
|
||||
| [QUAT W][ ][QUAT X][ ][QUAT Y][ ][QUAT Z][ ][GYRO X][ ][GYRO Y][ ] |
|
||||
| 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
||||
| |
|
||||
| [GYRO Z][ ][MAG X ][MAG Y ][MAG Z ][ACC X ][ ][ACC Y ][ ][ACC Z ][ ][ ] |
|
||||
| 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
||||
* ================================================================================================ */
|
||||
|
||||
// this block of memory gets written to the MPU on start-up, and it seems
|
||||
// to be volatile memory, so it has to be done each time (it only takes ~1
|
||||
// second though)
|
||||
const unsigned char dmpMemory[MPU6050_DMP_CODE_SIZE] PROGMEM = {
|
||||
// bank 0, 256 bytes
|
||||
0xFB, 0x00, 0x00, 0x3E, 0x00, 0x0B, 0x00, 0x36, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00,
|
||||
0x00, 0x65, 0x00, 0x54, 0xFF, 0xEF, 0x00, 0x00, 0xFA, 0x80, 0x00, 0x0B, 0x12, 0x82, 0x00, 0x01,
|
||||
0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x28, 0x00, 0x00, 0xFF, 0xFF, 0x45, 0x81, 0xFF, 0xFF, 0xFA, 0x72, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x03, 0xE8, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x7F, 0xFF, 0xFF, 0xFE, 0x80, 0x01,
|
||||
0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x3E, 0x03, 0x30, 0x40, 0x00, 0x00, 0x00, 0x02, 0xCA, 0xE3, 0x09, 0x3E, 0x80, 0x00, 0x00,
|
||||
0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00,
|
||||
0x41, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x0B, 0x2A, 0x00, 0x00, 0x16, 0x55, 0x00, 0x00, 0x21, 0x82,
|
||||
0xFD, 0x87, 0x26, 0x50, 0xFD, 0x80, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x05, 0x80, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
|
||||
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x6F, 0x00, 0x02, 0x65, 0x32, 0x00, 0x00, 0x5E, 0xC0,
|
||||
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xFB, 0x8C, 0x6F, 0x5D, 0xFD, 0x5D, 0x08, 0xD9, 0x00, 0x7C, 0x73, 0x3B, 0x00, 0x6C, 0x12, 0xCC,
|
||||
0x32, 0x00, 0x13, 0x9D, 0x32, 0x00, 0xD0, 0xD6, 0x32, 0x00, 0x08, 0x00, 0x40, 0x00, 0x01, 0xF4,
|
||||
0xFF, 0xE6, 0x80, 0x79, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD0, 0xD6, 0x00, 0x00, 0x27, 0x10,
|
||||
|
||||
// bank 1, 256 bytes
|
||||
0xFB, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0xFA, 0x36, 0xFF, 0xBC, 0x30, 0x8E, 0x00, 0x05, 0xFB, 0xF0, 0xFF, 0xD9, 0x5B, 0xC8,
|
||||
0xFF, 0xD0, 0x9A, 0xBE, 0x00, 0x00, 0x10, 0xA9, 0xFF, 0xF4, 0x1E, 0xB2, 0x00, 0xCE, 0xBB, 0xF7,
|
||||
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x02, 0x00, 0x02, 0x02, 0x00, 0x00, 0x0C,
|
||||
0xFF, 0xC2, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0xCF, 0x80, 0x00, 0x40, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x14,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x03, 0x3F, 0x68, 0xB6, 0x79, 0x35, 0x28, 0xBC, 0xC6, 0x7E, 0xD1, 0x6C,
|
||||
0x80, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB2, 0x6A, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xF0, 0x00, 0x00, 0x00, 0x30,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x25, 0x4D, 0x00, 0x2F, 0x70, 0x6D, 0x00, 0x00, 0x05, 0xAE, 0x00, 0x0C, 0x02, 0xD0,
|
||||
|
||||
// bank 2, 256 bytes
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x54, 0xFF, 0xEF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x01, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x01, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0xFF, 0xEF, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
|
||||
0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x78, 0xA2,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x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xA3, 0x29, 0x83, 0xDA,
|
||||
0x2C, 0x0E, 0xD8, 0xA3, 0x84, 0x49, 0x83, 0xDA, 0x2C, 0x4C, 0x0E, 0xD8, 0xB8, 0xB0, 0x97, 0x86,
|
||||
0xA8, 0x31, 0x9B, 0x06, 0x99, 0x07, 0xAB, 0x97, 0x28, 0x88, 0x9B, 0xF0, 0x0C, 0x20, 0x14, 0x40,
|
||||
0xB9, 0xA3, 0x8A, 0xC3, 0xC5, 0xC7, 0x9A, 0xA3, 0x28, 0x50, 0x78, 0xF1, 0xB5, 0x93, 0x01, 0xD9,
|
||||
0xDF, 0xDF, 0xDF, 0xD8, 0xB8, 0xB4, 0xA8, 0x8C, 0x9C, 0xF0, 0x04, 0x28, 0x51, 0x79, 0x1D, 0x30,
|
||||
0x14, 0x38, 0xB2, 0x82, 0xAB, 0xD0, 0x98, 0x2C, 0x50, 0x50, 0x78, 0x78, 0x9B, 0xF1, 0x1A, 0xB0,
|
||||
0xF0, 0xB1, 0x83, 0x9C, 0xA8, 0x29, 0x51, 0x79, 0xB0, 0x8B, 0x29, 0x51, 0x79, 0xB1, 0x83, 0x24,
|
||||
|
||||
// bank 6, 256 bytes
|
||||
0x70, 0x59, 0xB0, 0x8B, 0x20, 0x58, 0x71, 0xB1, 0x83, 0x44, 0x69, 0x38, 0xB0, 0x8B, 0x39, 0x40,
|
||||
0x68, 0xB1, 0x83, 0x64, 0x48, 0x31, 0xB0, 0x8B, 0x30, 0x49, 0x60, 0xA5, 0x88, 0x20, 0x09, 0x71,
|
||||
0x58, 0x44, 0x68, 0x11, 0x39, 0x64, 0x49, 0x30, 0x19, 0xF1, 0xAC, 0x00, 0x2C, 0x54, 0x7C, 0xF0,
|
||||
0x8C, 0xA8, 0x04, 0x28, 0x50, 0x78, 0xF1, 0x88, 0x97, 0x26, 0xA8, 0x59, 0x98, 0xAC, 0x8C, 0x02,
|
||||
0x26, 0x46, 0x66, 0xF0, 0x89, 0x9C, 0xA8, 0x29, 0x51, 0x79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0xF3, 0x9B, 0xA3, 0xA3,
|
||||
0xDC, 0xB9, 0xA7, 0xF1, 0x26, 0x26, 0x26, 0xD8, 0xD8, 0xFF
|
||||
};
|
||||
|
||||
const unsigned char dmpConfig[MPU6050_DMP_CONFIG_SIZE] PROGMEM = {
|
||||
// BANK OFFSET LENGTH [DATA]
|
||||
0x02, 0xEC, 0x04, 0x00, 0x47, 0x7D, 0x1A, // ?
|
||||
0x03, 0x82, 0x03, 0x4C, 0xCD, 0x6C, // FCFG_1 inv_set_gyro_calibration
|
||||
0x03, 0xB2, 0x03, 0x36, 0x56, 0x76, // FCFG_3 inv_set_gyro_calibration
|
||||
0x00, 0x68, 0x04, 0x02, 0xCA, 0xE3, 0x09, // D_0_104 inv_set_gyro_calibration
|
||||
0x01, 0x0C, 0x04, 0x00, 0x00, 0x00, 0x00, // D_1_152 inv_set_accel_calibration
|
||||
0x03, 0x86, 0x03, 0x0C, 0xC9, 0x2C, // FCFG_2 inv_set_accel_calibration
|
||||
0x03, 0x90, 0x03, 0x26, 0x46, 0x66, // (continued)...FCFG_2 inv_set_accel_calibration
|
||||
0x00, 0x6C, 0x02, 0x40, 0x00, // D_0_108 inv_set_accel_calibration
|
||||
|
||||
0x02, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_00 inv_set_compass_calibration
|
||||
0x02, 0x44, 0x04, 0x40, 0x00, 0x00, 0x00, // CPASS_MTX_01
|
||||
0x02, 0x48, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_02
|
||||
0x02, 0x4C, 0x04, 0x40, 0x00, 0x00, 0x00, // CPASS_MTX_10
|
||||
0x02, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_11
|
||||
0x02, 0x54, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_12
|
||||
0x02, 0x58, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_20
|
||||
0x02, 0x5C, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_21
|
||||
0x02, 0xBC, 0x04, 0xC0, 0x00, 0x00, 0x00, // CPASS_MTX_22
|
||||
|
||||
0x01, 0xEC, 0x04, 0x00, 0x00, 0x40, 0x00, // D_1_236 inv_apply_endian_accel
|
||||
0x03, 0x86, 0x06, 0x0C, 0xC9, 0x2C, 0x97, 0x97, 0x97, // FCFG_2 inv_set_mpu_sensors
|
||||
0x04, 0x22, 0x03, 0x0D, 0x35, 0x5D, // CFG_MOTION_BIAS inv_turn_on_bias_from_no_motion
|
||||
0x00, 0xA3, 0x01, 0x00, // ?
|
||||
0x04, 0x29, 0x04, 0x87, 0x2D, 0x35, 0x3D, // FCFG_5 inv_set_bias_update
|
||||
0x07, 0x62, 0x05, 0xF1, 0x20, 0x28, 0x30, 0x38, // CFG_8 inv_send_quaternion
|
||||
0x07, 0x9F, 0x01, 0x30, // CFG_16 inv_set_footer
|
||||
0x07, 0x67, 0x01, 0x9A, // CFG_GYRO_SOURCE inv_send_gyro
|
||||
0x07, 0x68, 0x04, 0xF1, 0x28, 0x30, 0x38, // CFG_9 inv_send_gyro -> inv_construct3_fifo
|
||||
0x07, 0x62, 0x05, 0xF1, 0x20, 0x28, 0x30, 0x38, // ?
|
||||
0x02, 0x0C, 0x04, 0x00, 0x00, 0x00, 0x00, // ?
|
||||
0x07, 0x83, 0x06, 0xC2, 0xCA, 0xC4, 0xA3, 0xA3, 0xA3, // ?
|
||||
// SPECIAL 0x01 = enable interrupts
|
||||
0x00, 0x00, 0x00, 0x01, // SET INT_ENABLE, SPECIAL INSTRUCTION
|
||||
0x07, 0xA7, 0x01, 0xFE, // ?
|
||||
0x07, 0x62, 0x05, 0xF1, 0x20, 0x28, 0x30, 0x38, // ?
|
||||
0x07, 0x67, 0x01, 0x9A, // ?
|
||||
0x07, 0x68, 0x04, 0xF1, 0x28, 0x30, 0x38, // CFG_12 inv_send_accel -> inv_construct3_fifo
|
||||
0x07, 0x8D, 0x04, 0xF1, 0x28, 0x30, 0x38, // ??? CFG_12 inv_send_mag -> inv_construct3_fifo
|
||||
0x02, 0x16, 0x02, 0x00, 0x03 // D_0_22 inv_set_fifo_rate
|
||||
|
||||
// This very last 0x01 WAS a 0x09, which drops the FIFO rate down to 20 Hz. 0x07 is 25 Hz,
|
||||
// 0x01 is 100Hz. Going faster than 100Hz (0x00=200Hz) tends to result in very noisy data.
|
||||
// DMP output frequency is calculated easily using this equation: (200Hz / (1 + value))
|
||||
|
||||
// It is important to make sure the host processor can keep up with reading and processing
|
||||
// the FIFO output at the desired rate. Handling FIFO overflow cleanly is also a good idea.
|
||||
};
|
||||
|
||||
const unsigned char dmpUpdates[MPU6050_DMP_UPDATES_SIZE] PROGMEM = {
|
||||
0x01, 0xB2, 0x02, 0xFF, 0xF5,
|
||||
0x01, 0x90, 0x04, 0x0A, 0x0D, 0x97, 0xC0,
|
||||
0x00, 0xA3, 0x01, 0x00,
|
||||
0x04, 0x29, 0x04, 0x87, 0x2D, 0x35, 0x3D,
|
||||
0x01, 0x6A, 0x02, 0x06, 0x00,
|
||||
0x01, 0x60, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x60, 0x04, 0x40, 0x00, 0x00, 0x00,
|
||||
0x02, 0x60, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x01, 0x08, 0x02, 0x01, 0x20,
|
||||
0x01, 0x0A, 0x02, 0x00, 0x4E,
|
||||
0x01, 0x02, 0x02, 0xFE, 0xB3,
|
||||
0x02, 0x6C, 0x04, 0x00, 0x00, 0x00, 0x00, // READ
|
||||
0x02, 0x6C, 0x04, 0xFA, 0xFE, 0x00, 0x00,
|
||||
0x02, 0x60, 0x0C, 0xFF, 0xFF, 0xCB, 0x4D, 0x00, 0x01, 0x08, 0xC1, 0xFF, 0xFF, 0xBC, 0x2C,
|
||||
0x02, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00,
|
||||
0x02, 0xF8, 0x04, 0x00, 0x00, 0x00, 0x00,
|
||||
0x02, 0xFC, 0x04, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x60, 0x04, 0x40, 0x00, 0x00, 0x00,
|
||||
0x00, 0x60, 0x04, 0x00, 0x40, 0x00, 0x00
|
||||
};
|
||||
|
||||
uint8_t MPU6050::dmpInitialize() {
|
||||
// reset device
|
||||
DEBUG_PRINTLN(F("\n\nResetting MPU6050..."));
|
||||
reset();
|
||||
delay(30); // wait after reset
|
||||
|
||||
// disable sleep mode
|
||||
DEBUG_PRINTLN(F("Disabling sleep mode..."));
|
||||
setSleepEnabled(false);
|
||||
|
||||
// get MPU product ID
|
||||
DEBUG_PRINTLN(F("Getting product ID..."));
|
||||
//uint8_t productID = 0; //getProductID();
|
||||
DEBUG_PRINT(F("Product ID = "));
|
||||
DEBUG_PRINT(productID);
|
||||
|
||||
// get MPU hardware revision
|
||||
DEBUG_PRINTLN(F("Selecting user bank 16..."));
|
||||
setMemoryBank(0x10, true, true);
|
||||
DEBUG_PRINTLN(F("Selecting memory byte 6..."));
|
||||
setMemoryStartAddress(0x06);
|
||||
DEBUG_PRINTLN(F("Checking hardware revision..."));
|
||||
uint8_t hwRevision = readMemoryByte();
|
||||
DEBUG_PRINT(F("Revision @ user[16][6] = "));
|
||||
DEBUG_PRINTLNF(hwRevision, HEX);
|
||||
DEBUG_PRINTLN(F("Resetting memory bank selection to 0..."));
|
||||
setMemoryBank(0, false, false);
|
||||
|
||||
// check OTP bank valid
|
||||
DEBUG_PRINTLN(F("Reading OTP bank valid flag..."));
|
||||
uint8_t otpValid = getOTPBankValid();
|
||||
DEBUG_PRINT(F("OTP bank is "));
|
||||
DEBUG_PRINTLN(otpValid ? F("valid!") : F("invalid!"));
|
||||
|
||||
// get X/Y/Z gyro offsets
|
||||
DEBUG_PRINTLN(F("Reading gyro offset values..."));
|
||||
int8_t xgOffset = getXGyroOffset();
|
||||
int8_t ygOffset = getYGyroOffset();
|
||||
int8_t zgOffset = getZGyroOffset();
|
||||
DEBUG_PRINT(F("X gyro offset = "));
|
||||
DEBUG_PRINTLN(xgOffset);
|
||||
DEBUG_PRINT(F("Y gyro offset = "));
|
||||
DEBUG_PRINTLN(ygOffset);
|
||||
DEBUG_PRINT(F("Z gyro offset = "));
|
||||
DEBUG_PRINTLN(zgOffset);
|
||||
|
||||
I2Cdev::readByte(devAddr, MPU6050_RA_USER_CTRL, buffer); // ?
|
||||
|
||||
DEBUG_PRINTLN(F("Enabling interrupt latch, clear on any read, AUX bypass enabled"));
|
||||
I2Cdev::writeByte(devAddr, MPU6050_RA_INT_PIN_CFG, 0x32);
|
||||
|
||||
// enable MPU AUX I2C bypass mode
|
||||
//DEBUG_PRINTLN(F("Enabling AUX I2C bypass mode..."));
|
||||
//setI2CBypassEnabled(true);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting magnetometer mode to power-down..."));
|
||||
//mag -> setMode(0);
|
||||
I2Cdev::writeByte(0x0E, 0x0A, 0x00);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting magnetometer mode to fuse access..."));
|
||||
//mag -> setMode(0x0F);
|
||||
I2Cdev::writeByte(0x0E, 0x0A, 0x0F);
|
||||
|
||||
DEBUG_PRINTLN(F("Reading mag magnetometer factory calibration..."));
|
||||
int8_t asax, asay, asaz;
|
||||
//mag -> getAdjustment(&asax, &asay, &asaz);
|
||||
I2Cdev::readBytes(0x0E, 0x10, 3, buffer);
|
||||
asax = (int8_t)buffer[0];
|
||||
asay = (int8_t)buffer[1];
|
||||
asaz = (int8_t)buffer[2];
|
||||
DEBUG_PRINT(F("Adjustment X/Y/Z = "));
|
||||
DEBUG_PRINT(asax);
|
||||
DEBUG_PRINT(F(" / "));
|
||||
DEBUG_PRINT(asay);
|
||||
DEBUG_PRINT(F(" / "));
|
||||
DEBUG_PRINTLN(asaz);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting magnetometer mode to power-down..."));
|
||||
//mag -> setMode(0);
|
||||
I2Cdev::writeByte(0x0E, 0x0A, 0x00);
|
||||
|
||||
// load DMP code into memory banks
|
||||
DEBUG_PRINT(F("Writing DMP code to MPU memory banks ("));
|
||||
DEBUG_PRINT(MPU6050_DMP_CODE_SIZE);
|
||||
DEBUG_PRINTLN(F(" bytes)"));
|
||||
if (writeProgMemoryBlock(dmpMemory, MPU6050_DMP_CODE_SIZE)) {
|
||||
DEBUG_PRINTLN(F("Success! DMP code written and verified."));
|
||||
|
||||
DEBUG_PRINTLN(F("Configuring DMP and related settings..."));
|
||||
|
||||
// write DMP configuration
|
||||
DEBUG_PRINT(F("Writing DMP configuration to MPU memory banks ("));
|
||||
DEBUG_PRINT(MPU6050_DMP_CONFIG_SIZE);
|
||||
DEBUG_PRINTLN(F(" bytes in config def)"));
|
||||
if (writeProgDMPConfigurationSet(dmpConfig, MPU6050_DMP_CONFIG_SIZE)) {
|
||||
DEBUG_PRINTLN(F("Success! DMP configuration written and verified."));
|
||||
|
||||
DEBUG_PRINTLN(F("Setting DMP and FIFO_OFLOW interrupts enabled..."));
|
||||
setIntEnabled(0x12);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting sample rate to 200Hz..."));
|
||||
setRate(4); // 1khz / (1 + 4) = 200 Hz
|
||||
|
||||
DEBUG_PRINTLN(F("Setting clock source to Z Gyro..."));
|
||||
setClockSource(MPU6050_CLOCK_PLL_ZGYRO);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting DLPF bandwidth to 42Hz..."));
|
||||
setDLPFMode(MPU6050_DLPF_BW_42);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting external frame sync to TEMP_OUT_L[0]..."));
|
||||
setExternalFrameSync(MPU6050_EXT_SYNC_TEMP_OUT_L);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting gyro sensitivity to +/- 2000 deg/sec..."));
|
||||
setFullScaleGyroRange(MPU6050_GYRO_FS_2000);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting DMP configuration bytes (function unknown)..."));
|
||||
setDMPConfig1(0x03);
|
||||
setDMPConfig2(0x00);
|
||||
|
||||
DEBUG_PRINTLN(F("Clearing OTP Bank flag..."));
|
||||
setOTPBankValid(false);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting X/Y/Z gyro offsets to previous values..."));
|
||||
setXGyroOffsetTC(xgOffset);
|
||||
setYGyroOffsetTC(ygOffset);
|
||||
setZGyroOffsetTC(zgOffset);
|
||||
|
||||
//DEBUG_PRINTLN(F("Setting X/Y/Z gyro user offsets to zero..."));
|
||||
//setXGyroOffset(0);
|
||||
//setYGyroOffset(0);
|
||||
//setZGyroOffset(0);
|
||||
|
||||
DEBUG_PRINTLN(F("Writing final memory update 1/19 (function unknown)..."));
|
||||
uint8_t dmpUpdate[16], j;
|
||||
uint16_t pos = 0;
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
|
||||
DEBUG_PRINTLN(F("Writing final memory update 2/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
|
||||
DEBUG_PRINTLN(F("Resetting FIFO..."));
|
||||
resetFIFO();
|
||||
|
||||
DEBUG_PRINTLN(F("Reading FIFO count..."));
|
||||
uint8_t fifoCount = getFIFOCount();
|
||||
|
||||
DEBUG_PRINT(F("Current FIFO count="));
|
||||
DEBUG_PRINTLN(fifoCount);
|
||||
uint8_t fifoBuffer[128];
|
||||
//getFIFOBytes(fifoBuffer, fifoCount);
|
||||
|
||||
DEBUG_PRINTLN(F("Writing final memory update 3/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
|
||||
DEBUG_PRINTLN(F("Writing final memory update 4/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
|
||||
DEBUG_PRINTLN(F("Disabling all standby flags..."));
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_PWR_MGMT_2, 0x00);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting accelerometer sensitivity to +/- 2g..."));
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_ACCEL_CONFIG, 0x00);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting motion detection threshold to 2..."));
|
||||
setMotionDetectionThreshold(2);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting zero-motion detection threshold to 156..."));
|
||||
setZeroMotionDetectionThreshold(156);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting motion detection duration to 80..."));
|
||||
setMotionDetectionDuration(80);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting zero-motion detection duration to 0..."));
|
||||
setZeroMotionDetectionDuration(0);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting AK8975 to single measurement mode..."));
|
||||
//mag -> setMode(1);
|
||||
I2Cdev::writeByte(0x0E, 0x0A, 0x01);
|
||||
|
||||
// setup AK8975 (0x0E) as Slave 0 in read mode
|
||||
DEBUG_PRINTLN(F("Setting up AK8975 read slave 0..."));
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_I2C_SLV0_ADDR, 0x8E);
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_I2C_SLV0_REG, 0x01);
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_I2C_SLV0_CTRL, 0xDA);
|
||||
|
||||
// setup AK8975 (0x0E) as Slave 2 in write mode
|
||||
DEBUG_PRINTLN(F("Setting up AK8975 write slave 2..."));
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_I2C_SLV2_ADDR, 0x0E);
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_I2C_SLV2_REG, 0x0A);
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_I2C_SLV2_CTRL, 0x81);
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_I2C_SLV2_DO, 0x01);
|
||||
|
||||
// setup I2C timing/delay control
|
||||
DEBUG_PRINTLN(F("Setting up slave access delay..."));
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_I2C_SLV4_CTRL, 0x18);
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_I2C_MST_DELAY_CTRL, 0x05);
|
||||
|
||||
// enable interrupts
|
||||
DEBUG_PRINTLN(F("Enabling default interrupt behavior/no bypass..."));
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_INT_PIN_CFG, 0x00);
|
||||
|
||||
// enable I2C master mode and reset DMP/FIFO
|
||||
DEBUG_PRINTLN(F("Enabling I2C master mode..."));
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_USER_CTRL, 0x20);
|
||||
DEBUG_PRINTLN(F("Resetting FIFO..."));
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_USER_CTRL, 0x24);
|
||||
DEBUG_PRINTLN(F("Rewriting I2C master mode enabled because...I don't know"));
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_USER_CTRL, 0x20);
|
||||
DEBUG_PRINTLN(F("Enabling and resetting DMP/FIFO..."));
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_USER_CTRL, 0xE8);
|
||||
|
||||
DEBUG_PRINTLN(F("Writing final memory update 5/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
DEBUG_PRINTLN(F("Writing final memory update 6/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
DEBUG_PRINTLN(F("Writing final memory update 7/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
DEBUG_PRINTLN(F("Writing final memory update 8/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
DEBUG_PRINTLN(F("Writing final memory update 9/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
DEBUG_PRINTLN(F("Writing final memory update 10/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
DEBUG_PRINTLN(F("Writing final memory update 11/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
|
||||
DEBUG_PRINTLN(F("Reading final memory update 12/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
readMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
#ifdef DEBUG
|
||||
DEBUG_PRINT(F("Read bytes: "));
|
||||
for (j = 0; j < 4; j++) {
|
||||
DEBUG_PRINTF(dmpUpdate[3 + j], HEX);
|
||||
DEBUG_PRINT(" ");
|
||||
}
|
||||
DEBUG_PRINTLN("");
|
||||
#endif
|
||||
|
||||
DEBUG_PRINTLN(F("Writing final memory update 13/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
DEBUG_PRINTLN(F("Writing final memory update 14/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
DEBUG_PRINTLN(F("Writing final memory update 15/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
DEBUG_PRINTLN(F("Writing final memory update 16/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
DEBUG_PRINTLN(F("Writing final memory update 17/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
|
||||
DEBUG_PRINTLN(F("Waiting for FIRO count >= 46..."));
|
||||
while ((fifoCount = getFIFOCount()) < 46);
|
||||
DEBUG_PRINTLN(F("Reading FIFO..."));
|
||||
getFIFOBytes(fifoBuffer, min(fifoCount, 128)); // safeguard only 128 bytes
|
||||
DEBUG_PRINTLN(F("Reading interrupt status..."));
|
||||
getIntStatus();
|
||||
|
||||
DEBUG_PRINTLN(F("Writing final memory update 18/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
|
||||
DEBUG_PRINTLN(F("Waiting for FIRO count >= 48..."));
|
||||
while ((fifoCount = getFIFOCount()) < 48);
|
||||
DEBUG_PRINTLN(F("Reading FIFO..."));
|
||||
getFIFOBytes(fifoBuffer, min(fifoCount, 128)); // safeguard only 128 bytes
|
||||
DEBUG_PRINTLN(F("Reading interrupt status..."));
|
||||
getIntStatus();
|
||||
DEBUG_PRINTLN(F("Waiting for FIRO count >= 48..."));
|
||||
while ((fifoCount = getFIFOCount()) < 48);
|
||||
DEBUG_PRINTLN(F("Reading FIFO..."));
|
||||
getFIFOBytes(fifoBuffer, min(fifoCount, 128)); // safeguard only 128 bytes
|
||||
DEBUG_PRINTLN(F("Reading interrupt status..."));
|
||||
getIntStatus();
|
||||
|
||||
DEBUG_PRINTLN(F("Writing final memory update 19/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
|
||||
DEBUG_PRINTLN(F("Disabling DMP (you turn it on later)..."));
|
||||
setDMPEnabled(false);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting up internal 48-byte (default) DMP packet buffer..."));
|
||||
dmpPacketSize = 48;
|
||||
/*if ((dmpPacketBuffer = (uint8_t *)malloc(42)) == 0) {
|
||||
return 3; // TODO: proper error code for no memory
|
||||
}*/
|
||||
|
||||
DEBUG_PRINTLN(F("Resetting FIFO and clearing INT status one last time..."));
|
||||
resetFIFO();
|
||||
getIntStatus();
|
||||
} else {
|
||||
DEBUG_PRINTLN(F("ERROR! DMP configuration verification failed."));
|
||||
return 2; // configuration block loading failed
|
||||
}
|
||||
} else {
|
||||
DEBUG_PRINTLN(F("ERROR! DMP code verification failed."));
|
||||
return 1; // main binary block loading failed
|
||||
}
|
||||
return 0; // success
|
||||
}
|
||||
|
||||
bool MPU6050::dmpPacketAvailable() {
|
||||
return getFIFOCount() >= dmpGetFIFOPacketSize();
|
||||
}
|
||||
|
||||
// uint8_t MPU6050::dmpSetFIFORate(uint8_t fifoRate);
|
||||
// uint8_t MPU6050::dmpGetFIFORate();
|
||||
// uint8_t MPU6050::dmpGetSampleStepSizeMS();
|
||||
// uint8_t MPU6050::dmpGetSampleFrequency();
|
||||
// int32_t MPU6050::dmpDecodeTemperature(int8_t tempReg);
|
||||
|
||||
//uint8_t MPU6050::dmpRegisterFIFORateProcess(inv_obj_func func, int16_t priority);
|
||||
//uint8_t MPU6050::dmpUnregisterFIFORateProcess(inv_obj_func func);
|
||||
//uint8_t MPU6050::dmpRunFIFORateProcesses();
|
||||
|
||||
// uint8_t MPU6050::dmpSendQuaternion(uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendGyro(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendAccel(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendLinearAccel(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendLinearAccelInWorld(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendControlData(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendSensorData(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendExternalSensorData(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendGravity(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendPacketNumber(uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendQuantizedAccel(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendEIS(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
|
||||
uint8_t MPU6050::dmpGetAccel(int32_t *data, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
if (packet == 0) packet = dmpPacketBuffer;
|
||||
data[0] = (((uint32_t)packet[34] << 24) | ((uint32_t)packet[35] << 16) | ((uint32_t)packet[36] << 8) | packet[37]);
|
||||
data[1] = (((uint32_t)packet[38] << 24) | ((uint32_t)packet[39] << 16) | ((uint32_t)packet[40] << 8) | packet[41]);
|
||||
data[2] = (((uint32_t)packet[42] << 24) | ((uint32_t)packet[43] << 16) | ((uint32_t)packet[44] << 8) | packet[45]);
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpGetAccel(int16_t *data, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
if (packet == 0) packet = dmpPacketBuffer;
|
||||
data[0] = (packet[34] << 8) | packet[35];
|
||||
data[1] = (packet[38] << 8) | packet[39];
|
||||
data[2] = (packet[42] << 8) | packet[43];
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpGetAccel(VectorInt16 *v, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
if (packet == 0) packet = dmpPacketBuffer;
|
||||
v -> x = (packet[34] << 8) | packet[35];
|
||||
v -> y = (packet[38] << 8) | packet[39];
|
||||
v -> z = (packet[42] << 8) | packet[43];
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpGetQuaternion(int32_t *data, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
if (packet == 0) packet = dmpPacketBuffer;
|
||||
data[0] = (((uint32_t)packet[0] << 24) | ((uint32_t)packet[1] << 16) | ((uint32_t)packet[2] << 8) | packet[3]);
|
||||
data[1] = (((uint32_t)packet[4] << 24) | ((uint32_t)packet[5] << 16) | ((uint32_t)packet[6] << 8) | packet[7]);
|
||||
data[2] = (((uint32_t)packet[8] << 24) | ((uint32_t)packet[9] << 16) | ((uint32_t)packet[10] << 8) | packet[11]);
|
||||
data[3] = (((uint32_t)packet[12] << 24) | ((uint32_t)packet[13] << 16) | ((uint32_t)packet[14] << 8) | packet[15]);
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpGetQuaternion(int16_t *data, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
if (packet == 0) packet = dmpPacketBuffer;
|
||||
data[0] = ((packet[0] << 8) | packet[1]);
|
||||
data[1] = ((packet[4] << 8) | packet[5]);
|
||||
data[2] = ((packet[8] << 8) | packet[9]);
|
||||
data[3] = ((packet[12] << 8) | packet[13]);
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpGetQuaternion(Quaternion *q, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
int16_t qI[4];
|
||||
uint8_t status = dmpGetQuaternion(qI, packet);
|
||||
if (status == 0) {
|
||||
q -> w = (float)qI[0] / 16384.0f;
|
||||
q -> x = (float)qI[1] / 16384.0f;
|
||||
q -> y = (float)qI[2] / 16384.0f;
|
||||
q -> z = (float)qI[3] / 16384.0f;
|
||||
return 0;
|
||||
}
|
||||
return status; // int16 return value, indicates error if this line is reached
|
||||
}
|
||||
// uint8_t MPU6050::dmpGet6AxisQuaternion(long *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetRelativeQuaternion(long *data, const uint8_t* packet);
|
||||
uint8_t MPU6050::dmpGetGyro(int32_t *data, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
if (packet == 0) packet = dmpPacketBuffer;
|
||||
data[0] = (((uint32_t)packet[16] << 24) | ((uint32_t)packet[17] << 16) | ((uint32_t)packet[18] << 8) | packet[19]);
|
||||
data[1] = (((uint32_t)packet[20] << 24) | ((uint32_t)packet[21] << 16) | ((uint32_t)packet[22] << 8) | packet[23]);
|
||||
data[2] = (((uint32_t)packet[24] << 24) | ((uint32_t)packet[25] << 16) | ((uint32_t)packet[26] << 8) | packet[27]);
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpGetGyro(int16_t *data, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
if (packet == 0) packet = dmpPacketBuffer;
|
||||
data[0] = (packet[16] << 8) | packet[17];
|
||||
data[1] = (packet[20] << 8) | packet[21];
|
||||
data[2] = (packet[24] << 8) | packet[25];
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpGetMag(int16_t *data, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
if (packet == 0) packet = dmpPacketBuffer;
|
||||
data[0] = (packet[28] << 8) | packet[29];
|
||||
data[1] = (packet[30] << 8) | packet[31];
|
||||
data[2] = (packet[32] << 8) | packet[33];
|
||||
return 0;
|
||||
}
|
||||
// uint8_t MPU6050::dmpSetLinearAccelFilterCoefficient(float coef);
|
||||
// uint8_t MPU6050::dmpGetLinearAccel(long *data, const uint8_t* packet);
|
||||
uint8_t MPU6050::dmpGetLinearAccel(VectorInt16 *v, VectorInt16 *vRaw, VectorFloat *gravity) {
|
||||
// get rid of the gravity component (+1g = +4096 in standard DMP FIFO packet)
|
||||
v -> x = vRaw -> x - gravity -> x*4096;
|
||||
v -> y = vRaw -> y - gravity -> y*4096;
|
||||
v -> z = vRaw -> z - gravity -> z*4096;
|
||||
return 0;
|
||||
}
|
||||
// uint8_t MPU6050::dmpGetLinearAccelInWorld(long *data, const uint8_t* packet);
|
||||
uint8_t MPU6050::dmpGetLinearAccelInWorld(VectorInt16 *v, VectorInt16 *vReal, Quaternion *q) {
|
||||
// rotate measured 3D acceleration vector into original state
|
||||
// frame of reference based on orientation quaternion
|
||||
memcpy(v, vReal, sizeof(VectorInt16));
|
||||
v -> rotate(q);
|
||||
return 0;
|
||||
}
|
||||
// uint8_t MPU6050::dmpGetGyroAndAccelSensor(long *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetGyroSensor(long *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetControlData(long *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetTemperature(long *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetGravity(long *data, const uint8_t* packet);
|
||||
uint8_t MPU6050::dmpGetGravity(VectorFloat *v, Quaternion *q) {
|
||||
v -> x = 2 * (q -> x*q -> z - q -> w*q -> y);
|
||||
v -> y = 2 * (q -> w*q -> x + q -> y*q -> z);
|
||||
v -> z = q -> w*q -> w - q -> x*q -> x - q -> y*q -> y + q -> z*q -> z;
|
||||
return 0;
|
||||
}
|
||||
// uint8_t MPU6050::dmpGetUnquantizedAccel(long *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetQuantizedAccel(long *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetExternalSensorData(long *data, int size, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetEIS(long *data, const uint8_t* packet);
|
||||
|
||||
uint8_t MPU6050::dmpGetEuler(float *data, Quaternion *q) {
|
||||
data[0] = atan2(2*q -> x*q -> y - 2*q -> w*q -> z, 2*q -> w*q -> w + 2*q -> x*q -> x - 1); // psi
|
||||
data[1] = -asin(2*q -> x*q -> z + 2*q -> w*q -> y); // theta
|
||||
data[2] = atan2(2*q -> y*q -> z - 2*q -> w*q -> x, 2*q -> w*q -> w + 2*q -> z*q -> z - 1); // phi
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpGetYawPitchRoll(float *data, Quaternion *q, VectorFloat *gravity) {
|
||||
// yaw: (about Z axis)
|
||||
data[0] = atan2(2*q -> x*q -> y - 2*q -> w*q -> z, 2*q -> w*q -> w + 2*q -> x*q -> x - 1);
|
||||
// pitch: (nose up/down, about Y axis)
|
||||
data[1] = atan(gravity -> x / sqrt(gravity -> y*gravity -> y + gravity -> z*gravity -> z));
|
||||
// roll: (tilt left/right, about X axis)
|
||||
data[2] = atan(gravity -> y / sqrt(gravity -> x*gravity -> x + gravity -> z*gravity -> z));
|
||||
return 0;
|
||||
}
|
||||
|
||||
// uint8_t MPU6050::dmpGetAccelFloat(float *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetQuaternionFloat(float *data, const uint8_t* packet);
|
||||
|
||||
uint8_t MPU6050::dmpProcessFIFOPacket(const unsigned char *dmpData) {
|
||||
/*for (uint8_t k = 0; k < dmpPacketSize; k++) {
|
||||
if (dmpData[k] < 0x10) Serial.print("0");
|
||||
Serial.print(dmpData[k], HEX);
|
||||
Serial.print(" ");
|
||||
}
|
||||
Serial.print("\n");*/
|
||||
//Serial.println((uint16_t)dmpPacketBuffer);
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpReadAndProcessFIFOPacket(uint8_t numPackets, uint8_t *processed) {
|
||||
uint8_t status;
|
||||
uint8_t buf[dmpPacketSize];
|
||||
for (uint8_t i = 0; i < numPackets; i++) {
|
||||
// read packet from FIFO
|
||||
getFIFOBytes(buf, dmpPacketSize);
|
||||
|
||||
// process packet
|
||||
if ((status = dmpProcessFIFOPacket(buf)) > 0) return status;
|
||||
|
||||
// increment external process count variable, if supplied
|
||||
if (processed != 0) *processed++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// uint8_t MPU6050::dmpSetFIFOProcessedCallback(void (*func) (void));
|
||||
|
||||
// uint8_t MPU6050::dmpInitFIFOParam();
|
||||
// uint8_t MPU6050::dmpCloseFIFO();
|
||||
// uint8_t MPU6050::dmpSetGyroDataSource(uint_fast8_t source);
|
||||
// uint8_t MPU6050::dmpDecodeQuantizedAccel();
|
||||
// uint32_t MPU6050::dmpGetGyroSumOfSquare();
|
||||
// uint32_t MPU6050::dmpGetAccelSumOfSquare();
|
||||
// void MPU6050::dmpOverrideQuaternion(long *q);
|
||||
uint16_t MPU6050::dmpGetFIFOPacketSize() {
|
||||
return dmpPacketSize;
|
||||
}
|
||||
|
||||
#endif /* _MPU6050_9AXIS_MOTIONAPPS41_H_ */
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
MPU6050 Triple Axis Gyroscope & Accelerometer. Pitch & Roll Accelerometer Example.
|
||||
Read more: http://www.jarzebski.pl/arduino/czujniki-i-sensory/3-osiowy-zyroskop-i-akcelerometr-mpu6050.html
|
||||
GIT: https://github.com/jarzebski/Arduino-MPU6050
|
||||
Web: http://www.jarzebski.pl
|
||||
(c) 2014 by Korneliusz Jarzebski
|
||||
*/
|
||||
|
||||
#include <Wire.h>
|
||||
#include <MPU6050.h>
|
||||
|
||||
MPU6050 mpu;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
Serial.println("Initialize MPU6050");
|
||||
|
||||
while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
|
||||
{
|
||||
Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
|
||||
delay(500);
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Read normalized values
|
||||
Vector normAccel = mpu.readNormalizeAccel();
|
||||
|
||||
// Calculate Pitch & Roll
|
||||
int pitch = -(atan2(normAccel.XAxis, sqrt(normAccel.YAxis*normAccel.YAxis + normAccel.ZAxis*normAccel.ZAxis))*180.0)/M_PI;
|
||||
int roll = (atan2(normAccel.YAxis, normAccel.ZAxis)*180.0)/M_PI;
|
||||
|
||||
// Output
|
||||
Serial.print(" Pitch = ");
|
||||
Serial.print(pitch);
|
||||
Serial.print(" Roll = ");
|
||||
Serial.print(roll);
|
||||
|
||||
Serial.println();
|
||||
|
||||
delay(10);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
MPU6050 Triple Axis Gyroscope & Accelerometer. Simple Accelerometer Example.
|
||||
Read more: http://www.jarzebski.pl/arduino/czujniki-i-sensory/3-osiowy-zyroskop-i-akcelerometr-mpu6050.html
|
||||
GIT: https://github.com/jarzebski/Arduino-MPU6050
|
||||
Web: http://www.jarzebski.pl
|
||||
(c) 2014 by Korneliusz Jarzebski
|
||||
*/
|
||||
|
||||
#include <Wire.h>
|
||||
#include <MPU6050.h>
|
||||
|
||||
MPU6050 mpu;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
Serial.println("Initialize MPU6050");
|
||||
|
||||
while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
|
||||
{
|
||||
Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// If you want, you can set accelerometer offsets
|
||||
// mpu.setAccelOffsetX();
|
||||
// mpu.setAccelOffsetY();
|
||||
// mpu.setAccelOffsetZ();
|
||||
|
||||
checkSettings();
|
||||
}
|
||||
|
||||
void checkSettings()
|
||||
{
|
||||
Serial.println();
|
||||
|
||||
Serial.print(" * Sleep Mode: ");
|
||||
Serial.println(mpu.getSleepEnabled() ? "Enabled" : "Disabled");
|
||||
|
||||
Serial.print(" * Clock Source: ");
|
||||
switch(mpu.getClockSource())
|
||||
{
|
||||
case MPU6050_CLOCK_KEEP_RESET: Serial.println("Stops the clock and keeps the timing generator in reset"); break;
|
||||
case MPU6050_CLOCK_EXTERNAL_19MHZ: Serial.println("PLL with external 19.2MHz reference"); break;
|
||||
case MPU6050_CLOCK_EXTERNAL_32KHZ: Serial.println("PLL with external 32.768kHz reference"); break;
|
||||
case MPU6050_CLOCK_PLL_ZGYRO: Serial.println("PLL with Z axis gyroscope reference"); break;
|
||||
case MPU6050_CLOCK_PLL_YGYRO: Serial.println("PLL with Y axis gyroscope reference"); break;
|
||||
case MPU6050_CLOCK_PLL_XGYRO: Serial.println("PLL with X axis gyroscope reference"); break;
|
||||
case MPU6050_CLOCK_INTERNAL_8MHZ: Serial.println("Internal 8MHz oscillator"); break;
|
||||
}
|
||||
|
||||
Serial.print(" * Accelerometer: ");
|
||||
switch(mpu.getRange())
|
||||
{
|
||||
case MPU6050_RANGE_16G: Serial.println("+/- 16 g"); break;
|
||||
case MPU6050_RANGE_8G: Serial.println("+/- 8 g"); break;
|
||||
case MPU6050_RANGE_4G: Serial.println("+/- 4 g"); break;
|
||||
case MPU6050_RANGE_2G: Serial.println("+/- 2 g"); break;
|
||||
}
|
||||
|
||||
Serial.print(" * Accelerometer offsets: ");
|
||||
Serial.print(mpu.getAccelOffsetX());
|
||||
Serial.print(" / ");
|
||||
Serial.print(mpu.getAccelOffsetY());
|
||||
Serial.print(" / ");
|
||||
Serial.println(mpu.getAccelOffsetZ());
|
||||
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Vector rawAccel = mpu.readRawAccel();
|
||||
Vector normAccel = mpu.readNormalizeAccel();
|
||||
|
||||
Serial.print(" Xraw = ");
|
||||
Serial.print(rawAccel.XAxis);
|
||||
Serial.print(" Yraw = ");
|
||||
Serial.print(rawAccel.YAxis);
|
||||
Serial.print(" Zraw = ");
|
||||
|
||||
Serial.println(rawAccel.ZAxis);
|
||||
Serial.print(" Xnorm = ");
|
||||
Serial.print(normAccel.XAxis);
|
||||
Serial.print(" Ynorm = ");
|
||||
Serial.print(normAccel.YAxis);
|
||||
Serial.print(" Znorm = ");
|
||||
Serial.println(normAccel.ZAxis);
|
||||
|
||||
delay(10);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
MPU6050 Triple Axis Gyroscope & Accelerometer. Free fall detection.
|
||||
Read more: http://www.jarzebski.pl/arduino/czujniki-i-sensory/3-osiowy-zyroskop-i-akcelerometr-mpu6050.html
|
||||
GIT: https://github.com/jarzebski/Arduino-MPU6050
|
||||
Web: http://www.jarzebski.pl
|
||||
(c) 2014 by Korneliusz Jarzebski
|
||||
*/
|
||||
|
||||
#include <Wire.h>
|
||||
#include <MPU6050.h>
|
||||
|
||||
MPU6050 mpu;
|
||||
|
||||
boolean ledState = false;
|
||||
boolean freefallDetected = false;
|
||||
int freefallBlinkCount = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
Serial.println("Initialize MPU6050");
|
||||
|
||||
while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_16G))
|
||||
{
|
||||
Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
mpu.setAccelPowerOnDelay(MPU6050_DELAY_3MS);
|
||||
|
||||
mpu.setIntFreeFallEnabled(true);
|
||||
mpu.setIntZeroMotionEnabled(false);
|
||||
mpu.setIntMotionEnabled(false);
|
||||
|
||||
mpu.setDHPFMode(MPU6050_DHPF_5HZ);
|
||||
|
||||
mpu.setFreeFallDetectionThreshold(17);
|
||||
mpu.setFreeFallDetectionDuration(2);
|
||||
|
||||
checkSettings();
|
||||
|
||||
pinMode(4, OUTPUT);
|
||||
digitalWrite(4, LOW);
|
||||
|
||||
attachInterrupt(0, doInt, RISING);
|
||||
}
|
||||
|
||||
void doInt()
|
||||
{
|
||||
freefallBlinkCount = 0;
|
||||
freefallDetected = true;
|
||||
}
|
||||
|
||||
void checkSettings()
|
||||
{
|
||||
Serial.println();
|
||||
|
||||
Serial.print(" * Sleep Mode: ");
|
||||
Serial.println(mpu.getSleepEnabled() ? "Enabled" : "Disabled");
|
||||
|
||||
Serial.print(" * Motion Interrupt: ");
|
||||
Serial.println(mpu.getIntMotionEnabled() ? "Enabled" : "Disabled");
|
||||
|
||||
Serial.print(" * Zero Motion Interrupt: ");
|
||||
Serial.println(mpu.getIntZeroMotionEnabled() ? "Enabled" : "Disabled");
|
||||
|
||||
Serial.print(" * Free Fall Interrupt: ");
|
||||
Serial.println(mpu.getIntFreeFallEnabled() ? "Enabled" : "Disabled");
|
||||
|
||||
Serial.print(" * Free Fal Threshold: ");
|
||||
Serial.println(mpu.getFreeFallDetectionThreshold());
|
||||
|
||||
Serial.print(" * Free FallDuration: ");
|
||||
Serial.println(mpu.getFreeFallDetectionDuration());
|
||||
|
||||
Serial.print(" * Clock Source: ");
|
||||
switch(mpu.getClockSource())
|
||||
{
|
||||
case MPU6050_CLOCK_KEEP_RESET: Serial.println("Stops the clock and keeps the timing generator in reset"); break;
|
||||
case MPU6050_CLOCK_EXTERNAL_19MHZ: Serial.println("PLL with external 19.2MHz reference"); break;
|
||||
case MPU6050_CLOCK_EXTERNAL_32KHZ: Serial.println("PLL with external 32.768kHz reference"); break;
|
||||
case MPU6050_CLOCK_PLL_ZGYRO: Serial.println("PLL with Z axis gyroscope reference"); break;
|
||||
case MPU6050_CLOCK_PLL_YGYRO: Serial.println("PLL with Y axis gyroscope reference"); break;
|
||||
case MPU6050_CLOCK_PLL_XGYRO: Serial.println("PLL with X axis gyroscope reference"); break;
|
||||
case MPU6050_CLOCK_INTERNAL_8MHZ: Serial.println("Internal 8MHz oscillator"); break;
|
||||
}
|
||||
|
||||
Serial.print(" * Accelerometer: ");
|
||||
switch(mpu.getRange())
|
||||
{
|
||||
case MPU6050_RANGE_16G: Serial.println("+/- 16 g"); break;
|
||||
case MPU6050_RANGE_8G: Serial.println("+/- 8 g"); break;
|
||||
case MPU6050_RANGE_4G: Serial.println("+/- 4 g"); break;
|
||||
case MPU6050_RANGE_2G: Serial.println("+/- 2 g"); break;
|
||||
}
|
||||
|
||||
Serial.print(" * Accelerometer offsets: ");
|
||||
Serial.print(mpu.getAccelOffsetX());
|
||||
Serial.print(" / ");
|
||||
Serial.print(mpu.getAccelOffsetY());
|
||||
Serial.print(" / ");
|
||||
Serial.println(mpu.getAccelOffsetZ());
|
||||
|
||||
Serial.print(" * Accelerometer power delay: ");
|
||||
switch(mpu.getAccelPowerOnDelay())
|
||||
{
|
||||
case MPU6050_DELAY_3MS: Serial.println("3ms"); break;
|
||||
case MPU6050_DELAY_2MS: Serial.println("2ms"); break;
|
||||
case MPU6050_DELAY_1MS: Serial.println("1ms"); break;
|
||||
case MPU6050_NO_DELAY: Serial.println("0ms"); break;
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Vector rawAccel = mpu.readRawAccel();
|
||||
Activites act = mpu.readActivites();
|
||||
|
||||
Serial.print(act.isFreeFall);
|
||||
Serial.print("\n");
|
||||
|
||||
if (freefallDetected)
|
||||
{
|
||||
ledState = !ledState;
|
||||
|
||||
digitalWrite(4, ledState);
|
||||
|
||||
freefallBlinkCount++;
|
||||
|
||||
if (freefallBlinkCount == 20)
|
||||
{
|
||||
freefallDetected = false;
|
||||
ledState = false;
|
||||
digitalWrite(4, ledState);
|
||||
}
|
||||
}
|
||||
|
||||
delay(100);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
MPU6050 Triple Axis Gyroscope & Accelerometer. Pitch & Roll & Yaw Gyroscope Example.
|
||||
Read more: http://www.jarzebski.pl/arduino/czujniki-i-sensory/3-osiowy-zyroskop-i-akcelerometr-mpu6050.html
|
||||
GIT: https://github.com/jarzebski/Arduino-MPU6050
|
||||
Web: http://www.jarzebski.pl
|
||||
(c) 2014 by Korneliusz Jarzebski
|
||||
*/
|
||||
|
||||
#include <Wire.h>
|
||||
#include <MPU6050.h>
|
||||
|
||||
MPU6050 mpu;
|
||||
|
||||
// Timers
|
||||
unsigned long timer = 0;
|
||||
float timeStep = 0.01;
|
||||
|
||||
// Pitch, Roll and Yaw values
|
||||
float pitch = 0;
|
||||
float roll = 0;
|
||||
float yaw = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
// Initialize MPU6050
|
||||
while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
|
||||
{
|
||||
Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// Calibrate gyroscope. The calibration must be at rest.
|
||||
// If you don't want calibrate, comment this line.
|
||||
mpu.calibrateGyro();
|
||||
|
||||
// Set threshold sensivty. Default 3.
|
||||
// If you don't want use threshold, comment this line or set 0.
|
||||
mpu.setThreshold(3);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
timer = millis();
|
||||
|
||||
// Read normalized values
|
||||
Vector norm = mpu.readNormalizeGyro();
|
||||
|
||||
// Calculate Pitch, Roll and Yaw
|
||||
pitch = pitch + norm.YAxis * timeStep;
|
||||
roll = roll + norm.XAxis * timeStep;
|
||||
yaw = yaw + norm.ZAxis * timeStep;
|
||||
|
||||
// Output raw
|
||||
Serial.print(" Pitch = ");
|
||||
Serial.print(pitch);
|
||||
Serial.print(" Roll = ");
|
||||
Serial.print(roll);
|
||||
Serial.print(" Yaw = ");
|
||||
Serial.println(yaw);
|
||||
|
||||
// Wait to full timeStep period
|
||||
delay((timeStep*1000) - (millis() - timer));
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
MPU6050 Triple Axis Gyroscope & Accelerometer. Simple Gyroscope Example.
|
||||
Read more: http://www.jarzebski.pl/arduino/czujniki-i-sensory/3-osiowy-zyroskop-i-akcelerometr-mpu6050.html
|
||||
GIT: https://github.com/jarzebski/Arduino-MPU6050
|
||||
Web: http://www.jarzebski.pl
|
||||
(c) 2014 by Korneliusz Jarzebski
|
||||
*/
|
||||
|
||||
#include <Wire.h>
|
||||
#include <MPU6050.h>
|
||||
|
||||
MPU6050 mpu;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
// Initialize MPU6050
|
||||
Serial.println("Initialize MPU6050");
|
||||
while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
|
||||
{
|
||||
Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// If you want, you can set gyroscope offsets
|
||||
// mpu.setGyroOffsetX(155);
|
||||
// mpu.setGyroOffsetY(15);
|
||||
// mpu.setGyroOffsetZ(15);
|
||||
|
||||
// Calibrate gyroscope. The calibration must be at rest.
|
||||
// If you don't want calibrate, comment this line.
|
||||
mpu.calibrateGyro();
|
||||
|
||||
// Set threshold sensivty. Default 3.
|
||||
// If you don't want use threshold, comment this line or set 0.
|
||||
mpu.setThreshold(3);
|
||||
|
||||
// Check settings
|
||||
checkSettings();
|
||||
}
|
||||
|
||||
void checkSettings()
|
||||
{
|
||||
Serial.println();
|
||||
|
||||
Serial.print(" * Sleep Mode: ");
|
||||
Serial.println(mpu.getSleepEnabled() ? "Enabled" : "Disabled");
|
||||
|
||||
Serial.print(" * Clock Source: ");
|
||||
switch(mpu.getClockSource())
|
||||
{
|
||||
case MPU6050_CLOCK_KEEP_RESET: Serial.println("Stops the clock and keeps the timing generator in reset"); break;
|
||||
case MPU6050_CLOCK_EXTERNAL_19MHZ: Serial.println("PLL with external 19.2MHz reference"); break;
|
||||
case MPU6050_CLOCK_EXTERNAL_32KHZ: Serial.println("PLL with external 32.768kHz reference"); break;
|
||||
case MPU6050_CLOCK_PLL_ZGYRO: Serial.println("PLL with Z axis gyroscope reference"); break;
|
||||
case MPU6050_CLOCK_PLL_YGYRO: Serial.println("PLL with Y axis gyroscope reference"); break;
|
||||
case MPU6050_CLOCK_PLL_XGYRO: Serial.println("PLL with X axis gyroscope reference"); break;
|
||||
case MPU6050_CLOCK_INTERNAL_8MHZ: Serial.println("Internal 8MHz oscillator"); break;
|
||||
}
|
||||
|
||||
Serial.print(" * Gyroscope: ");
|
||||
switch(mpu.getScale())
|
||||
{
|
||||
case MPU6050_SCALE_2000DPS: Serial.println("2000 dps"); break;
|
||||
case MPU6050_SCALE_1000DPS: Serial.println("1000 dps"); break;
|
||||
case MPU6050_SCALE_500DPS: Serial.println("500 dps"); break;
|
||||
case MPU6050_SCALE_250DPS: Serial.println("250 dps"); break;
|
||||
}
|
||||
|
||||
Serial.print(" * Gyroscope offsets: ");
|
||||
Serial.print(mpu.getGyroOffsetX());
|
||||
Serial.print(" / ");
|
||||
Serial.print(mpu.getGyroOffsetY());
|
||||
Serial.print(" / ");
|
||||
Serial.println(mpu.getGyroOffsetZ());
|
||||
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Vector rawGyro = mpu.readRawGyro();
|
||||
Vector normGyro = mpu.readNormalizeGyro();
|
||||
|
||||
Serial.print(" Xraw = ");
|
||||
Serial.print(rawGyro.XAxis);
|
||||
Serial.print(" Yraw = ");
|
||||
Serial.print(rawGyro.YAxis);
|
||||
Serial.print(" Zraw = ");
|
||||
Serial.println(rawGyro.ZAxis);
|
||||
|
||||
Serial.print(" Xnorm = ");
|
||||
Serial.print(normGyro.XAxis);
|
||||
Serial.print(" Ynorm = ");
|
||||
Serial.print(normGyro.YAxis);
|
||||
Serial.print(" Znorm = ");
|
||||
Serial.println(normGyro.ZAxis);
|
||||
|
||||
delay(10);
|
||||
}
|
||||
|
||||
|
||||
156
arduino-cli/libraries/MPU6050/MPU6050_motion/MPU6050_motion.ino
Normal file
156
arduino-cli/libraries/MPU6050/MPU6050_motion/MPU6050_motion.ino
Normal file
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
MPU6050 Triple Axis Gyroscope & Accelerometer. Motion detection.
|
||||
Read more: http://www.jarzebski.pl/arduino/czujniki-i-sensory/3-osiowy-zyroskop-i-akcelerometr-mpu6050.html
|
||||
GIT: https://github.com/jarzebski/Arduino-MPU6050
|
||||
Web: http://www.jarzebski.pl
|
||||
(c) 2014 by Korneliusz Jarzebski
|
||||
*/
|
||||
|
||||
#include <Wire.h>
|
||||
#include <MPU6050.h>
|
||||
|
||||
MPU6050 mpu;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
Serial.println("Initialize MPU6050");
|
||||
|
||||
while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_16G))
|
||||
{
|
||||
Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
mpu.setAccelPowerOnDelay(MPU6050_DELAY_3MS);
|
||||
|
||||
mpu.setIntFreeFallEnabled(false);
|
||||
mpu.setIntZeroMotionEnabled(false);
|
||||
mpu.setIntMotionEnabled(false);
|
||||
|
||||
mpu.setDHPFMode(MPU6050_DHPF_5HZ);
|
||||
|
||||
mpu.setMotionDetectionThreshold(2);
|
||||
mpu.setMotionDetectionDuration(5);
|
||||
|
||||
mpu.setZeroMotionDetectionThreshold(4);
|
||||
mpu.setZeroMotionDetectionDuration(2);
|
||||
|
||||
checkSettings();
|
||||
|
||||
pinMode(4, OUTPUT);
|
||||
digitalWrite(4, LOW);
|
||||
|
||||
pinMode(7, OUTPUT);
|
||||
digitalWrite(7, LOW);
|
||||
}
|
||||
|
||||
void checkSettings()
|
||||
{
|
||||
Serial.println();
|
||||
|
||||
Serial.print(" * Sleep Mode: ");
|
||||
Serial.println(mpu.getSleepEnabled() ? "Enabled" : "Disabled");
|
||||
|
||||
Serial.print(" * Motion Interrupt: ");
|
||||
Serial.println(mpu.getIntMotionEnabled() ? "Enabled" : "Disabled");
|
||||
|
||||
Serial.print(" * Zero Motion Interrupt: ");
|
||||
Serial.println(mpu.getIntZeroMotionEnabled() ? "Enabled" : "Disabled");
|
||||
|
||||
Serial.print(" * Free Fall Interrupt: ");
|
||||
Serial.println(mpu.getIntFreeFallEnabled() ? "Enabled" : "Disabled");
|
||||
|
||||
Serial.print(" * Motion Threshold: ");
|
||||
Serial.println(mpu.getMotionDetectionThreshold());
|
||||
|
||||
Serial.print(" * Motion Duration: ");
|
||||
Serial.println(mpu.getMotionDetectionDuration());
|
||||
|
||||
Serial.print(" * Zero Motion Threshold: ");
|
||||
Serial.println(mpu.getZeroMotionDetectionThreshold());
|
||||
|
||||
Serial.print(" * Zero Motion Duration: ");
|
||||
Serial.println(mpu.getZeroMotionDetectionDuration());
|
||||
|
||||
Serial.print(" * Clock Source: ");
|
||||
switch(mpu.getClockSource())
|
||||
{
|
||||
case MPU6050_CLOCK_KEEP_RESET: Serial.println("Stops the clock and keeps the timing generator in reset"); break;
|
||||
case MPU6050_CLOCK_EXTERNAL_19MHZ: Serial.println("PLL with external 19.2MHz reference"); break;
|
||||
case MPU6050_CLOCK_EXTERNAL_32KHZ: Serial.println("PLL with external 32.768kHz reference"); break;
|
||||
case MPU6050_CLOCK_PLL_ZGYRO: Serial.println("PLL with Z axis gyroscope reference"); break;
|
||||
case MPU6050_CLOCK_PLL_YGYRO: Serial.println("PLL with Y axis gyroscope reference"); break;
|
||||
case MPU6050_CLOCK_PLL_XGYRO: Serial.println("PLL with X axis gyroscope reference"); break;
|
||||
case MPU6050_CLOCK_INTERNAL_8MHZ: Serial.println("Internal 8MHz oscillator"); break;
|
||||
}
|
||||
|
||||
Serial.print(" * Accelerometer: ");
|
||||
switch(mpu.getRange())
|
||||
{
|
||||
case MPU6050_RANGE_16G: Serial.println("+/- 16 g"); break;
|
||||
case MPU6050_RANGE_8G: Serial.println("+/- 8 g"); break;
|
||||
case MPU6050_RANGE_4G: Serial.println("+/- 4 g"); break;
|
||||
case MPU6050_RANGE_2G: Serial.println("+/- 2 g"); break;
|
||||
}
|
||||
|
||||
Serial.print(" * Accelerometer offsets: ");
|
||||
Serial.print(mpu.getAccelOffsetX());
|
||||
Serial.print(" / ");
|
||||
Serial.print(mpu.getAccelOffsetY());
|
||||
Serial.print(" / ");
|
||||
Serial.println(mpu.getAccelOffsetZ());
|
||||
|
||||
Serial.print(" * Accelerometer power delay: ");
|
||||
switch(mpu.getAccelPowerOnDelay())
|
||||
{
|
||||
case MPU6050_DELAY_3MS: Serial.println("3ms"); break;
|
||||
case MPU6050_DELAY_2MS: Serial.println("2ms"); break;
|
||||
case MPU6050_DELAY_1MS: Serial.println("1ms"); break;
|
||||
case MPU6050_NO_DELAY: Serial.println("0ms"); break;
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Vector rawAccel = mpu.readRawAccel();
|
||||
Activites act = mpu.readActivites();
|
||||
|
||||
if (act.isActivity)
|
||||
{
|
||||
digitalWrite(4, HIGH);
|
||||
} else
|
||||
{
|
||||
digitalWrite(4, LOW);
|
||||
}
|
||||
|
||||
if (act.isInactivity)
|
||||
{
|
||||
digitalWrite(7, HIGH);
|
||||
} else
|
||||
{
|
||||
digitalWrite(7, LOW);
|
||||
}
|
||||
|
||||
Serial.print(act.isActivity);
|
||||
Serial.print(act.isInactivity);
|
||||
|
||||
Serial.print(" ");
|
||||
Serial.print(act.isPosActivityOnX);
|
||||
Serial.print(act.isNegActivityOnX);
|
||||
Serial.print(" ");
|
||||
|
||||
Serial.print(act.isPosActivityOnY);
|
||||
Serial.print(act.isNegActivityOnY);
|
||||
Serial.print(" ");
|
||||
|
||||
Serial.print(act.isPosActivityOnZ);
|
||||
Serial.print(act.isNegActivityOnZ);
|
||||
Serial.print("\n");
|
||||
delay(50);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
MPU6050 Triple Axis Gyroscope & Accelerometer. Temperature Example.
|
||||
Read more: http://www.jarzebski.pl/arduino/czujniki-i-sensory/3-osiowy-zyroskop-i-akcelerometr-mpu6050.html
|
||||
GIT: https://github.com/jarzebski/Arduino-MPU6050
|
||||
Web: http://www.jarzebski.pl
|
||||
(c) 2014 by Korneliusz Jarzebski
|
||||
*/
|
||||
|
||||
#include <Wire.h>
|
||||
#include <MPU6050.h>
|
||||
|
||||
MPU6050 mpu;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
Serial.println("Initialize MPU6050");
|
||||
|
||||
while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
|
||||
{
|
||||
Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
|
||||
delay(500);
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
float temp = mpu.readTemperature();
|
||||
|
||||
Serial.print(" Temp = ");
|
||||
Serial.print(temp);
|
||||
Serial.println(" *C");
|
||||
|
||||
delay(500);
|
||||
}
|
||||
|
||||
|
||||
25
arduino-cli/libraries/MPU6050/README.md
Normal file
25
arduino-cli/libraries/MPU6050/README.md
Normal file
@@ -0,0 +1,25 @@
|
||||
Arduino-MPU6050
|
||||
===============
|
||||
|
||||
MPU6050 Triple Axis Gyroscope & Accelerometer Arduino Library.
|
||||
|
||||

|
||||
|
||||
Tutorials: http://www.jarzebski.pl/arduino/czujniki-i-sensory/3-osiowy-zyroskop-i-akcelerometr-mpu6050.html
|
||||
|
||||
This library use I2C to communicate, 2 pins are required to interface
|
||||
|
||||
I need your help
|
||||
----------------
|
||||
|
||||
July 31, 2017
|
||||
|
||||
In the near future I plan to refactoring the libraries. The main goal is to improve code quality, new features and add support for different versions of Arduino boards like Uno, Mega and Zero.
|
||||
|
||||
For this purpose I need to buy modules, Arduino Boards and lot of beer.
|
||||
|
||||
If you want to support the further and long-term development of libraries, please help.
|
||||
|
||||
You can do this by transferring any amount to my PayPal account: paypal@jarzebski.pl
|
||||
|
||||
Thanks!
|
||||
216
arduino-cli/libraries/MPU6050/helper_3dmath.h
Normal file
216
arduino-cli/libraries/MPU6050/helper_3dmath.h
Normal file
@@ -0,0 +1,216 @@
|
||||
// I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050 class, 3D math helper
|
||||
// 6/5/2012 by Jeff Rowberg <jeff@rowberg.net>
|
||||
// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
|
||||
//
|
||||
// Changelog:
|
||||
// 2012-06-05 - add 3D math helper file to DMP6 example sketch
|
||||
|
||||
/* ============================================
|
||||
I2Cdev device library code is placed under the MIT license
|
||||
Copyright (c) 2012 Jeff Rowberg
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
===============================================
|
||||
*/
|
||||
|
||||
#ifndef _HELPER_3DMATH_H_
|
||||
#define _HELPER_3DMATH_H_
|
||||
|
||||
class Quaternion {
|
||||
public:
|
||||
float w;
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
|
||||
Quaternion() {
|
||||
w = 1.0f;
|
||||
x = 0.0f;
|
||||
y = 0.0f;
|
||||
z = 0.0f;
|
||||
}
|
||||
|
||||
Quaternion(float nw, float nx, float ny, float nz) {
|
||||
w = nw;
|
||||
x = nx;
|
||||
y = ny;
|
||||
z = nz;
|
||||
}
|
||||
|
||||
Quaternion getProduct(Quaternion q) {
|
||||
// Quaternion multiplication is defined by:
|
||||
// (Q1 * Q2).w = (w1w2 - x1x2 - y1y2 - z1z2)
|
||||
// (Q1 * Q2).x = (w1x2 + x1w2 + y1z2 - z1y2)
|
||||
// (Q1 * Q2).y = (w1y2 - x1z2 + y1w2 + z1x2)
|
||||
// (Q1 * Q2).z = (w1z2 + x1y2 - y1x2 + z1w2
|
||||
return Quaternion(
|
||||
w*q.w - x*q.x - y*q.y - z*q.z, // new w
|
||||
w*q.x + x*q.w + y*q.z - z*q.y, // new x
|
||||
w*q.y - x*q.z + y*q.w + z*q.x, // new y
|
||||
w*q.z + x*q.y - y*q.x + z*q.w); // new z
|
||||
}
|
||||
|
||||
Quaternion getConjugate() {
|
||||
return Quaternion(w, -x, -y, -z);
|
||||
}
|
||||
|
||||
float getMagnitude() {
|
||||
return sqrt(w*w + x*x + y*y + z*z);
|
||||
}
|
||||
|
||||
void normalize() {
|
||||
float m = getMagnitude();
|
||||
w /= m;
|
||||
x /= m;
|
||||
y /= m;
|
||||
z /= m;
|
||||
}
|
||||
|
||||
Quaternion getNormalized() {
|
||||
Quaternion r(w, x, y, z);
|
||||
r.normalize();
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
class VectorInt16 {
|
||||
public:
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
int16_t z;
|
||||
|
||||
VectorInt16() {
|
||||
x = 0;
|
||||
y = 0;
|
||||
z = 0;
|
||||
}
|
||||
|
||||
VectorInt16(int16_t nx, int16_t ny, int16_t nz) {
|
||||
x = nx;
|
||||
y = ny;
|
||||
z = nz;
|
||||
}
|
||||
|
||||
float getMagnitude() {
|
||||
return sqrt(x*x + y*y + z*z);
|
||||
}
|
||||
|
||||
void normalize() {
|
||||
float m = getMagnitude();
|
||||
x /= m;
|
||||
y /= m;
|
||||
z /= m;
|
||||
}
|
||||
|
||||
VectorInt16 getNormalized() {
|
||||
VectorInt16 r(x, y, z);
|
||||
r.normalize();
|
||||
return r;
|
||||
}
|
||||
|
||||
void rotate(Quaternion *q) {
|
||||
// http://www.cprogramming.com/tutorial/3d/quaternions.html
|
||||
// http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/transforms/index.htm
|
||||
// http://content.gpwiki.org/index.php/OpenGL:Tutorials:Using_Quaternions_to_represent_rotation
|
||||
// ^ or: http://webcache.googleusercontent.com/search?q=cache:xgJAp3bDNhQJ:content.gpwiki.org/index.php/OpenGL:Tutorials:Using_Quaternions_to_represent_rotation&hl=en&gl=us&strip=1
|
||||
|
||||
// P_out = q * P_in * conj(q)
|
||||
// - P_out is the output vector
|
||||
// - q is the orientation quaternion
|
||||
// - P_in is the input vector (a*aReal)
|
||||
// - conj(q) is the conjugate of the orientation quaternion (q=[w,x,y,z], q*=[w,-x,-y,-z])
|
||||
Quaternion p(0, x, y, z);
|
||||
|
||||
// quaternion multiplication: q * p, stored back in p
|
||||
p = q -> getProduct(p);
|
||||
|
||||
// quaternion multiplication: p * conj(q), stored back in p
|
||||
p = p.getProduct(q -> getConjugate());
|
||||
|
||||
// p quaternion is now [0, x', y', z']
|
||||
x = p.x;
|
||||
y = p.y;
|
||||
z = p.z;
|
||||
}
|
||||
|
||||
VectorInt16 getRotated(Quaternion *q) {
|
||||
VectorInt16 r(x, y, z);
|
||||
r.rotate(q);
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
class VectorFloat {
|
||||
public:
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
|
||||
VectorFloat() {
|
||||
x = 0;
|
||||
y = 0;
|
||||
z = 0;
|
||||
}
|
||||
|
||||
VectorFloat(float nx, float ny, float nz) {
|
||||
x = nx;
|
||||
y = ny;
|
||||
z = nz;
|
||||
}
|
||||
|
||||
float getMagnitude() {
|
||||
return sqrt(x*x + y*y + z*z);
|
||||
}
|
||||
|
||||
void normalize() {
|
||||
float m = getMagnitude();
|
||||
x /= m;
|
||||
y /= m;
|
||||
z /= m;
|
||||
}
|
||||
|
||||
VectorFloat getNormalized() {
|
||||
VectorFloat r(x, y, z);
|
||||
r.normalize();
|
||||
return r;
|
||||
}
|
||||
|
||||
void rotate(Quaternion *q) {
|
||||
Quaternion p(0, x, y, z);
|
||||
|
||||
// quaternion multiplication: q * p, stored back in p
|
||||
p = q -> getProduct(p);
|
||||
|
||||
// quaternion multiplication: p * conj(q), stored back in p
|
||||
p = p.getProduct(q -> getConjugate());
|
||||
|
||||
// p quaternion is now [0, x', y', z']
|
||||
x = p.x;
|
||||
y = p.y;
|
||||
z = p.z;
|
||||
}
|
||||
|
||||
VectorFloat getRotated(Quaternion *q) {
|
||||
VectorFloat r(x, y, z);
|
||||
r.rotate(q);
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* _HELPER_3DMATH_H_ */
|
||||
18
arduino-cli/libraries/MPU6050/library.json
Normal file
18
arduino-cli/libraries/MPU6050/library.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "I2Cdevlib-MPU6050",
|
||||
"keywords": "gyroscope, accelerometer, sensor, i2cdevlib, i2c",
|
||||
"description": "The MPU6050 combines a 3-axis gyroscope and a 3-axis accelerometer on the same silicon die together with an onboard Digital Motion Processor(DMP) which processes complex 6-axis MotionFusion algorithms",
|
||||
"include": "Arduino/MPU6050",
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/jrowberg/i2cdevlib.git"
|
||||
},
|
||||
"dependencies":
|
||||
{
|
||||
"name": "I2Cdevlib-Core",
|
||||
"frameworks": "arduino"
|
||||
},
|
||||
"frameworks": "arduino",
|
||||
"platforms": "atmelavr"
|
||||
}
|
||||
Reference in New Issue
Block a user