IEEERobotics / bot

Robot code for 2014.
BSD 2-Clause "Simplified" License
18 stars 11 forks source link

PRUs for ultrasonics #69

Closed dfarrell07 closed 10 years ago

dfarrell07 commented 10 years ago

The US sensors should be managed by the PRUs on the bone, to achieve very high read speeds and be sure that the Linux scheduler doesn't cause timing problems. @PaladinEng is working on this.

dfarrell07 commented 10 years ago

@PaladinEng - How's this work going? Update?

For the sake info-sharing, I consider this issue a moderate but growing risk. There's a lot of unvalidated work to be done, and it's on the critical path for localizer.

PaladinEng commented 10 years ago

I have not touched it since my last progress report. I'll pick it back up after my last exam (tomorrow), when we all meet next, at the latest.

On Mon, Dec 16, 2013 at 11:52 PM, Daniel Farrell notifications@github.comwrote:

@PaladinEng https://github.com/PaladinEng - How's this work going? Update?

For the sake info-sharing, I consider this issue a moderate but growing risk. There's a lot of unvalidated work to be done, and it's on the critical path for localizer.

— Reply to this email directly or view it on GitHubhttps://github.com/NCSUhardware/bot/issues/69#issuecomment-30726167 .

dfarrell07 commented 10 years ago

I have not touched it since my last progress report. I'll pick it back up after my last exam (tomorrow), when we all meet next, at the latest.

@PaladinEng - How's the PRU work going?

Note that I've upgraded this to a high priority issue, for the same reasons I mentioned previously on this thread.

PaladinEng commented 10 years ago

The PRUs are still not working, but they are supposed to be.

I'm following this guide: http://www.element14.com/community/community/knode/single-board_computers/next-gen_beaglebone/blog/2013/05/22/bbb--working-with-the-pru-icssprussv2#comment-22613

and this: https://github.com/jadonk/validation-scripts/tree/master/test-capemgr

Specifically, I'm at the step where: echo cape-bone-pru > $SLOTS cat $SLOTS

is giving me this error: -bash: echo: write error: No such file or directory

but should be giving me this: 0: 54:PF--- 1: 55:PF--- 2: 56:PF--- 3: 57:PF--- 4: ff:P-O-L Bone-LT-eMMC-2G,00A0,Texas Instrument,BB-BONE-EMMC-2G 5: ff:P-O-L Bone-Black-HDMI,00A0,Texas Instrument,BB-BONELT-HDMI 6: ff:P-O-L Override Board Name,00A0,Override Manuf,BB-BONE-PRU

Jeff and I spent time this evening tying to trace the problem. It looks like the file BB-BONE-PRU is linked to cape-bone-pru-00A0.dtbo but that file does not exist. The linkage is specified in am335x-boneblack.dtb

So, right now I'm searching for more information, and posting in threads for help. Trying to get more information on this missing overlay file.

dfarrell07 commented 10 years ago

Okay, thanks for the update. Glad to see you're working on it, even if the progress is difficult. Also I strongly suggest continuing to work with @jschornick as he has time, since he has a great skill combo to help with this.

PaladinEng commented 10 years ago

PRU is now enabled and working. Now working on writing assembly code to trigger ultrasonics and report values

dfarrell07 commented 10 years ago

Awesome! Big milestone in that domain! On Jan 9, 2014 8:37 PM, "Alwyn Smith" notifications@github.com wrote:

PRU is now enabled and working. Now working on writing assembly code to trigger ultrasonics and report values

— Reply to this email directly or view it on GitHubhttps://github.com/NCSUhardware/bot/issues/69#issuecomment-31995831 .

PaladinEng commented 10 years ago

Found a git repo using the PRU to activate the exact same ultrasonics we are using. https://github.com/Teknoman117/beaglebot/tree/master/hcsr04-demo Studying it now to figure out how it works and how we can alter it to trigger 4 ultrasonic sets.

R00ney commented 10 years ago

Nice! Achievement Get: Standing on the shoulders of others!

Neal

On Fri, Jan 10, 2014 at 11:24 AM, Alwyn Smith notifications@github.comwrote:

Found a git repo using the PRU to activate the exact same ultrasonics we are using. https://github.com/Teknoman117/beaglebot/tree/master/hcsr04-demo Studying it now to figure out how it works and how we can alter it to trigger 4 ultrasonic sets.

