Thank you very much I will try this one out because I’m not to confident in my efforts using pokitto, I’ve got 27x 1 /4 tires how close to the rim do you recommend putting the sensor?
The distance from the rim should not matter because we are measuring revolutions
Your fixed point library has definitely influenced how my implementation has changed over time. That internal type class trick is one of the things. I previously had one private constructor and public named constructors for different types, like fromInt(), fromFloat() and fromInternal(). But that made the code that used fixed points a bit difficult to read.
Yes, that’s correct.
ok, so I just plug in the size of the rim (27 inch) there isn’t a prompt for that is there?
on your GitHub what do I download and change to make ti work for me?
BTW I just downloaded it and installed it on Pokitto, and is ti really nice, almost exactly what I wanted lol. it is a little metricey but I can probably handle that, I presume it is currently set for a 700 c rim
the diameter for a 27 is 630 mm and 622 for a 700c if its too much trouble I can live with an 8 mm difference
ok, so I calculated it and your rim is 2100 mm and men is 2153
honestly changing the rim size is kinda nit picking though Id like to understand how to do it,
only real change I could see needing was a metric to whatever you call the us system for speed and distance,
Fair enough. I would have appreciated a bit of recognition though.
(Also the default constructor initialising the internal value to 0 is a bad idea,
that’s on the list of things to fix in my implementation.
At the time I went for it because I wanted to make it simple for beginners,
but I later realised it had a hidden cost.)
If I remember rightly, that was inspired by Arduino’s
(If I were to do it again though, I’d consider using tag distpatching.)
This is where argument overloading comes in useful,
you could have just had
from(float) et cetera.
A proper constructor is certainly the more expected option in C++ though.
Given that I’m still half clueless with hardware,
how exactly does the sensor work?
Does it track the sensor’s orientation and count how many times it achieves a particular orientation?
Does it count the spokes? (That’s how some mouse wheels work.)
Its a reed switch (mechanical old tech) or a HAL sensor (modern semiconductor tech). Magnet passes, reed switch closes = pulse made, or HAL sensor makes a small electric current = pulse made.
Then just the pulses are counted vs. real time clock = revolutions per minute
rpm * circumference of wheel = speed
You mean a Hall effect sensor?
.gif is really nice. Sometimes a picture is worth a thousand words.)
In which case, yes, only time and a pulse count are needed for actually counting revolutions,
but the wheel/tyre circumference is needed for measuring distance travelled.
Yes a Hall effect sensor
2001: a Space Odyssey had a too big effect on me
I made a special US-version that displays speed and distance in miles.
Source code and binary: Cyclometer-US.zip (55.4 KB)
Below is a picture showing how to easily measure wheel circumference. Did you find the line where to enter the value in ‘Cyclometer.h’?
static constexpr uint32_t CIRCUMFERENCE = 2153; // millimeters
Technically Britain also still uses miles. (Especially the older generations.)
Let me guess, no pun intended?
At any rate, the recognition is much appreciated.
One last piece of unsolicited advice:
If you’re using
<cstdint>, you should make sure to qualify
cstdint is guaranteed to declare
std::uint32_t (& co) in the
but not required to declare
::uint32_t (& co) in the global namespace.
stdint.h is guaranteed to declare
::uint32_t (& co) in the global namespace,
but not required to declare
std::uint32_t (& co) in the
It’s possible that one day you’ll run into a version of
<cstdint> that doesn’t bring
uint32_t (& co) into the global namespace,
and technically that version of
<cstdint> will be 100% correct.
(The same is true for any other
Ok, so that’s why compiler doesn’t give me errors about it now.
Do you mean it was giving you errors/warnings?
(If so, that’s a good compiler you’re using.)
Or do you mean that it isn’t giving you warnings and you were wondering why I was telling you about something the compiler isn’t reporting?
I mean I would expect it to give me warnings but haven’t ever seen that happen. I used to use the std namespace but if the compiler doesn’t care then why should I. Now I know.
There’s probably several reasons (or perhaps ‘excuses’) for why compilers don’t check,
some of which are probably part of why it works in the first place
(after all, it’s usually the compiler vendor that provides the standard library implementation).
It’s not the only reason to prefer to fully qualify names though,
just one of the ones people tend to be less aware of,
probably precisely because compilers tend to let people get away with it,
and people tend to assume that if their compiler allows something then it’s probably legal/standard.
Tangentially related anecdote
I got bitten once by GCC allowing non-standard code.
I had a load of
reinterpret_casts stuffed into
constexpr functions/contexts and I didn’t realise it was illegal until I tried to compile for a different platform.
Technically it was partly Arduino’s fault for using
but even so, it just goes to show that the compiler isn’t always right.
Very cool, I have no idea how to compile the code for pokitto though.
You can try FemtoIDE, for example. That’s what I’m using.
Once you have that installed, just unzip the cyclometer code into FemtoIDE/projects/Cyclometer folder, start FemtoIDE and choose Cyclometer project from the list.
Here’s the modified design. The axles don’t go through the Pokitto connectors as easily as you’d think though. Fitting is really tight and I think the bush parts at top of axles are not actually needed. I haven’t done any field tests yet because of this exceptionally warm and wet winter/prolonged autumn, but the design feels secure and removing Pokitto is slightly easier and smoother than with the pegs.
Another option, don’t know if you have them, is the small rod like pieces that are smooth, like used for the StarWars Lego Lightsabers.
I don’t have those, but that could also work. It seems that there is even a part that connects technic axle and a rod in 90 degree angle, so it would nicely attach to the horizontal axles.
I know it’s asking a lot how do I use it? Is all the code in one lump or small parts?
I’m not sure I understand what you are asking. The cyclometer code is divided in several files.