Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.

MakeCode: why no yaw for accelerometer?

If I am trying to see what is going on with the accelerometer, I can see pitch and roll, but what I really care about is yaw, the Z-axis. The goal is to keep a bot driven by two DC motors going straight by adjusting motor speeds. Unless I mount the unit vertically, I cannot see the rotation of the unit. I am assuming that "rotation" is integrating accelerometer data over time to determine the angle the accelerometer is currently pointing. Since there seems to be no reason for not having the Z-axis data processed, can this be added?
joe

flounder

Posts: 417
Joined: Wed Sep 18, 2013 9:10 pm
Location: Pittsburgh PA

Re: MakeCode: why no yaw for accelerometer?

There's a drop-down on the acceleration block with x, y, and z. Do you see this on yours?
Selection_077.png (7.62 KiB) Viewed 804 times

danhalbert

Posts: 2139
Joined: Tue Aug 08, 2017 12:37 pm

Re: MakeCode: why no yaw for accelerometer?

yes, but I was asking about “rotation”, which only has pitch and roll. I am assuming that pitch and roll are based on taking acceleration and computing rotational position. And while *I* can do the computation, I would be asking 4th or 5th grade students to do this computation. This would be beyond them. Of course, I could mount the CP(exp) vertically, but what if I need position in all three axes?

I have been unable to verify how position actually behaves because I cannot get any serial output displayed.
joe

flounder

Posts: 417
Joined: Wed Sep 18, 2013 9:10 pm
Location: Pittsburgh PA

Re: MakeCode: why no yaw for accelerometer?

Ah, I see what you're asking. The LIS3DH sensor on the CPX is only a 3-axis accelerometer. It doesn't have a gyroscope, which would give you rate-of-change of yaw, or a magnetometer (compass), which would give you absolute yaw. It can't detect rotation normal to gravity with just an accelerometer.

https://robotics.stackexchange.com/ques ... -gyroscope
https://www.quora.com/Why-an-Accelerome ... easure-Yaw

danhalbert

Posts: 2139
Joined: Tue Aug 08, 2017 12:37 pm

Re: MakeCode: why no yaw for accelerometer?

So, yes, you'll need to mount it vertically to get yaw. But if the robot is running on a flat surface, I think that would be OK, since you don't need one of the other axes in that case.

Re serial output: Feel free to open a new thread about that. I myself have had trouble with serial output on MakeCode, but I gave up perhaps too soon.

danhalbert

Posts: 2139
Joined: Tue Aug 08, 2017 12:37 pm

Re: MakeCode: why no yaw for accelerometer?

there is an option called "rotation", which suggests that accelerometer data is being processed into pseudo-gyroscopic data. I can't tell for sure what it is, because I am unable to get serial data so the attached program does nothing useful.

Note that I want to add blocks

set yaw to rotation (°) yaw
console log value "yaw" = yaw
Attachments
Screen Shot 2018-01-29 at 6.46.39 AM.png (47.17 KiB) Viewed 718 times

flounder

Posts: 417
Joined: Wed Sep 18, 2013 9:10 pm
Location: Pittsburgh PA

Re: MakeCode: why no yaw for accelerometer?

Rotation out of the plane of the earth can be detected. That changes the gravitational forces on the three sensors in the LIS3DH. However, slow rotation such as on a flat tabletop parallel to the ground can't be detected, because there's no change in the gravitational force on the sensors. That's why there's no yaw in the dropdown. Maybe you could detect a jerkiness if you did a sudden rotation, but you can't get any useful heading information out of that.

The comments in the link above (https://robotics.stackexchange.com/ques ... -gyroscope) explain why yaw isn't available.

danhalbert

Posts: 2139
Joined: Tue Aug 08, 2017 12:37 pm

Re: MakeCode: why no yaw for accelerometer?

Sigh. I would have thought that the force vector representing the sideways thrust of a turn (especially on a flat surface) would have been detectable. Well, back to the \$34.95 9DOF Fusion unit (#2472). Is there a MakeCode block for that?
joe

[As a small-plane pilot and a large-plane passenger, I can testify that a badly-coordinated turn definitely applies a sideways acceleration component. It isn’t always pleasant, because our vestibular systems do not handle sideways acceleration well. I was in a 727, and it was the only time I recall ever reaching for the barf-bag. I didn’t need it, but I was close. The fact that it was a 727 tells you how long ago this was.]

flounder

Posts: 417
Joined: Wed Sep 18, 2013 9:10 pm
Location: Pittsburgh PA

Re: MakeCode: why no yaw for accelerometer?

You can probably detect the jerk of a significant change in heading, but not a slow smooth turn, and it's not going to be accurate enough for anything. Think about the case, for instance, where there are mechanical inaccuracies that make it drift left or right all the time, such one wheel slightly larger than the other or the motors not working perfectly in sync.

My comment about mounting it vertically is wrong, of course, since it's still normal to gravity.

There are no blocks for external sensors, but there is general I2C support under the Pins menu.

Could you try some other way of sensing heading, like homing on a bright light or sound or following a line?

danhalbert

Posts: 2139
Joined: Tue Aug 08, 2017 12:37 pm

Re: MakeCode: why no yaw for accelerometer?

We do have cheaper 9-DOF sensors: https://www.adafruit.com/?q=9-dof

danhalbert

Posts: 2139
Joined: Tue Aug 08, 2017 12:37 pm