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

ServoTrim assumes 180 degree rotation #197

Closed
EAGrahamJr opened this issue Apr 13, 2024 · 2 comments · Fixed by #198
Closed

ServoTrim assumes 180 degree rotation #197

EAGrahamJr opened this issue Apr 13, 2024 · 2 comments · Fixed by #198

Comments

@EAGrahamJr
Copy link
Contributor

It took a while to figure out why my gear ratios were not matching real-world mappings until I realized that the servos I'm using (MG90s) move more than 180 degrees with an appropriate pulse-width setting, but the ServoTrim class assumes that a servo cannot move more than 180 degrees.

Thus, ServoTrim should have additional constructors to cover these additional parameters (and adjust all the things accordingly).

EAGrahamJr added a commit to EAGrahamJr/diozero that referenced this issue Apr 14, 2024
Fixes mattjlewis#197

The default mapping would turn out non-zero based angle values because the ddefault assumption is for a 180-degree motor. This new constructor set up the servo to turn from it's baseline 0 degrees to whatever maximum is supplied.

Also added a definition for MG90S metal-gear micro-servos.
@mattjlewis
Copy link
Owner

I don't believe this constructor assumes 180 degree range of movement as per the new constructor comment:

	public ServoTrim(int midPulseWidthUs, int ninetyDegPulseWidthUs, int minPulseWidthUs, int maxPulseWidthUs) {
		this.midPulseWidthUs = midPulseWidthUs;
		this.ninetyDegPulseWidthUs = ninetyDegPulseWidthUs;
		this.minPulseWidthUs = minPulseWidthUs;
		this.maxPulseWidthUs = maxPulseWidthUs;
		minAngle = RangeUtil.map(minPulseWidthUs, midPulseWidthUs - ninetyDegPulseWidthUs,
				midPulseWidthUs + ninetyDegPulseWidthUs, 0, 180, false);
		maxAngle = RangeUtil.map(maxPulseWidthUs, midPulseWidthUs - ninetyDegPulseWidthUs,
				midPulseWidthUs + ninetyDegPulseWidthUs, 0, 180, false);
	}

@mattjlewis mattjlewis reopened this Apr 18, 2024
@EAGrahamJr
Copy link
Contributor Author

Well, I'm an idiot -- I was putting the same value for the 90 degree as the mid-point, so of course it was coming out odd.

At least my new constructor is a little easier to use? 😊

@EAGrahamJr EAGrahamJr closed this as not planned Won't fix, can't repro, duplicate, stale Apr 19, 2024
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 a pull request may close this issue.

2 participants