A grab all rant fest, tech review, book review and whatever strikes my fancy to talk about.
Tuesday, February 24, 2015
T'Rex Update: Batteries, Brains and Wires Oh My
Motivation: So I have finally gotten the Arduino to talk to the Orion and the Raspberry Pi. For a long time I was banging my head against a poor documentation issue. The Roboclaw examples all show a setup that only sends two parameters when configuring the comm to the controller. However an error throws when you match the example saying it expects 4 parameters. I couldn't figure out what the additional parameters were being used for going through the .h file so I tossed in a couple of values. Turns out the 3rd parameters was the timeout and setting it to 0 means the damn thing never has a chance to listen to any commands. It also looks like if you use the RoboClaw setup it only uses the UART Tx Rx pins (0 and 1) on the Arduino. Fun times. Right now I have a bastardized solution where the USB serial from the Pi and the RoboClaw comm is happening on these pins. This means I can sit on the terminal window (or serial monitor in the Arduino IDE) on the Pi and send commands to turn the treads. As I am connecting to the Pi via a VNC remote desktop session from my Mac this represents a remote control solution via wireless. Eventually I will probably ditch the VNC portion and build a mac (or possibly iPad) application that receives telemetry rather than using a full on desktop session.
I also have the camera streaming data directly to the mac via netcat that I finally got working (Thanks to This example). Back to motion. I built in a function that takes a power input and then steps to it based on an interval (currently 100 milliseconds) This makes for much smoother speed transitions. If the power number is higher than current it ramps up and down if it is lower. This is also setup doing a clock watch rather than delay so it does not interfere with doing other tasks. Right now I only have it doing forward so I still need to build in similar functions for reverse and the turns. If you are interested in doing the clock watch solution as opposed to using Delay then check out the Arduino multitasking lesson on adafruit.com. At heart it is just watching the return value from millis() and setting up a couple of variables to watch the gap since the last time you checked. When the delta is greater than your desired interval, do something. Pretty easy to do and I wish most of the examples out there for arduino used this methodology rather than the rampant delay usage you see out there. The end of that lesson also starts you down the path of classes which is also a good thing to learn here. It isn't that the Arduino is multi tasking, it is just that it can run through a LOT of instructions if you let it. 16Mhz is FAST. Each clock cycle is 1/16,000,000ths of a second. A 1000ms delay wastes 16,000,000 clock cycles that you could be doing something useful.
Anyway, If you saw my Facebook post (ITS ALIVE) you may have noticed the tracks were not in sync. Out of a valid range of 1-127 it was taking till 35 to get both treads moving, one started around 30. I had to take them apart and figured out one of the bogies was pretty gummed up from my RC track initial run. I ended up using some moly dry lube that I have for my road bike to lube up all the bogies, drive wheel and gearboxes. The result was that I can now get consistent tread rotation at around 12 and they now seem in sync.
In addition to motivation I also finally got my pan/tilt servos situated/calibrated to center and wrote a couple of routines for moving them through their respective 180 degree arcs of motion also from the serial connection from the pi. Next... need to figure out how to mount the camera, ping sensor and maybe the microphone as a pan/tiltable sensor head. The Arduino sketch is up to 10k of 32... well really 28k available (using a trinket from Adadfruit in the final build). Should be able to handle the rest of the movement and sensors in that.
Another bone head lesson (and why I am overloaded on serial comm via the 1,0 pins) was that BMSerial.h and softwareserial.h were conflicting.... because they do the same damn thing. If anyone else runs across this trying to setup a separate serial line than the one being used to communicate with the Orion Roboclaw motor controller then you just need to make a second serial setup with BMserial... the example is always myserial(tx,rx), just make myserial2(tx,rx) or whatever name you want to use. Or if you are using the roboclaw (tx,rx, timeout, ?) call you can do an independent BMserial creation, just don't use the 1,0 pins. Cleaning that up and implementing the multiple serial comm lines is probably the next thing on my to do list.
Power: I learned a lot about power on this thing recently... almost fried my UNO board in the process. I found a couple of projects online showing how to do a voltage divider circuit that let me monitor the cell voltages of the lipo battery I was using via the balancer connector. This way I could not just rely on the RoboClaw shutoff or a lipo monitor widget, I could actually send back the pack, and individual cell voltages via telemetry. Well this worked great for one lipo pack. I am planning to run this via two 2S 7.4 5000Mah packs wired in series (14-16v or so). So after I had it working for one pack I wrote the routines for monitoring two packs at once then wired (make that tried) the second pack in. Well I found out the hard way that when wiring the second ground from the balancer connection to the common ground I created a mismatched parallel configuration.... *sparks, pop, SHIT*. Basically this created a wiring equivalent of division by zero where infinite current tries to flow between the two batteries (and through anything they are wired through) to get them to match. This also blew a hole in my theory that the balancer wiring was protected from full current from the batteries... um NOT. Anyway it seems I only did some minor damage to the UNO board. It now reads a bit high on the analog inputs but so far so good.
So after getting a clean pair of shorts (2S 30C Lipo's on a mission to discharge are no joke) and doing some belated googling I learned a couple of important things. The first was that bit about the stupidity of the wiring I tried. The second is that RC LiPo's are more dangerous than I was already aware as they typically lack any kind of built in protections for the lipo cells. This lets them pack the punch they do for those little remote controlled rockets. But it also puts them at a much higher risk of a failure scenario where fire or worse happens. In the voice of Tom Hanks in Polar Express " Lesson.... Learned". I hadn't been planning to try and do this. I ordered a couple of voltage monitors that beep when the cells get low as plan A. However the great deal I got meant waiting on an order and I got bored waiting for them to show up ad thus plan B was born. Anyway, I do still want to try and figure out how to do this. I am sure I could do it with a relay but that is probably overkill. For now I will probably be happy with just figuring out how to get the pack voltage from the two way packet mode from the Orion RoboClaw controller.
Brains: Move over Raspberry Pi B+ and make room for Raspberry Pi 2. Got one through Adafruit for I think 40ish something + shipping. It will be nice once the launch fuss settles down and you can reliably get these for the advertised 35$ price. I may load up everything on the B+ once I button it all up. But the Pi 2 has really been able to speed up all the Arduino coding I am doing on board the Pi. I think my end configuration will be using one of the HAT prototyping boards from Adafruit with a pro trinket mounted. haven't decided yet if the trinket will be the 3.3v (direct comm to Pi) or the 5v version (will require a logic level shifter which I already have).
Wednesday, February 18, 2015
Raspberry Pi 2: Tomorrow has come while no-one was looking
The future is here. Is it the Apple Watch? Apple Car? Flying Car? Google Glass? Oculus Rift? Hololens? Project Loon? Google Fiber? Tesla Model 3, Hyperloop, SpaceX Falcon Heavy with resusab reusable boosters?
No.... it is the Raspberry Pi 2.
Surely I am being over sensational. Surely this is an overstatement of the importance of a not-for profit educational geek toy that even now most people probably have not heard of even though it may well be the most successful computer ever made in the UK, or if they have heard of it, they have no real idea just what the heck a raspberry pi is.
Ok, perhaps it is. However, I ask you to bear with me me for a minute as I explain. The Raspberry Pi 2 and its kin like Intel Edison, Beaglebone etc... are all in this very interesting space. Truly inexpensive computing. The Raspberry Pi 2 is the first one 'across the line' so to speak in my opinion.
No.... it is the Raspberry Pi 2.
Surely I am being over sensational. Surely this is an overstatement of the importance of a not-for profit educational geek toy that even now most people probably have not heard of even though it may well be the most successful computer ever made in the UK, or if they have heard of it, they have no real idea just what the heck a raspberry pi is.
Ok, perhaps it is. However, I ask you to bear with me me for a minute as I explain. The Raspberry Pi 2 and its kin like Intel Edison, Beaglebone etc... are all in this very interesting space. Truly inexpensive computing. The Raspberry Pi 2 is the first one 'across the line' so to speak in my opinion.
- $35 - one computer board with 40 GPIO pins, quad core 900mhz Arm 7 chip, HDMI input, 4 USB, Wired Ethernet port, 1GB of RAM.
- $20 - one 16GB top of the line SD card, you don't need to speed more than $10
- $10 - wireless USB adaptor
- $10 - Pi Case
- $6* - Amazon basics HDMI cable
- $23* - Amazon Basics wireless keyboard and mouse (14 for wired)
- $150* - Basic HD Monitor
- $10* - 2amp 5volt usb micro power supply
*lots of folks have these laying around from older systems/phones/tablets etc...
Total cost if you have none of the * - $264
Total cost if you have the * stuff already or plan to use it "headless" - $75
In 1993 my mother took out a loan against our savings account to buy a 486 desktop computer. I am talking around $2000 of VGA and CD ROM goodness. In today's money that would be a computer costing over $3,000 dollars. 12x the cost of the pi system I laid out above.
A 66mhz 486 was a 16bit system with in theory 66million instructions per second and boasted a 'massive' 32MB of RAM if memory doesn't fail me. Graphics were impressive at VGA (640x480).
The Pi 2 clocks 900Mhz on 4 cores. Simple math says 900 million instructions * 4, or 3.2 billion 32bit instructions per second. Granted multi core performance is a much more nuanced issue. but hey lets go on the conservative side and say 1billion 32bit instructions per second vs 66 million instructions at 16 bits. That is 32billion bits being pushed per second vs ~1 billion.
1/12th the cost. 32:1 performance increase in terms of a rough bit pushing metric. That is before you go into things like increased storage (16GB was LOT of space in 93, 1GB of RAM was just silly talk), graphics capability, wireless communication and power usage. Or built in software like wolfram alpha, mathmatica (worth more than this whole system if bought independently) and built in development tools with an ease of use and freely accessible tutorial information that was simply unthinkable in 93.
But hey, super powered computing in a small inexpensive packages are not really new. Afterall, odds are good if you are reading this you have a smart phone, possibly you have had several. If it is a current top of the line phone it is quite a bit more powerful than this board I am describing. It isn't just the low cost and computing power that makes this board (and others like it) special. It is those 40GPIO pins, camera connector, USB ports, display connector (HDMI and another more special purpose one). Why are those so important that I would make such a grandiose s statement above?
Let us fast forward a few years to 1999. I am in college studying computer science and I take a class in what I remember as physical computing (can't remember the actual title). That is taking these abstract calculators and using them to do real things in the real world like recognise a picture, or turn a motor, read a button push etc... To say I was interested is a mild understatement. But I was truly disappointed to discover how freaking expensive and yet crude it all was. You could spend as much on controller boards and interface cables as you could on the computer. And if you were not very careful you could easily fry your multi-thousand dollar system. The main component we used that semester was a board that amounted to a microprocessor tied to a serial port for the bargain price of $500 (you can get a better version in an Arduino Uno for less than a 10th of that today). $500 dollars + say a $500 old used 386/486 system plus periphials (keyboard, mouse etc...) was a lot of money for someone to throw at an adventure that could very easily lead to letting the 'magic smoke' out of all the expensive electronics. In some ways the cost was good as it taught us all caution. Looking back on it I think it was the worst element of the class, as that same experience with painful experimentation cost of any physical computing interface was occurring all across the nation, hell the world, at that same time.
That
Has
Completely
Changed
Granted this is not a crisp line. This change has been in work for a few years. Physical computer experimentation via cheap SBCs like the Pi and microcontrollers like Basic Stamp, Arduino etc... has been steadily ramping up on what looks to be the early part of an exponential curve collectively being referred to as the Internet of Things or IOT. I mark this spot as the point where the curve starts really taking off where before long people will be aware of technology like the raspberry pi or similar technology just as they are smart-phones. I point to the Raspberry Pi 2 as the IOT equivalent of the original iPhone in the smart phone world. Makerbots replicator is probably the IOTs Apple 1/Macintosh. Basic Stamp and Arduino both fit in the picture as prominent players as well. Remember Apple didn't invent the smart phone or the personal computer, it got the world to fall in love with them and start buying them in mass.
Why do I think the Pi 2 is so special?
Because the Pi 2 marries both practical understood computing and the IOT. In doing so it transects the world most of us live in where a computer has to work, and the burgeoning maker\IOT movement where a computer has to interact via more than just a keyboard\mouse\touchscreen and internet connection. The previous Pi B+ board that came out last year was a marvellous headless linux system for things. It was a curiosity as a computer you would use in general. Running the x11 desktop was akin to running quake on (insert some random highly inappropriate hardware) just to show that you could. You could do it, you could sort of run Minecraft, dev tools, a web browser or Mathmatica etc.... But it was a masochistic exercise in patience to do anything resembling real work. Compared to that... I am writing this post in a browser on my Pi 2. I did all my research in additional tabs. I have multiple Arduino development windows up in the background. TOP is running in one of several SSH sessions logged into the box and utilization is rarely peaking above about 20% and load times are a mild annoyance similar to web browsing circa 2000->2002 or so vs impossible obstacle. In other words, It. Is. A. Computer. And unlike most computers it is designed from the outset to be friendly to interfacing with the real world rather than just cyberspace. Now you can access all that wonderful educational content directly on the device while working with it. With a Pi and an Arduino you have the IOT equivalent of Duct Tape and Bailing wire. You could in theory take $1000 in stuff and create the next big IOT thing. Sell it to the world via Kickstarter and be a massive successful company in almost no time at all relative to history if you have the right idea and present it the right way. That is an investment of 1/3 of what my Mother had to spend to get us a working early internet era system. I am pretty confident that someone is out there doing it right now and in 5-10 years time you will think of them like you think of Jobs, Gates, Musk etc... and when you read their history you will read how they got started with this kind of device. Guess I will have to check back in on this post in a few years and see if I was nuts or not :-)
Monday, January 26, 2015
Robie Jr: Moving on to T-Rex Chasis
Ok, Robie is not dead, but I do not want to rip him up to try and fit everything inside. I have a couple of adafruit trinket pro's to play with on the T'Rex project. I think I will work on getting Robie to run around with one of those sans Raspberry pi in the future.
On the T'Rex project I have the raspberrypi camera finally working with decent latency. Here is a pic (not much but that is the camera image up on my mac on the screen, coming from the pi)
For those trying to do something similar the best solution I found was using netcat (nc.traditional on the pi and just nc on the mac shell commands) with nc and mplayer on the mac (had to get via macports, mplayerX is NOT a good option). Anyway basic idea is:
Also, it is important to remember to start the listening stream first on the PC you want to see the video.
In playing around with all the options I ended up installing v4l2 libraries on the pi. I got an rtsp stream (example 6 on the page) up and running using VLC streaming out of the pi using those libraries and I am wondering if I can do a direct kick out to netcat skipping VLC (VLC server was causing 2-3 seconds delay on HTTP and RTSP examples). The reason I would like to try that is the v4l2 stream allows you to tweak some settings while the stream is live. If raspivid allows you do that I haven't figured it out yet. Would help with tweaking the camera view when out roving around.
Bandwidth in the netcat example using a 640x480 stream is ~380KBps. My initial run with full HD was a bit jumbled and laggy though I haven't tried it again since I got some of the settings tweaked. latency was pretty minimal when it was caught up but it was variable from a tenth or two up to a second or three at times. Seemed to be tied to when I hid the video window for a while and brought it back up on the pi got bogged down on something else.
As you can see the camera is mounted to a pan tilt kit (micro server pan tilt kit from Adafruit). I have tested that with an RC controller but have not gotten it running from the arduino trinket. I also have a new basic wiring diagram for the project. Still pretty rough...
On the T'Rex project I have the raspberrypi camera finally working with decent latency. Here is a pic (not much but that is the camera image up on my mac on the screen, coming from the pi)
For those trying to do something similar the best solution I found was using netcat (nc.traditional on the pi and just nc on the mac shell commands) with nc and mplayer on the mac (had to get via macports, mplayerX is NOT a good option). Anyway basic idea is:
- on the receiving computer you do
- nc -l [some port number] | mplayer -fps 60 -cache 1024 -
- on the pi you do
- raspivid [setup your video stream] -o - | nc [dest ip] [dest port]
Also, it is important to remember to start the listening stream first on the PC you want to see the video.
In playing around with all the options I ended up installing v4l2 libraries on the pi. I got an rtsp stream (example 6 on the page) up and running using VLC streaming out of the pi using those libraries and I am wondering if I can do a direct kick out to netcat skipping VLC (VLC server was causing 2-3 seconds delay on HTTP and RTSP examples). The reason I would like to try that is the v4l2 stream allows you to tweak some settings while the stream is live. If raspivid allows you do that I haven't figured it out yet. Would help with tweaking the camera view when out roving around.
Bandwidth in the netcat example using a 640x480 stream is ~380KBps. My initial run with full HD was a bit jumbled and laggy though I haven't tried it again since I got some of the settings tweaked. latency was pretty minimal when it was caught up but it was variable from a tenth or two up to a second or three at times. Seemed to be tied to when I hid the video window for a while and brought it back up on the pi got bogged down on something else.
As you can see the camera is mounted to a pan tilt kit (micro server pan tilt kit from Adafruit). I have tested that with an RC controller but have not gotten it running from the arduino trinket. I also have a new basic wiring diagram for the project. Still pretty rough...
For now I am not sure about all of this. But it seems like the roboclaw can provide 5v at 3amps from the main battery supply, and the raspberrypi can pass through whatever it does not use. So I shuold be able to mangle a USB cable to run power from the BEC circuit into the pi USB input (much better protected than running it to the 5v and gnd GPIO pins directly). The question is if the power supply is clean enough to avoid resetting the pi (seems they are pretty sensitive). Worse case I will just run power to the pi from a USB battery backup I have. Then use the pass through to kick out to the two micro servos and trinket arduino. Hope to setup packet/serial communication from the trinket to gpio on the pi board. I got a series connector for two 7.4 lipo 5000mah packs I have. I have a couple of voltage monitors on the way to make sure I don't blow them up. Also found some projects for using some voltage dividers to use analog arduino ports to provide the same function.
I am a bit concerned about the two packs as they are kicking out over 20v fully charged which is more than I was expecting. Need to read up on these motors, they should take over voltage fairly well if I run it lightly, but that is a lot more than I expected to be dealing with. I still have a smaller 11.1 3s pack to run with if need be.
A word of caution for anyone looking to use this platform... I ran it around in RC mode and found that it is relatively easy to get this thing to turtle if you run it up to something it can't climb. The treads will grab and roll it over onto its back pretty easily. I may be building in some roll bars to protect the electronics and to get it back up right in the event of a spill.
Subscribe to:
Posts (Atom)