— Reply to this email directly or view it on GitHubhttps://github.com/NCSUhardware/bot/issues/69#issuecomment-32041565 .

JobenNC commented 10 years ago

Hey guys, sorry I've been so terrible about actually getting over to the meetings. I've been chatting with Alwyn and I'm hoping that I can contribute a little to this project. If the PRUs have been accessed, what's the current bottleneck?

PaladinEng commented 10 years ago

The problem now is simply that I don't have time to work on it, rather than a technical or learning hurdle. There is example code here: https://github.com/Teknoman117/beaglebot/tree/master/hcsr04-demo which explains how to get one ultrasonic up and running, and I got it working.

From that code all that's left is: 1) modify the device tree fragment file (attached) to select the correct pins and modes. 2) modify the assembler code (from the repo above) to cycle through or simultaneously trigger and count 4 ultrasonics instead of one. 3) modify the c code to (from the repo above) to grab 4 variables from memory instead of one.

The device tree file I've attached lists the pins and modes that need to loaded in the device tree overlay

I am free today after 3:30 for a more detailed discussion/project handoff to walk through it. Now that the BBB I was using is not bricked after all, it should be easy to walk you through the execution basic steps. I assume that Daniel put it in one of the lockers?

On Wed, Feb 5, 2014 at 9:22 AM, Joseph Jarriel notifications@github.comwrote:

Hey guys, sorry I've been so terrible about actually getting over to the meetings. I've been chatting with Alwyn and I'm hoping that I can contribute a little to this project. If the PRUs have been accessed, what's the current bottleneck?

Reply to this email directly or view it on GitHubhttps://github.com/NCSUhardware/bot/issues/69#issuecomment-34176286 .

dfarrell07 commented 10 years ago

I assume that Daniel put it in one of the lockers?

Yeah, it's in locker 43.

I am free today after 3:30 for a more detailed discussion/project hand-off to walk through it.

Depending on when this is, I might tag along. Let @JobenNC and @jschornick's schedules drive the time, however.

jschornick commented 10 years ago

My schedule has been 100% tied up with a conference paper which will be submitted tonight. After that, I should be able to fully return my attention to DMS and PRU issues.

If anyone meets with @PaladinEng today be sure to record detailed notes of all the steps and commands necessary to replicate the current state that are not explicitly described in this issue. Notes could be either a wiki page or a text file in git, but just make sure it's linked here somehow.

dfarrell07 commented 10 years ago

I suggest waiting on the brain dump until Jeff can make it. He's a major stakeholder (you rock Jeff!).

Good luck on the paper. :)

JobenNC commented 10 years ago

I won't be able to meet up with anyone today. Jeff, would you happen to be around NCSU tomorrow morning?

PaladinEng commented 10 years ago

I'll be in tomorrow by 9:30. Look for me in the fishbowl. Who can meet me then?

Sent from my iPhone

On Feb 5, 2014, at 3:07 PM, Joseph Jarriel notifications@github.com wrote:

I won't be able to meet up with anyone today. Jeff, would you happen to be around NCSU tomorrow morning? — Reply to this email directly or view it on GitHub.

jschornick commented 10 years ago

Assuming I get to bed before 4:00a for once, I should be able to meet tomorrow morning.

JobenNC commented 10 years ago

I'll see you there, Alwyn!

On Wed, Feb 5, 2014 at 4:22 PM, Jeff Schornick notifications@github.comwrote:

Assuming I get to bed before 4:00a for once, I should be able to meet tomorrow morning.

Reply to this email directly or view it on GitHubhttps://github.com/NCSUhardware/bot/issues/69#issuecomment-34248154 .

dfarrell07 commented 10 years ago

I see that @jschornick added tons more PRU documentation to the wiki. Awesome!

Who's actively working on this now, @JobenNC and @jschornick?

JobenNC commented 10 years ago

I'm planning on working on it. I'll take a look at the recently added documentation in preparation for the meeting tomorrow.

Joseph Jarriel

On Mon, Feb 10, 2014 at 9:00 PM, Daniel Farrell notifications@github.comwrote:

I see that @jschornick https://github.com/jschornick added tons more PRU documentation https://github.com/NCSUhardware/bot/wiki/PRU-Informationto the wiki. Awesome!

Who's actively working on this now, @JobenNC https://github.com/JobenNCand @jschornick https://github.com/jschornick?

