Ball !!!!!
The next step was to get Rover to move when the Pixy saw a learnt colour. This was very easy! And was completed in a couple lines and a few minutes.
Over the next days the code evolved until Rover was able to turn to centre the ball and move forward until the ball was a set size.
The Pixy camera made this easy for me, each learnt colour it finds is outputted as a block, with the following information.
The colour signature number, it’s location and size.
With this information, the code can turn the robot towards the colour it is hunting, centre and move forward until the ball is in the centre and correct distance away from Rover. I have tested the code with a ball just over the max distance between balls, just over 175 cm. The ball at that distance is only a few pixels wide!
if blocks[index].signature == 4 and (blocks[index].width > 5 and blocks[index].height > 5):
ball = True
the above line checks that found signature is the required signature and meets the size requirements and sets the flag ball to true, if true.
the following line sets the position variable with the x coordinate of the colour object
position = blocks[index].x
The next block of code sets the motors speeds, depending on the position of colour signature.
if ball:
print('Ball!')
position = blocks[index].x
if position > 165:
print("**** right ****")
power_right = -75
power_left = 100
elif position < 125:
print("**** left ****")
power_right = 100
power_left = -75
else:
print("**** forward ****")
power_right = 100
power_left = 100
]]>
Once again, I turned to my friend Google and Google found the following website and guide.
First attempt failed because I used a too small SD card, 8Gb was not large enough! Found an unused 16Gb SD card restarted again followed the guide. Got up to Step 5, 4 hours to Compile! Luckily it was about 10pm so I started compiling it and will pick up in the morning when it had finished, good plan I thought. This morning I woke up, and checked my laptop, yes I had started a SSH session to install it. I found that my laptop had gone to sleep after ½ hour of me leaving my laptop. Bottoms! The compile had stopped, restart the compile, after 2 hours compiling, I was ready for the next step, install. I followed the steps to install for Python 3.5. tested importing OpenCV and it worked!
So what have I learnt from this? always make sure that your laptop, when on mains power does not go asleep or work on the Raspberry Pi instead of using SSH, use a large SD card if you not sure how large the software package you are compiling is.
Now for more learning and testing. Watch this space!
update
you also need to follow the guide below to get the PiCamera working within the virtual environment.
https://www.pyimagesearch.com/2015/03/30/accessing-the-raspberry-pi-camera-with-opencv-and-python/
Keith suggested using gnu screen in this tweet for long/big install ;-D
Brian, gnu screen is a good utility to use when doing big installs. Install carries on even if ssh session fails.
— Keith's Pi Tutorials (@PiTutorials) November 5, 2017
Brian
]]>]]>
There are just under 200 days until the competition starts, planning starts as of, well being honest, 3 months ago. The plan, use the same chassis as last year, but this time, build a 1940's roadster for Babbage. Hopefully there will be at least one blog post a week until the competition, I plan to share my build progress, plus random posts about designing a Pi Wars robot and for my first post, my Pi Wars History.
I have been lucky to take part in the last 3 Pi Wars, and to my great surprise winning the last two! So what about the first one? I came about third from the bottom, with my Raspberry Pi 2 model A, PyroBot. I was a mess, challenges code had the motor turning in different ways between them, no easy way to change programmes / functions.
For Pi Wars 2, my plan was to build a robot that was OK, and not be the smallest robot. Revenge was born 6 wheeled monster of a robot, it's foot print the size of A3 paper. Revenge had a touch screen interface to select functions.
Next came MAX, based on a Prototype chassis, I was a designing for Coretec, MAX is a 4 wheel design, I added pointless LED and chip tunes!
And finally
The Pi Wars team asked me for some hints and tips, and they can be found here.
Brian
Head Meat Bag
]]>