Minor comment error fix and speed_byte mapping fix.#16
Minor comment error fix and speed_byte mapping fix.#16bwshockley wants to merge 4 commits intoRailstars:masterfrom
Conversation
Fixed typo in line 13; The end_bit for the DCC packet is a "1"
The original operation would often give me "-1" near the top value of speed_byte instead of 127.
|
Could you say more about the errors? I was seeing some interesting speed errors at the high end of things—directing a train to move faster than some value would produce erratic results. I have no doubt this line is specious, but I would prefer not to use |
|
There is a better way to do this. Consider this snippet:
So, the whole procedure is just wrong. For now, let's forget the speed of |
|
I will recreate the errors first and attach the output here. Then I will try the new method. I made another change that I will also post. |
|
I made a few modifications to the original - mostly troubleshooting lighting functions, optional pins for enabling and braking the LMD18200 - not yet implemented, and finally the speed/direction. I realize in my setup, it is possible to change a loco direction with the speed still at full, not really idea, but possible. I didn't like trying to find the magic stopping point. You and I came up with the same "dead_zone" concept, just different method. I'm not a coder by trade, so I'm sure my stuff is not elegant or efficient, but it got me there. :) |
|
Oh yeah, this demo code uses a single pot, with no direction switch—turn to the right, move forward, turn to the left slow, then start moving in reverse. I wanted to keep the hardware requirements dead simple. |
|
Hmm, I like your proposal as you have a set constant for the "dead_zone". Looking into it, dead zone ends up being 9 analog values wide. I like it. I might modify it a bit to increase that to 10 values - but your method is great. |
|
Howdy! Did you ever update your code? Can you either push to this PR or generate a new one? |
Updated the dead_zone to span the middle 10 values (as written 506 - 516) and map them to -127 to -2 and 2 to 127.
|
I think I should remove my "Direction" code and go back to the minimum you started with - just a single pot to control speed and direction. Back on topic though, and the original reason I started using map instead of the bit shift was that bit shift to the right by 2 produces a speed value of 128 at 1023 which caused errors. What we need to produce is something between -127 and -2 as well as 2 to 127 for actual speeds. Based on what you wrote back on July 4 - we are going to ignore e-stops. I tweaked your code a bit, but it works well. |
Updated conditional statements to match mapping code.
The first commit is a minor one in which the comment incorrectly stated the end_bit is a 0, when it is a 1.
The second commit I found to be a more robust method of assigning the speed_byte based on the 0-1023 analog input values. I found the first method was producing errors for me.