Reply to this email directly or view it on GitHubhttps://github.com/NCSUhardware/bot/issues/69#issuecomment-34719776 .

JobenNC commented 10 years ago

Update:

My wife has a pretty rough case of the flu, so I'm going to stay home tonight to help her out. I will, however, try to see if I can turn some of Jeff's notes and Alwyn's previous work into some kind of proof of concept this week. At the very least, I'll hopefully be able to add something to the wiki.

Joe

On Mon, Feb 10, 2014 at 10:12 PM, Joseph Jarriel jmjarrie@ncsu.edu wrote:

I'm planning on working on it. I'll take a look at the recently added documentation in preparation for the meeting tomorrow.

Joseph Jarriel

On Mon, Feb 10, 2014 at 9:00 PM, Daniel Farrell notifications@github.comwrote:

I see that @jschornick https://github.com/jschornick added tons more PRU documentation https://github.com/NCSUhardware/bot/wiki/PRU-Informationto the wiki. Awesome!

Who's actively working on this now, @JobenNC https://github.com/JobenNCand @jschornick https://github.com/jschornick?

Reply to this email directly or view it on GitHubhttps://github.com/NCSUhardware/bot/issues/69#issuecomment-34719776 .

dfarrell07 commented 10 years ago

Okay, thanks for the update. Hope she feels better.

Are you at the point where you can replicate @PaladinEng's ability to read a single ultrasonic with a PRU? As a quick iteration, just figuring out how to do that for each ultrasonic seems reasonable (changing whatever addresses need to be changed). Then a simple copy+paste and address swap to read all 4?

jschornick commented 10 years ago

If @JobenNC isn't swimming in success in the next couple of days, I'll pick this up again once #84 and the I2C work of #70 are done.

Definitely keep at the wiki. It was mostly an information dump from Alwyn, and needs to be cleaned up as we go through the process of reproducing workng PRUs. Once it's solid, I'll encode the resulting PRU-enabled environment into the low-level BBB setup we do for the bot.

JobenNC commented 10 years ago

Hey guys,

I probably won't be swimming in success very soon. :-/ I've picked up a couple of new assignments at work that require some studying on my part, and I'm helping my wife put together a project that she needs done by the end of the month. Realistically, I probably will only be able to work on Tuesdays or Fridays at meetings. I still find the PRU project interesting, but if there's something else that I would be of more use doing with my limited availability, I'm open to that.

Sorry for not figuring this out sooner, Joe

On Tue, Feb 11, 2014 at 3:32 PM, Jeff Schornick notifications@github.comwrote:

If @JobenNC https://github.com/JobenNC isn't swimming in success in the next couple of days, I'll pick this up again once #84https://github.com/NCSUhardware/bot/issues/84and the I2C work of

70 https://github.com/NCSUhardware/bot/issues/70 are done.

Definitely keep at the wiki. It was mostly an information dump from Alwyn, and needs to be cleaned up as we go through the process of reproducing workng PRUs. Once it's solid, I'll encode the resulting PRU-enabled environment into the low-level BBB setup we do for the bot.

Reply to this email directly or view it on GitHubhttps://github.com/NCSUhardware/bot/issues/69#issuecomment-34802463 .

jschornick commented 10 years ago

Starting work on this now. Will update once I have something working in my testbed.

jschornick commented 10 years ago

It took longer than I had hoped, but I think the PRU interface to the ultrasonics looks good. Do to some changes in the PRUSS library, bugs in the PRUSS library, and key differences in physical implementation of the demo code, there was quite a bit of learning and hair pulling involved.

Long story short is I have one HC-SR04 sensor returning what appears to be very accurate distance measurements to a C program. Setup on the bone side is highly simplified, and no longer requires device tree changes.

Current work is in my PRU branch: https://github.com/NCSUhardware/bot/tree/pru

Next steps for Friday:

One question for @R00ney and @jfic -- is the current ultrasonic wiring going through a logic level converter? The trigger signal is fine straight through, but the echo signal is 5V from the sensor (and needs to be stepped down).

R00ney commented 10 years ago

There is no logic level converter. Worst comes to worst, I "should" be able to build four 5 to 3.3V converters from bjts and resistors, just like the wolfbot dmc board.

jschornick commented 10 years ago

PRU assembly code modularized and now reading two ultrasonics simultaneously(*). A sample of the success:

0231 :
       Pre-pulse (count) = 2065
       Pulse (us) = 1197
       Distance = 20.37 cm
       Distance = 8.02 in

       Pre-pulse (count) = 2072
       Pulse (us) = 1617
       Distance = 27.51 cm
       Distance = 10.83 in

       Pre-pulse (count) = 0
       Pulse (us) = 0
       Distance = 0.00 cm
       Distance = 0.00 in

       Pre-pulse (count) = 0
       Pulse (us) = 0
       Distance = 0.00 cm
       Distance = 0.00 in

0232 :
       Pre-pulse (count) = 2079
       Pulse (us) = 1194
       Distance = 20.32 cm
       Distance = 8.00 in

       Pre-pulse (count) = 2063
       Pulse (us) = 1593
       Distance = 27.11 cm
       Distance = 10.67 in

       Pre-pulse (count) = 0
       Pulse (us) = 0
       Distance = 0.00 cm
       Distance = 0.00 in

       Pre-pulse (count) = 0
       Pulse (us) = 0
       Distance = 0.00 cm
       Distance = 0.00 in

The new code structure means we should be able to add in sensors 3 and 4 as soon as they are physically wired to the bone.

(*) Well, not literally at the same time, as that would cause all kinds of nasty interference.

napratin commented 10 years ago

This is fantastic! So we had to go from Python to C to Assembly..true hardware team!

Quick note: The abstraction class for ultrasonics is in hardware/us.py, and needs to be populated with code that calls on the PRU-based module appropriately (the only thing that really needs to be changed is the update() method that returns distance in meters, other than any initialization stuff).

Any per-sensor configuration parameters (e.g. US sensor unit IDs/addresses, GPIOs) can be stored under the 'ultrasonics' key in config.yaml. US.__init__() gets all these parameters in the params arg.

The four US objects are instantiated by USHub, and that in turn is created by USLocalizer. Currently, the localizer can work with just 2 sensors (one front/back, one left/right) - so we can start testing before all four are on board.

jschornick commented 10 years ago

Current status (from last night) --

I now have four sensors reading during a single "pass" of the PRU loop, each of which ends with an interrupt sent to the ARM processor to indicate that the data is ready. Reading from a well-defined chunk of memory then allows the main processor to collect the pulse time recorded from each sensor. Minimum turn around time is rough 4*33ms, which is almost entirely due to a delay loop that allows all the ultrasonic echoes to dissipate.

If an individual sensor pulse is taking much longer than expected (bad reading/bad sensor connection), the PRU code should time out gracefully (avoiding hangs) and we should be able to detect this condition in the main code.

Regarding C versus Python -- there is a packaged Python wrapper of the C library in the am335x_pru_package from the BeagleBoard project, but I couldn't get it to load without error. Google helped me find an alternate by the guy who makes the Replicape, which while missing features, mostly works: https://bitbucket.org/intelligentagent/pypruss

I hacked in a quick patch to his C bindings to support the newer interface to libprussdrv, which requires an extra parameter to prussdrv_pru_clear_event(). This allows Python to wait for the PRU-generated interrupt. Reading the PRU data memory isn't supported, but luckily it's mapped to a static address on the ARM side. A quick map of /dev/mem and some integer unpacking allows us to get the sensor data into Python.

So we're pretty damn close... next I need to package up the modified libraries and make sure the installer puts them on the bone. I'll then wire up the logic converters and ultrasonics on the bot and see what goes boom.

jschornick commented 10 years ago

Library installation and a dozen little related details have been codified into setup_bone.py. Running the script to update the bot's bone went cleanly, and (after a reboot), the ultrasonic test script can load and receive data from the PRU. @R00ney and I didn't get around to wiring the logic converters due to time, but all the software is in place.

I still need to finish updating hardware/us.py to initialize the PRU and report the sensor values, but this should be nothing more than copy and pasting from the current test script.

jschornick commented 10 years ago

@R00ney was kind enough to wire up the ultrasonics this afternoon, and after a couple of quick fixes to the startup scripts... success! We can now read all 4 ultrasonics on the bot immediately after boot via the test scripts (both C and Python).

I'll go back to focusing on the integration with the code base now.

jschornick commented 10 years ago

A single Ultrasonic class has been merged into master, along with config and test bits to keep our codebase happy. I believe this should be all we need to integrate ultrasonic data into targeting, so I'm considering this closed. On to the next issue!