XRobots / openDog

CAD and code for each episode of my open source dog series
GNU General Public License v3.0
830 stars 189 forks source link

Early bail instead of nested "if" makes it a bit easier #9

Open ApanLoon opened 6 years ago

ApanLoon commented 6 years ago

This looks huge but only the top few lines of "loop" are actually changed - the rest is just indentation.

P.S. I can not test this code as I don't have the hardware, but it compiles and should be correct. Make sure you test before merging - if you even want to merge.

XRobots commented 6 years ago

Thanks for this, but I don't have time to test it right now, we'd also need to make the same edits to slave02 which uses different data set names and different physical pin numbers. I've also made further changes to the code because I'm working on the next episode right now.

Ideally I'd like to get the bulk of the work done and get the robot functional before accepting contributions - there will be plenty of clean up to do then ;-)

ApanLoon commented 6 years ago

Right. I will keep making some changes to my forked repo. If you want to and have time, you can always check my commits, incorporate them manually, ask me for merge requests or ignore them completely. ;-)

The latest makes it easier to edit for Slave02 - using #defines at the top for all the pin numbers.

ApanLoon commented 6 years ago

I made a big change that removed a lot of the copy/paste code. A separate function for finding the end stop of one actuator. This is then called from the various states. However, some things were done differently for the undercarriage actuators and some of those differences are now gone. I am not 100% certain that I understand exactly what is going on there, and I fear that I need the full robot to actually understand it completely. Even if my latest commit isn't altogether correct, maybe the idea can be adopted to the original code.