PID -Hardware needed for a software fix

New Home Forum Mostly Printed CNC – MPCNC Hardware Development – MPCNC PID -Hardware needed for a software fix

Tagged: 

This topic contains 474 replies, has 31 voices, and was last updated by  Ryan 5 days, 1 hour ago.

Viewing 30 posts - 61 through 90 (of 475 total)
  • Author
    Posts
  • #52884

    Jeffeb3
    Participant

    So each interrupt runs independently of each other and the main loop?

    Check.

    #52928

    Ryan
    Keymaster

    AHHHHAHAHAHAAHHHHHH dang it. I could not figure out the led situation forever. I have a photodiode, tested it with the meter, seems good, a bag of 200 UV leds and all sorts of other ones. Nothing worked. My buddy sparked a lighter at it…works, like works in the rpm code even. So I can only guess that they were not a matched pair as in my photodiode isn’t tuned to the same 395nm as my UV LED’s? Ordered the matched set from the instructables article, so on hold until Tuesday.

     

    #52948

    Mike
    Participant

    Awesome, awesome progress man! I’m really happy with the Makita so far with it’s manual speed range settings, but I would definitely look at giving this a try once it gets developed.

    #52949

    Ryan
    Keymaster

    As far as I know anything with a built in speed adjust has to be hardwired without it. I have no idea if just setting it to 100% works but I will look into it more when/if this works.

    #52951

    Nate
    Participant

    I have one Makita and two of the copycat Rocky 30 routers, I’m willing to take one apart and try this in the name of progress!

    1 user thanked author for this post.
    #52969

    Jeffeb3
    Participant

    As far as I know anything with a built in speed adjust has to be hardwired without it. I have no idea if just setting it to 100% works but I will look into it more when/if this works.

    Yeah, this is interesting. I wish I knew more about it. There’s an interesting story there. I imagine it like two pairs of polarized sunglasses, varying in phase, but I doubt it’s that simple.

    #52973

    Ryan
    Keymaster

    Holy cow, have you seen what happens with three polarizing filters?? Blew my mind. I gotta find it.

    #52974

    Ryan
    Keymaster

    Sorry for going off topic but that doesn’t sit right with me.

    #52977

    Jeffeb3
    Participant

    So, as long as you put another Triac in there, it will be fine.

    #52979

    Ryan
    Keymaster

    Maybe right, All those semesters of physics….I feel like I was lied to. So crazy.

    #53168

    Ryan
    Keymaster

    Okay the RPM seems to be getting read but the numbers are off by what I would guess is 10k rpm meaning what I would expect to be 30k is reading as 40k dirty signal though, pretty dam hard to get a good reading. I am going to grab a optical tachometer from HF to try and verify some numbers.

    #53172

    Ryan
    Keymaster

    The optical is giving me 20, 400 to 29,500 with my store bought speed control. Sweet numbers to work with and even it works best at an angle and not straight on.

    #53174

    Jeffeb3
    Participant

    Are you timing rising edge to rising edge? Rising edge to falling edge would have more error, I think.

    I’m not sure what you meant in your second post.

    #53175

    Ryan
    Keymaster

    Sorry, I was kinds jotting down notes/making an update.

    rpm

    I don’t think optical reflection is that safe of a indicator. The clean reading point is small and I think ambient light has a lot to do with the interference. I would much prefer an optical encoder style disk. I have nice pre-made all in one sensor and receiver boards and I think that is going to be a much cleaner signal. Hopefully a disk can be 3D printed, but there are tons of issues with that as well. http://amzn.to/2EvyBDp

    The second message was just me buying an actual rpm tool and verifying the readings.

    Another option would be to put a dot on the cooling fins of the 660 and get the readings from that. It is dark and a better target but the dust build up would probably make it a bad choice.

    Attachments:
    #53178

    Ryan
    Keymaster

    The comments are just me keeping notes. Using unsigned long just in case there was some sort of math error but a volatile word is the correct option here I think.

    #53179

    Ryan
    Keymaster

    Dang it…I see what I did wrong there, that is still for pwm timing. I just need time between falling. Explains the 10k RPM off, doen’t fix the crappy signal.

    #53182

    Ryan
    Keymaster

    Using the sensor board and the encoder the readings are super consistent, +- 10-15rpm @20k with many repeat readings! Super sketchy holding a router with a spinning disk and a small pcb in both hands…

     

    Attachments:
    #53185

    Jeffeb3
    Participant

    Are you wearing safety squints?

    https://gist.github.com/jeffeb3/9cd8c6958de6293345c6e3f369b74684

    You can use just the one callback to handle the RPMs. If you don’t have a good reason not to, just use ints for any integers. Bytes are mostly just for storing characters and words aren’t really used for anything.

    The next thing we could add, since we are literally getting a measurement every 3ms, is to do some low pass filtering. It will make the response slower, but the reading smoother:

    smoothed_rpm += ALPHA * (rpmmath - smoothed_rpm);

    ALPHA goes from 0-1, at zero, the value never changes, at 1.0, it just copies the input. For this math, you need to just use floating point numbers.

    #53187

    Ryan
    Keymaster

    It took me a while to understand the other ISR(? void functions). I kept think how the heck is this doing three freaking loops at the same time. About and hour ago it clicked. Only the void loop is looping, the other two ISR(?) are running once (independently, I get that) and calling each other perpetuating a loop only if the interrupt triggers a falling condition. I kept thinking the loops where piling up or something.

    I feel like such a schmuck but it has been a while for fresh coding and never involving interrupts.

    I understand your code and need to try it. I had already realized the need for long’s.

    This is pretty fun, I do like the logic part of it. I couldn’t work out how to get the two different times in the same ISR(?) your solution makes total sense.

    So how does the time work (micros), is there ever a need to zero it out? I mean 8 hours or run time could result in a giant number. Will it roll over at some point? I kept trying to loop it and zero it out each loop.

    This is weird that I have questions but not the right language to ask it in. Fascinating, really, I feel like I am on a bus in a foreign country and don’t know the language. I know what I want just not how to ask properly. Each little piece of info is a minor triumph.

    #53193

    Jeffeb3
    Participant

    Aargh. I had a big post and somehow deleted it while trying to format the code in it. Did it email itself to you?

    #53198

    Ryan
    Keymaster

    Yeah I got it. Quoted below so everyone can see the info.

    So how does the time work (micros), is there ever a need to zero it out?

    It is an unsigned long, which is 2^64 on an Arduino, I think. It starts at zero when the processor boots. 2^10 is 1024, so you have about 2^44 seconds. There are 525,600 minutes in a year (thanks Rent!). So 30M seconds/year. So that’s about 2^19 years? I wouldn’t worry about it. The brushes on the dewalt are not going to last as long as those 64 bits.

    This is weird that I have questions but not the right language to ask it in.

    It really is strange. Anthropologists should be studying the whiteboard meetings between software engineers. I would really like to know why some things are so easy to explain in programming but hard in English. Plus, when you’re starting out, you don’t know what the algorithms are called.

    Glad you’re enjoying it. Just remember how many hours you have burned in CAD and design and don’t expect to immediately have success in software. It takes practice, like anything else. I’ve put in my 10,000 hours, but I still have to look stuff up all the time and the computer is constantly complaining about my work. 🙂 You’re doing great already.

    Only the void loop is looping

    The loop() is an Arduino specific thing. I don’t know why they did that, but normal c++ doesn’t have a setup or loop. In Arduino, they basically add this to the very end of the code:

    int main()
    {
    setup();
    while (true)
    {
    loop();
    }
    }

    ISR is an “interrupt service routine”. And that tells you exactly what it does. The hardware actually stops execution of the main code, and goes to “service” that interrupt. The ISR is running whenever the physical hardware senses the change, and it stops whatever else is running. That’s why you don’t do much work in the ISR, because nothing else is happening as long as it’s running (including other ISRs). So when the hardware detects that falling edge, it will quit printing to the serial port (as an example), and copy the micros out. If you were doing something really slow, then it might miss timing on the serial port or something. The attach call resets the interrupt to fire again. I moved it to the end because I’m paranoid, but you don’t want the interrupt to fire while your still in the ISR.

    #53199

    Ryan
    Keymaster

    Everything I know about programming I learned from arduino’s build in examples, and you! Even the crazy programming courses I had to take in school were not broad focus, it was more about how to program an equation. Excel is harder to do math in and we had to learn that in Chemistry 1.

    This Interrupt thing, feels like you gave me a key to something huge. Again a million thanks for your patience and guidance.

    Back on track.

    The encoder disk is such a clean signal I don’t it is even worth it to try to do it any other way. I will continue with it and the other way will always work if we can figure out a better way with the reflection thing. The reflection is also picking up a ton of electrical noise so it needs some sort of filter. This was mentioned in the Instructables thing about his OLED. So far the encoder board is clean and I feel much safer way to play with mains power control.

     

    #53213

    Todd Hansen
    Participant

    Just wanted to say I like the work you are doing on the speed controller.

    Keep up the good work.

    1 user thanked author for this post.
    #53215

    Ryan
    Keymaster

    MVIMG_20180216_124019
    No, it is not the final design, this is just to keep my fingers a little further away. The actual mount will need to get tucked in real good and be able to swing out of the way I think, I would love just epoxy a disk to the top end of the shaft.

    Now….let the real programming begin. First a little speed control test. Might try top get a video snippet of it. Then figure out some PID stuff.

    #53222

    Ryan
    Keymaster

    Crap, Sh%t, #$%^&#$%^*(V @#)#%$*@#.

    I think the speed control died. I have no idea what happened. Tried to put the 660 on it, nothing, and then out of the blue full speed. Nothing but full speed since. I guess that was the wrong part.

    #53227

    Ryan
    Keymaster

    Even with the control powered off it is still running the power and it didn’t do that before. I really have no idea what happened but I ordered new triacs for that board, and a new board.

    https://www.tindie.com/products/thewp122/ac-60hz50hz-dimmerssr-controller-board/

    And I got a face full of that encoder while while it happened, so that isn’t a good idea.

     

    #53232

    Jeffeb3
    Participant

    Whoa! The encoder flew off or your printed part?

    If you can dodge an encoder, you can dodge a ball.

    Maybe we have to go back to the HF speed control with a servo moving the knob.

    #53233

    Ryan
    Keymaster

    Maybe we have to go back to the HF speed control with a servo moving the knob.

    BOOOO! Maybe, but I am not giving up so quick. That board though, I do not like how it dies wide open….It could have been my fault I used two different outlets, maybe I was on separate circuits?

    The printed part popped in half. I knew the split design wasn’t the best idea but it was fast to CAD. Got my hand and my face….Safety squints from now on. You tried to warn me.

    #53488

    Ryan
    Keymaster

    The new triacs work! So just tested the simple speed control for the rambo, M3 s15000 and m4, work! The router spins at real low power even, of course I haven’t test the strength but it is promising).

    It is a bit disturbing though when I plug in the dewalt to the triac board I do get a usb disconnect and reconnect…..powered off. I will leave it alone for now because of the rat nest of wires could be an issue and I can just say before turning anything on make sure the router is plugged in.

    So back to integrating the encoder side.

    #53490

    Ryan
    Keymaster

    Okay the speed sensing and speed control are on the same nano and working. That is a great step.

    So we have a gas pedal and a speedometer. Now refine the logic a bit, and then start working on the cruise control (PID).

Viewing 30 posts - 61 through 90 (of 475 total)

You must be logged in to reply to this topic.