Skip to content
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

Add function to allow for haptic vibration parameters #3

Merged
merged 3 commits into from
Jan 25, 2022
Merged

Conversation

jclin22009
Copy link
Collaborator

No description provided.

src/haptics.cpp Outdated Show resolved Hide resolved
src/haptics.cpp Outdated
}
}

void actuate_motor(int motor_pin, int duration, int frequency, double percent_motor) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duration: notice that that the loop on line 19 runs each duration for 2*frequency milliseconds. Maybe have duration be specified in milliseconds (instead of motor vibration cycles) and have a line of math to calculate how many times the loop should run.

Copy link
Collaborator

@mjpauly mjpauly Jan 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Motor frequency is also unchanging for this particular motor we are using (it only resonates at one frequency: 170Hz), so can be a constant in the function that doesn't have to be passed in (like how the 85% maximum drive is also a motor-specific constant).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so would the frequency constant be 170?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It stays at 3, since that's the amount of time in milliseconds for half of a cycle. 1/(.006s) = 166.66Hz, which is close enough to 170Hz. Here's a illustration of what we're doing with the analogWrites to simulate a sinusoid at 167Hz. (In our case, unlike in the illustration, the duty cycle doesn't change during those 3ms half-cycles.)

proxy-image(8)sd

Copy link
Collaborator

@mjpauly mjpauly Jan 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you could say that you want to specify the constant as 170Hz, then have some math to turn that into the half-period time: 1/(170Hz) / 2 = 0.00294s. You could get closer to this value than before by multiplying by 10^6 to get the number of microseconds to delay, and use delayMicroseconds instead of delay. Imo 3ms is good enough tho

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also sorry about how not obvious all of this is. I'll admit this PWM scheme to simulate the sinusoid is a bit funny. The motor parameters come from the datasheet which can be found here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, that makes sense. Thanks!

@mjpauly mjpauly merged commit 517a3d4 into main Jan 25, 2022
@jclin22009 jclin22009 deleted the jasons-branch branch January 25, 2022 21:35
@jclin22009 jclin22009 restored the jasons-branch branch January 29, 2022 21:33
@jclin22009 jclin22009 deleted the jasons-branch branch January 29, 2022 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants