We earned 3rd Place !

In a 3-team field of Beginner teams… And we had a LOT of fun doing it, and learned a LOT. Hopefully we’ll get the chance to try this again in 2023. It was great to have the chance to watch the creative ways that everyone else approached the same challenges we did.

If anybody’s interested here’s a playlist of our videos: Barn Rats PiWars 2022

Some of our technical documentation is now on the Dons Tech Stuff site, more is on the way

Stopwatch / Status Display

This shows a combination status display / stopwatch panel that provides visual feedback on the progress of our challenge runs on the videos. The display is built from (2) 32×64 LED matrix displays, giving a total field of 32×128 pixels. It uses an Adafruit MatrixPortal to drive the panel and to connect to an MQTT broker over the network to receive commands.

While the unit was built specifically for the PiWars challenges, it could be easily used for any competitive event that would benefit from a display of status messages and event timing.

The panel is 130×500 mm in size, using the 4mm pitch display panels from Adafruit, but 3mm pitch or 6mm pitch panels could be substituted to achieve different physical sizes at this resolution, or the field “width” or “height” can be extended by adding additional panels, with minimal software changes.

Software and complete documentation including message protocols is available on Don’s Tech Stuff site.

Those who watched our challenge videos will remember that there was a bug in the stopwatch code that caused it to “run slow”. The bug is fixed in the posted code. It was a careless error, born of rushing to get this ready for filming, but its a great reminder that (1) rushing is rarely a good idea, and (2) code reviews ARE ALWAYS a good idea.

Apple plucking strategy

So, we don’t actually “pluck” the apples. We sort of bash them instead. Lacks a bit in finesse or elegance, but it’s simple, and pretty effective.

Basically, we have a “knocker” at the height of each branch. The knockers have fingers positioned at the location where the apple stems are on the branch (pretty handy that these trees have such consistently placed apples…).

The apples are attached to the tree with small magnets. When the robot approaches the tree, the fingers restrain the apples so they don’t “pivot” upwards too much, and the back knocker panels push them off the tree.

They fall into a “scoop” container at the front of the robot, and at the end of the run the robot returns to the barn, raises the scoop and dumps the apples.

Code and OpenSCAD files will be posted soon-ish.

Trough filling strategy

So after our earlier discovery that rice is indeed heavy, we re-thought our strategy for delivery. We now use 3 bins that rotate on a turntable. This way the mass is concentrated over the wheels instead of in front of the wheels.

Each bin is filled with enough rice to fill a bin half-way, plus 20%. Each bin has a servo-operated trap door at the bottom that allows the rice to be delivered all in one big “gush”. The turntable is driven by a small stepper motor, geared down by 4x so it can handle the necessary torque (did i mention that rice is heavy???).

Code and OpenSCAD files will be posted soon-ish.

Our Challenge Videos are Submitted !!

We did it !!! BrattyPi was able to successfully feed the Hungry Cattle and pluck the Nature’s Bounty apple tree. We didn’t do quite as perfectly as we had initially hoped (and we didn’t play with any sheep), but we made a very respectable effort, learned a lot, and had a LOT of fun doing it. Can’t wait for you all to see the videos in July.

We haven’t been very attentive to this blog in quite a while (life happens…), but we expect to start updating it to show technical documentation for the various parts of our project now that the pressure to “get it working” is past.

And by the way, we have a new family portrait !!

How Heavy is that Cattle Food, Answered

So this week on the Discord a lively conversation bounced around the subject of the weight of the Cattle Food that we need to transport for the Hungry Cattle challenge.

The Barn Rats team previously demonstrated a pretty successful dispenser that was able to fill a food trough to the required volume. But we had not really given any consideration or thought to the issue of what would happen if we had 3 of those dispensers hanging off the front of our robot.

Uh. That might have been a mistake…

Turns out that the short answer to the question is … we’re going to need to substantially rethink our design.

The dispenser works pretty well, as long as the robot is not trying to go anywhere. Driving it around however is a bit of a problem… Its way too front-heavy for our test chassis.

The chassis is about 180 mm square, with the dispensers sticking out about 100mm to the front of it. The robot body itself weighs 1300g. The front-mounted dispenser weighs in at about 400g empty, and 1000g when filled with 600g of dry rice, which is the amount it would take to fill 3 food troughs to 50%.

The robot has no trouble moving the mass around, even though this test chassis just uses tiny TT motors. Unfortunately backing up, or stopping from forward motion causes the whole thing to tip over…

On the flip side (poor pun intended), it DOES do a pretty good job of dispensing the rice. Most of the rice actually makes it into the food trough. The central bin with the front-dropping trapdoor does a better job than the side bins which have side-facing trapdoors. But as you can see in the photo we do manage to get the bin up to just over half full (the black stripe starts at the 50% point (thanks for the idea @keegan).

So it looks like some redesign is in order. Thinking about moving the bins “back” so their mass is mostly between the robot wheels, then having a slide to aim the rice down towards the trough. Mom always used to say that “there are no fails in life, just opportunities to learn”…

The big lesson here is “pay attention to the mass of that rice”. It is probably not insignificant compared to the mass of your robot.

How heavy is that Cattle Food ?

For those wondering about how much weight you’ll need to carry around in that Hungry Cattle challenge, here’s some background info.

This is using dry white rice. My empty trough is 76 grams, a full-ish one is 460 grams. So just under 400 grams of rice to fill one trough completely, or about 200g to fill one half-way.

So 3 troughs would be about 600g.

If you’re worried about weight, i wonder what an equivalent volume of Rice Crispies would weigh? Or if cows like Rice Krispies ??

@keegan had a great idea in today’s Discord (jan 9) — when you print your troughs, change color half-way up to make it easy to show that its half-full.

Empty trough 76g
Filled trough 460g

Introducing the Barn Rats

Hi — i’m little bRat, and i’ll be your guide this next couple months as we watch those tech guys teach my big brother bRattyPi some new tricks. I’m actually the smart one in the family, but big brother wants to believe he is. He thinks he’s a pretty cool dude, but me and all the sibs know he’s actually pretty square.

Me and all the brothers live in a barn that lives in a basement in the middle of Michigan, in the US of A. Its a pretty cool place, with lots of screens and technical gizmos. I don’t really understand a lot of that stuff, but big bro bRattyPi claims he does and that he’s itching to learn how to play with some of the new toys those tech guys are making. Frankly, i think its just fleas that have got him itching.

Anyhow, here’s a pic of me and the fam, just hangin’ out (that’s me – the biggest and handsomest rodent in the photo above; big bro bRattyPi is the guy dressed in yellow and blue; all together we’re the family of Barn Rats). You’ll be seeing a lot of us this next couple months as we all watch bRattyPi learn his stuff.

Prototyping the Hungry Cattle dispenser

Before we build our real robot we need to prototype (try out) some of the ideas for parts and strategies we will use in the real bot. Fortunately we have an existing robot that has a chassis pretty much perfect for trying out ideas.

The test robot has a 3d-printed chassis with grid holes on its front and lid that make it easy to attach test parts for various projects. It has 4 brushed motors driving Mecanum (omnidirectional) wheels, and is controlled from a ps4 controller (using Approximate Engineering’s software drivers on a Raspberry Pi Zero). Though not relevant to this particular test, it has a TFT display and a NeoPixel ring on its back end that provide a lot of operational information on commands and battery / system status.

Because we want to eventually try to make this work autonomously, we also included mounts for some sensors we want to try out. They’re shown in the video, but we left them out of the OpenSCAD design code we show below, because they are really fodder (pun intended…) for another story. And because we haven’t actually done anything with them yet.

So, on to the good news. It works. Mostly. A little bit. Sort of… The prototype did its job and pointed out the flaws in our concept. As a proof-of-concept, it was a success. We’ll fix the oops-es and carry on with this as the strategy.

For sure the driver (oops, me…) had some issues with accuracy and driving skills. The major design flaws became much more obvious in the physical reality than they were in the imagination. You probably noticed that we put a camera on the front of the mounting bracket, in anticipation of later using that to help find and accurately position the robot in front of a trough. You probably also noticed that the trap door totally blinds it when it opens. Oops ! Might need to rethink that… You’ll also notice that the hopper needs to be mounted a little higher so its opened door wouldn’t bump into the food trough on the next approach. But, fundamentally, it does drop food.

On the “plus side”, the unanticipated interference between the camera and the trapdoor made the trapdoor turn into a pretty nice ramp that helps to spread out the feed. Even though we plan to relocate the camera (and probably replace it with a Pi Zero with a tiny spycam on OpenCV), we’ll probably put in a “stop” to duplicate that ramp effect.

Our plan is to ultimately have 3 of these hoppers arranged horizontally on the mounting bracket, one for each food trough. And each hopper will be tall enough to hold enough food to fill a single hopper to the required half-way point. The one shown here is “shorter” to reduce printing time since its only a prototype.

What it looks like / How it works

This is how the hopper door operates; the door itself is on a pivot at the back. Normally a small “catch” holds it closed. The catch is mounted on an SG-90 micro servo which can be activated to release the door

The photos below show details of the catch mechanism. Note that the catch is printed with a small pocket into which a standard servo horn is bolted with M2 bolts (its too hard to print the tiny teeth that actually mount to the servo itself).

The trapdoor has a lip to make a clean seal for the “feed”. It rotates on pivots that are actually M3 bolts screwed into a tubular sleeve on the back edge of the trapdoor. Note that the centerline of the pivot should be inline (vertically) with the joint line between the hopper and the trapdoor to avoid binding or interference crashes.

The bottom of the bin has holes for M3 screws that act as pivots; these holes are 4mm dia so that the screws turn freely in them (and the screws are not “fully tightened” when installed). As noted above, these pivot holes are vertically inline with the joint line. Also note that the “back” of the bin has a vertical clearance gap to allow room for the axle sleeve.

The “front” of the bin has mounting holes that the servo mount box bolts into, the back of the box has mounting holes that are used to attach the bin to the mounting bracket. Note that in the pictures below, the bin is shown “upside down” because it is oriented in the way that prints best (with no supports).

The CAD Design

The OpenSCAD code that generates the hopper parts is as shown below.

// note part should be "bin" or "door", "servo", or "catch"
draw_part("catch");

bin_l = 55;         // interior length of bin (x)
bin_w = 40;         // interior width of bin (y)
body_wall_thickness = 2.0;  
door_clearance_gap = 1.0;       // clearance gap between door lip and inside of bin box

axle_ring_dia = 8;              // ring that surrounds axle hole in bin
axle_offset_x = 3;              // axle distance from back wall
shaft_vertical_clearance = 4;   // height of gap in bin back wall to clear axle shaft
shaft_horizontal_clearance = 9; // gap in door bottom lip to clear axle shaft

grid_spacing = 16;              // for mounting grid (mount trough to robot)
grid_height = 20;               // height of first grid row above bin bottom  
grid_mount_tube_dia = 7;        // to help self-tap screws grab    
grid_mount_tube_len = 5;        // to help self-tap screws grab    

oversize_multiplier = 1.25;
volume_needed = 100 * 100 * 25 * oversize_multiplier;
// bin_h = 52;       // used only for testing, normally use volume-calculated from below
bin_h = volume_needed / (bin_l * bin_w);

bin_outer_l = bin_l + (2*body_wall_thickness);
bin_outer_w = bin_w + (2*body_wall_thickness);

// standard part dimensions
M3_selftap_dia = 3;       
M3_throughhole_dia = 4;   
M2_selftap_dia = 2;         
M2_throughhole_dia = 2.5;    
M25_selftap_dia = 2.5;

module draw_part(part) {
    if (part == "bin") {
        draw_bin();
    }
    if (part == "door") {
        draw_door();
    }
    if (part == "servo") {
        draw_servo_mount();
    }

    if (part == "catch") {
        draw_door_catch();
    }
}

// note that the bin is generated "upside down" to facilitate support-less 3d printing
module draw_bin() {
    $fn = 24;
    difference() {
        union() {
            difference() {
                // make outside of basic box
                cube([ bin_outer_l, bin_outer_w, bin_h ]);
                // remove inside of box
                translate([ body_wall_thickness, body_wall_thickness, -0.1 ]) 
                    cube([ bin_l, bin_w, bin_h + 0.2 ]);
            }    

            // add rings that surround axle bolts
            translate([ axle_offset_x, 0, bin_h ]) 
                rotate([ -90, 0, 0 ]) 
                cylinder ( d=axle_ring_dia, h=body_wall_thickness);
            translate([ axle_offset_x, (bin_outer_w - body_wall_thickness), bin_h ]) 
                rotate([ -90, 0, 0 ]) 
                cylinder ( d=axle_ring_dia, h=body_wall_thickness);    

            // make mounting grid tubes (to thicken wall so self-tap screws grab)
            translate([ 0, (bin_outer_w/2) - (grid_spacing/2), bin_h - grid_height ])
                rotate([ 0, 90, 0 ]) 
                cylinder ( d=grid_mount_tube_dia, h=grid_mount_tube_len );
            translate([ 0, (bin_outer_w/2) + (grid_spacing/2), bin_h - grid_height ])
                rotate([ 0, 90, 0 ]) 
                cylinder ( d=grid_mount_tube_dia, h=grid_mount_tube_len );
            translate([ 0, (bin_outer_w/2) - (grid_spacing/2), bin_h - grid_height - grid_spacing ])
                rotate([ 0, 90, 0 ]) 
                cylinder ( d=grid_mount_tube_dia, h=grid_mount_tube_len );
            translate([ 0, (bin_outer_w/2) + (grid_spacing/2), bin_h - grid_height - grid_spacing ])
                rotate([ 0, 90, 0 ]) 
                cylinder ( d=grid_mount_tube_dia, h=grid_mount_tube_len );

            // make mounting tubes for servo mount
            translate([ (bin_outer_l - grid_mount_tube_len), 12, bin_h - 5 ])
                rotate([ 0, 90, 0 ]) 
                cylinder ( d=grid_mount_tube_dia, h=grid_mount_tube_len );
            translate([ (bin_outer_l - grid_mount_tube_len), 12, bin_h - 5 - 42 ])
                rotate([ 0, 90, 0 ]) 
                cylinder ( d=grid_mount_tube_dia, h=grid_mount_tube_len );
        }

        // make vertical room for axle sheath
        translate([ -0.1, body_wall_thickness, (bin_h - shaft_vertical_clearance) ]) 
            cube([ body_wall_thickness + 0.2, bin_w, shaft_vertical_clearance + 0.1 ]);

        // make throughholes for axle bolts
        translate([ axle_offset_x, -1, bin_h ]) 
            rotate([ -90, 0, 0 ]) 
            cylinder ( d=M3_throughhole_dia, h=56);

        // make mounting grid (holes for selftap)
        translate([ -0.1, (bin_outer_w/2) - (grid_spacing/2), bin_h - grid_height ])
            rotate([ 0, 90, 0 ]) 
            cylinder ( d=M3_selftap_dia, h=grid_mount_tube_len + 0.2 );
        translate([ -0.1, (bin_outer_w/2) + (grid_spacing/2), bin_h - grid_height ])
            rotate([ 0, 90, 0 ]) 
            cylinder ( d=M3_selftap_dia, h=grid_mount_tube_len + 0.2 );

        translate([ -0.1, (bin_outer_w/2) - (grid_spacing/2), bin_h - grid_height - grid_spacing ])
            rotate([ 0, 90, 0 ]) 
            cylinder ( d=M3_selftap_dia, h=grid_mount_tube_len + 0.2 );
        translate([ -0.1, (bin_outer_w/2) + (grid_spacing/2), bin_h - grid_height - grid_spacing ])
            rotate([ 0, 90, 0 ]) 
            cylinder ( d=M3_selftap_dia, h=grid_mount_tube_len + 0.2 );

        // make mounting holes for servo mount
        translate([ (bin_outer_l - (grid_mount_tube_len + 0.1)), 12, bin_h - 5 ])
            rotate([ 0, 90, 0 ]) 
            cylinder ( d=M3_selftap_dia, h=grid_mount_tube_len + 0.2 );
        translate([ (bin_outer_l - (grid_mount_tube_len + 0.1)), 12, bin_h - 5 - 42 ])
            rotate([ 0, 90, 0 ]) 
            cylinder ( d=M3_selftap_dia, h=grid_mount_tube_len + 0.2 );
    }

    echo("hopper height = ", bin_h);
}

module draw_door() {
    $fn = 24;
    wall_and_gap = body_wall_thickness + door_clearance_gap;

    difference() {
        union() {
            // thick part of door (box bottom)
            // note it is the raised part that should fit "inside" the bin box
            translate([ 0, wall_and_gap, 0 ]) 
                cube([ (bin_outer_l - wall_and_gap), (bin_w - (2*door_clearance_gap)), (body_wall_thickness + 1.5) ]);

            // outer "lip" for door (thin part of door)
            // (should match outside dim of bin, less shaft horizontal clearance gap)
            translate([ shaft_horizontal_clearance, 0, 0 ]) 
                cube([ (bin_outer_l - shaft_horizontal_clearance), bin_outer_w, body_wall_thickness ]);

            translate([ wall_and_gap, wall_and_gap, wall_and_gap ]) 
                rotate([ -90, 0, 0 ]) 
                cylinder ( r=wall_and_gap, h=(bin_w - (2*door_clearance_gap)));
        }
        translate([ wall_and_gap, 0, wall_and_gap ]) 
            rotate([ -90, 0, 0 ]) 
            cylinder ( d=M3_selftap_dia, h=bin_outer_w);        
    }
}

module draw_servo_mount() {
    $fn = 24;
    screw_separaton = 28;

    pocket_length = 24;   
    pocket_width = 13; 
    mountbox_width = 18;
    mountbox_length = 35;
    mountbox_depth = 19;

    mountbox_tab_l = 50;
    mountbox_tab_screw_sep = 42;

    difference() {
        translate([ -mountbox_length/2, -mountbox_width/2, 0]) 
            cube([ mountbox_length, mountbox_width, mountbox_depth ]); 

        translate([ -((pocket_length/2) + 0.1), -pocket_width/2, -0.1 ]) 
            cube([ pocket_length+0.2, pocket_width, mountbox_depth+0.2 ]);

        translate([ -screw_separaton/2, 0, -0.1 ])
            cylinder( d=M2_selftap_dia, h=mountbox_depth+0.2 );
        translate([ screw_separaton/2, 0, -0.1 ])
            cylinder( d=M2_selftap_dia, h=mountbox_depth+0.2 );
    }

    translate([ 0, -mountbox_width/2, 0 ]) difference() {
        translate([ -mountbox_tab_l/2, 0, 0 ]) 
            cube([ mountbox_tab_l, 2, mountbox_depth ]);
        translate([ -mountbox_tab_screw_sep/2, -0.1, mountbox_depth/2 ]) 
            rotate([ -90, 0, 0 ]) 
            cylinder( d=M3_throughhole_dia, h=2.2);
        translate([ mountbox_tab_screw_sep/2, -0.1, mountbox_depth/2 ]) 
            rotate([ -90, 0, 0 ]) 
            cylinder( d=M3_throughhole_dia, h=2.2);
    }
}

module draw_door_catch() {
    $fn = 24;
    arm_w = 10;
    arm_thick = 3;
    servo_axle_x = 5;
    horn_shaft_dia = 8;
    pocket_bottom_z = 1.5;
    pocket_axle_to_end_x = 18;
    pocket_width = 6;
    catch_from_axel = 24;
    catch_width = 4;
    catch_length = 18;
    arm_l = servo_axle_x + catch_from_axel + catch_width;
    hole1_x = 6.5;
    hole2_x = 13.0;

    difference() {
        union() {
            translate([ -servo_axle_x, -arm_w/2, 0 ])  
                cube([ arm_l, arm_w, arm_thick ]);
            translate([ catch_from_axel, -arm_w/2, 0 ]) 
                cube([ catch_width, catch_length, arm_thick ]);
        }
        translate([ 0, 0, -0.1 ]) 
            cylinder( d=M3_throughhole_dia, h=arm_thick + 0.2 );
        translate([ 0, 0, pocket_bottom_z ]) 
            cylinder( d=horn_shaft_dia, h=arm_thick );
        translate([ 0, -pocket_width/2, pocket_bottom_z]) 
            cube([ pocket_axle_to_end_x, pocket_width, arm_thick ]);
        translate([ hole1_x, 0, -0.1 ]) 
            cylinder( d=M2_throughhole_dia, h=arm_thick + 0.2);
        translate([ hole2_x, 0, -0.1 ]) 
            cylinder( d=M2_throughhole_dia, h=arm_thick + 0.2);
    }
}

Note that the code is heavily parameterized. The most likely parameters that would be changed to support a new robot are bin_l, bin_w, and oversize_multiplier. These control the length (front-to-back) and width (side-to-side) of the bin.

The height of the bin is calculated in the code to hold a sufficient volume of “food” to fill the 100 x 100 x 50mm bin half-way. Note that the oversize-multiplier parameter allows you to allow room for a bit extra to allow for spillage. In this example the parameter is set to 1.25 which gives 25% extra.

The “standard part dimensions” screw diameter parameters and the door_clearance_gap parameter can be used to tune your design to match the actual extrusion profiles of your 3d printer.

To run this code, simply paste it into the OpenSCAD editor. You can change the parameter in line 2 to select which part will be generated when you render the design. There are 4 possibilities: “bin”, “door”, “catch”, and “servo” (which generates the clamp that mounts the SG90 servo).

The Python Code

The servo is driven by a PWM signal generated on the Raspberry Pi Zero controller. This code uses the pigpio library to generate PWM signals that are jitter-free.

The setup for the library and hardware is as follows:

import RPi.GPIO as GPIO
import pigpio
# 
# note it is important to "sudo pigpiod" at bootup to allow this to work...
#
# verified that it works with all 3 servos, even though documentation
# seems to suggest that there is only one PWM generator in pi.  
# probably only needs one generator to work even with multiple pins
# https://ben.akrin.com/?p=9158 
#
# the pin numbering is per gpio numbers.   
# tested with GPIO.24, GPIO.25, and GPIO.9 simultaneously
# 
servo = 24
pwm = pigpio.pi()
pwm.set_mode(servo, pigpio.OUTPUT)
pwm.set_PWM_frequency( servo, 50 )

The code used to open and close the trapdoor latch is as follows (if you build one, the actual constants (600 and 1500), which represent the pulse width, will probably be different, based on your angular placement of the arm on the servo motor shaft):

if joystick.presses.l1:
    print("pressed L1 servo 600 LATCH TRAPDOOR")
    pwm.set_servo_pulsewidth ( servo, 600 )

if joystick.presses.l2:
    print("pressed L2 servo 1500 OPEN TRAPDOOR")
    pwm.set_servo_pulsewidth ( servo, 1500 )

Wrap-Up

So we are encouraged to know that our initial prototype shows that the idea will work. We will need to make some hardware tweaks to fix the OOPS-es, and we’ll need to try it out with a full-height bin just to make sure there’s no surprises there, but we feel like this is indeed the approach we will use for this challenge.

The Barn Rats are Ready to Play !!

We Made It !!! The Barn Rats are officially entered in PiWars 2022. We’re excited to participate, to learn, and to become active members of the PiWars community.

The official “competing” Barn Rat is named bRattyPi and he will be introduced later in the season. His younger brother little bRat is excited to make your acquaintance and will be introduced here shortly.