-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update MMA8452.cpp #5
base: master
Are you sure you want to change the base?
Conversation
Added pitch roll calculation. MMA8452.cpp part.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple small questions.
I think this can be simplified a bit; ideally the initPitchRoll
would not be needed at all.
Also, could you please put both commits in the same PR so we can merge them as one unit? Basically please do the changes to .h
in this PR too and close the other one
*pitch = (atan2(fXg, sqrt(fYg*fYg + fZg*fZg))*180.0) / M_PI; | ||
} | ||
|
||
void MMA8452::initPitchRoll(float a) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed at all? Could fXg
, fYG
and fZg
not just need to be local variables in getPitchRoll
& alpha
be an argument to the function? If you forget to call initPitchRoll
, alpha
would not be set which would probably not work as expected. Also, it's not immediately clear what the purpose of alpha
is; i suppose it's acting as range? It's not clear what value should be passed in (0.5
?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alpha indeed could be a parameter.
fXg, fYg and fZg need to be members or passed as reference (in/out) parameters to the function and be saved by the caller.
fXg, fYg and fZg are used as a low pass filter implemented as a weighted average of the current reading and the previous readings. It slows the response time but without it the result will be very jerky. When Alpha == 1 the result is calculated without history (no low pass filter). When Alpha is close to zero (e.g. 0.1) the low pass filter is strong and the result is stable (albeit with a few hundred milliseconds delay). 0.5 is a good value for Alpha.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you like this format better?
void MMA8452::getPitchRoll(float *pitch, float *roll, float alpha, float *fXg, float *fYg, float *fZg)
{
float Xg, Yg, Zg;
getAcceleration(&Xg, &Yg, &Zg);
//Low Pass Filter
*fXg = Xg * alpha + (*fXg * (1.0 - alpha));
*fYg = Yg * alpha + (*fYg * (1.0 - alpha));
*fZg = Zg * alpha + (*fZg * (1.0 - alpha));
*roll = (atan2(- *fYg, *fZg)*180.0) / M_PI;
*pitch = (atan2(*fXg, sqrt(*fYg * *fYg + *fZg * *fZg))*180.0) / M_PI;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, i see what you mean now! I've typically implemented lowpass as v += (target - v) * a
so i missed this. This makes sense. Could you please add a comment on alpha
though:
alpha defines how quickly to react to changes. The value should be 0-1.
I would prefer to keep the signature smaller and not having to have the called keep track of these values. Was thinking though, since you're expected to call init()
anyway, why not just set the moving average values (fXg
/fYg
/fZg
) to 0
in there?
@@ -517,3 +517,25 @@ int8_t MMA8452::convertTo2sComplement(int8_t value) | |||
value = (0xFF && ~value) + 1; | |||
return value; | |||
} | |||
|
|||
void MMA8452::getPitchRoll(float *pitch, float *roll) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this also support yaw?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not aware of a way to calculate yaw without a magnetometer or gyro.
I don't know how to commit 2 files in one PR when it is not my account. |
Oh, I guess you did the PR on GitHub directly? What ends up happening is that the project is forked to your user and if you push new commits to the branch there, they'll show in this PR. https://github.com/kshepitzki/Arduino-MMA8452/tree/patch-3
The commit should then show up here. Happy to help if you need more info! |
@kshepitzki I think this is a very useful feature, would be nice to see it merged. Let me know if you need any more help with github etc, i'm happy to help |
body p { margin-bottom: 0cm; margin-top: 0pt; }
Yes
I couldn't get to make changes in 2 files in one PR.
Can you maybe merge the change yourself? I don't care about
appearing as contributor. Just want your library to offer more to
people like me.
BR
Gary
On 6/8/2018 5:21 PM, Antti Kupila
wrote:
@kshepitzki
I think this is a very useful feature, would be nice to see it
merged. Let me know if you need any more help with github etc,
i'm happy to help
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
{"@context":"http://schema.org","@type":"EmailMessage","potentialAction":{"@type":"ViewAction","target":"https://github.com/akupila/Arduino-MMA8452/pull/5#issuecomment-395776242","url":"https://github.com/akupila/Arduino-MMA8452/pull/5#issuecomment-395776242","name":"View Pull Request"},"description":"View this Pull Request on GitHub","publisher":{"@type":"Organization","name":"GitHub","url":"https://github.com"}}
{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/akupila/Arduino-MMA8452","title":"akupila/Arduino-MMA8452","subtitle":"GitHub repository","main_image_url":"https://assets-cdn.github.com/images/email/message_cards/header.png","avatar_image_url":"https://assets-cdn.github.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/akupila/Arduino-MMA8452"}},"updates":{"snippets":[{"icon":"PERSON","message":"@akupila in #5: @kshepitzki I think this is a very useful feature, would be nice to see it merged. Let me know if you need any more help with github etc, i'm happy to help"}],"action":{"name":"View Pull Request","url":"#5 (comment)"}}}
{
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"hideOriginalBody": "false",
"originator": "AF6C5A86-E920-430C-9C59-A73278B5EFEB",
"title": "Re: [akupila/Arduino-MMA8452] Update MMA8452.cpp (#5)",
"sections": [
{
"text": "",
"activityTitle": "**Antti Kupila**",
"activityImage": "https://assets-cdn.github.com/images/email/message_cards/avatar.png",
"activitySubtitle": "@akupila",
"facts": [
]
}
],
"potentialAction": [
{
"name": "Add a comment",
"@type": "ActionCard",
"inputs": [
{
"isMultiLine": true,
"@type": "TextInput",
"id": "IssueComment",
"isRequired": false
}
],
"actions": [
{
"name": "Comment",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"IssueComment\",\n\"repositoryFullName\": \"akupila/Arduino-MMA8452\",\n\"issueId\": 5,\n\"IssueComment\": \"{{IssueComment.value}}\"\n}"
}
]
},
{
"name": "Close pull request",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"PullRequestClose\",\n\"repositoryFullName\": \"akupila/Arduino-MMA8452\",\n\"pullRequestId\": 5\n}"
},
{
"targets": [
{
"os": "default",
"uri": "#5 (comment)"
}
],
"@type": "OpenUri",
"name": "View on GitHub"
},
{
"name": "Unsubscribe",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"MuteNotification\",\n\"threadId\": 339266123\n}"
}
],
"themeColor": "26292E"
}
Virus-free. www.avast.com
|
Added pitch roll calculation. MMA8452.cpp part.