Arduino firmware - Custom functions for CAN bus based encoders


#1

Hello everyone,

I am currently building our Farmbot and have opted to use a slightly different set up with independent encoders, rather than motor shaft mounted ones. It is most similar to Genesis V1.2 I guess, in that I am utilising the RAMPS 1.4 shield, but most of the hardware is closer to Genesis V1.3.

In order to overcome the limitations of multiple encoders on the same master Arduino, I have made a few standalone controllers that are connected locally at each encoder and track the position internally. These can communicate the current position back to the master over CANbus when requested.

My stand alone bench tests all work well, each remote can update the master when needed, but I am having trouble integrating this into the farmbot arduino code. I have gotten a lot of it written in well enough, but it all falls apart when the interrupt routine is created (not just called). Even if the ISR is empty, the timer associated with millis() stops working, and as such the program is kind of halted there.

My ISR is for handling incoming communications, as the internal message buffer of the CANbus chips I have used (MCP2515) are very small, and I have decided to pull these messages into a software buffer as quickly as they come. The ISR keeps responding to messages even if millis() if stopped. This behaviour is not present on the bench unit, the only difference is the additional farmbot firmware along side it.

I’m kind of stuck here and don’t know what to do next. Is there a function in the stock farmbot firmware which modifies this timer, and then my code interferes? I am happy to share all of the code and designs I have made for this modification, just let me know the best way to upload.

Any help on the matter would be greatly appreciated.

Cheers,
Andrew.


#2

OK, so I made a workaround to the problem above. I dug through the CANbus library I was using and replicated the interrupt functionality, but without the actual interrupt. I now poll the master CANbus module every loop to see if there are any new messages. This worked well, and we are just powering on our Farmbot for the first time today to test it all. Fingers crossed.


#3

All crossed, too, down in the Melbourne 'burbs :crossed_fingers:
I’m waiting to buy a Farmduino v1.4 board before I get to the sort of refinement that you’re doing !


#4

Hi jsimmonds, nice to see another Aussie lurking in here too. Just an update if anyone is interested, the new CANbus encoder system works really well but I’ve got some other trouble driving the stepper motors. I’m sure I’ll get to the bottom of that issue soon, but it was nice to know that the farmbot was able to track it’s location well when moving the axis by hand. A few more tweaks with scaling to get it accurate is needed though.

I’ve forked the Github farmbot firmware and am keeping it updated as I make changes to suit. I’ll put the remote module code in there soon as well if anybody would like to try it out. Maybe if the dev team at farmbot like my additions it could be merged in. Who knows…