Wednesday, April 5, 2017

R2C2 Chasing CHiP the Dog

Smile
Next task on Robotics Specialization Course was to calibrate the motors, IMU and camera and then to build a differential drive controller to follow an April Tag. But unfortunately the Raspberry Pi v2 camera module I had turned out to be defective. Crying faceProbably it got damaged while sitting in my car for few days under scorching sun Sun
Fortunately Ruvinda Dambarage, one of my colleagues had a v1 camera that I could borrow. Angel
After working on this late night at workplace all was good. But what could be more cooler than using another robot to test your robot?
So here my WowWee CHiP robot Dog Dog face giving me a helping hand at April Tag handling while I do the Camerashooting required for the assignment. Hot smile



[Published with Open Live Writer on Windows 10]

Wednesday, March 15, 2017

R2C2 - Raspberry Pi + ROS Robot for Coursera Robotics Course (Part 1 - Assembly)

Smile
As part of carrier oriented personal goals for 2016/17 I have being taking the Robotics Specialization course at Coursera offered by Penn university. In this 6 course specialization you have to complete a capstone project related to robotics. There are two tracks you can select for this. Either a MATLAB based simulation project or if you are more adventurous, you can choose to build a real autonomous robot from basic hobbyist robot components you can easily source from online vendors.
Well even though you only need to complete either of the tracks to pass the course, since doing the simulation track is more straightforward and less exotic why not doing both? So here I go ahead with doing both tracks. Nerd smile
First step was to acquire the required components. As a guideline course moderators have provided a wish list at Adafruit for sourcing the components. But I have choose to do a little bit of my own research and use alternative components that I can easily find either locally or for a lower price from ebay.
So here is the components I used.
  • Raspberry Pi 3 Model B – ebay (US $36.96) 
  • Raspberry Pi Camera Board v2 – ebay (US $20.99)
  • 3-wheel Smart Robot Car Chassis with Speed encoder and Battery Box – Local Shop (LKR 1100.00 - Approx. US $7.25)
  • I2C TB6612 Stepper Motor PCA9685 Servo Driver Shield V2 Fr Arduino – ebay (US $5.91)
  • 10DOF LSM303D + L3GD20 + BMP180 Pressure Field + Gyroscope Module Sensors – ebay (US $6.97) 
  • Adjustable Pi Camera Mount – ebay (US $1.89)
When the chassis is observed, even though it had some holes to mount components, none were aligning with the Raspberry Pi. So I got some holes drilled up on to mount the Raspberry Pi before assembling the chassis.
CAM00430 (1280x961)
I also flashed the Raspberry Pi image provided at course webpage and configured for remote access since the way I have chosen to place the Raspberry Pi prevents easy access to the HDMI port once the Motor shield is mounted.
After assembling the chassis I had mounted the Raspberry Pi using some plastic mounts and screws. I also mounted the Camera mount base and the IMU using a single screw.
CAM00432 (1280x962)
Then I screwed the Raspberry Pi camera to the camera mount and attached it to the camera mount base. And attached the camera cable to Raspberry Pi.
CAM00436 (1280x960)
Since I purchased a Arduino version of the Motor shield instead of Raspberry Pi version (purely to save some bucks since Arduino version was much cheaper)  I had to mount it separately instead mounting directly on top of the Raspberry Pi. Then connected the wires from motors to the motor hat.
CAM00439 (1280x960)
Then I used a Level converted and some jumper wires to connect Raspberry Pi, Motor Hat and the IMU. Here both IMU and Motor Hat runs in 5V logic levels while Raspberry Pi is Running at 3.3V logic levels.
Untitled Sketch_bb
Note: Actual components used are slightly different than in the above diagram.
CAM00440 (1280x960)
Unlike the Adafruit chassis kit, the one I used did not have a top shelf. So I got an ad-hock platform 3D printed. Unfortunately sitting in my car under scorching sun,Sun it got bent down in the middle.
CAM00442 (1280x960)
But nevertheless it serves the purpose for mounting the battery packs. I used double sided tapes to secure the battery packs on top of the platform.
CAM00443 (1280x962)
Once all done and modifying the controller template to issue a 0.3m/s forward and 0.5rad/s angular velocity as instructed in the course, I could verify that all were connected in order.

I conveniently named the robot as R2C2 which stands for Raspberry Pi ROS (Robot) for Coursera (Robotics) Course. It is also partly inspired from R2D2 (even though former is a droid unlike this which is a differential drive robot)
[Published with Open Live Writer on Windows 10]

Monday, July 11, 2016

TDD Tools for C++ – Unit Testing & Mocking Frameworks

Smile
Test driven development (TDD) is a big buzz word when it comes to software development best practices. It has been well received in .NET and Java world and almost all the IDEs out of the box support tools/plugins required to ease the task for these languages.Computer
However when it comes to C/C++ it is a little bit different story. Your favorite IDE may not support the necessary tools/plugins for the TDD out of the box. But in fact there is a plethora of tools and plugins for major IDEs that you can use for a seamless development experience. Since the choices of IDEs and the tools/frameworks falls in a wide range, I do not plan to explain here how to use each and every tool/plugin. In fact there is enough instructions out there if you know how to Google things up. Winking smileRather I would list down a couple of popular tools/frameworks you could use along with the notable differences between them so you could choose the tools best suitable for your requirements. Also note that this is not an exhaustive coverage on all type of tools but should be good enough to get the most of TDD. Also it should be noted that I do not plan on discussing on TDD approach in general either.
In TDD, first step is to write an initially failing test case to test improvements or new functions that you need to add. In doing this you need a good Unit testing framework as well as a Mocking framework to set the expectations on interfaces of objects you would be using.
Unit Testing Frameworks.
Google Test[1]
Google Test is a good unit testing framework and has gained popularity among C++ developers recently. In Windows, it has a test runner plugin for Visual Studio. Also in Linux, It has plugins for both Qt Creator as well as Eclipse CDT. Google Test also supports value parameterized tests as well[2]. Though it is not that much intuitive like defining Theories on xUnit++. Google Tests is also well maintained and actively supported.
You can read more on getting started with Google Test here: https://github.com/google/googletest/blob/master/googletest/docs/Primer.md
Boost Unit Testing Framework[3]
If you are already using Boost libraries, Boost Unit Testing Framework is another good choice for unit testing. It also has a plugin support for both Visual Studio as well as Eclipse CDT. Like Google Test, Boost Unit Testing Framework also has support for value parameterized testing starting from Boost.Test v3 (Library version 1.59.0). For the older versions you can use unary function based test cases[4] Even though it’s not that elegant like theories defined in xUnit++ or the newer BOOST_DATA_TEST_CASE declarations.
Even though it is not a requirement of a unit testing framework, apart from CppUTest, Boost Unit Testing framework also supports Memory Leak Detection through its execution monitor[5]. However this feature is, at the moment, implemented only for the Microsoft family of compilers (and Intel, if it employs Microsoft C Runtime Library). Also it can not be tuned per instance of the monitor and is only triggered globally and reported after the whole program execution is done. Like Other Boost libraries Boost.Test is also well maintained and supported.
xUnit++[6]
xUnit++ is a unit testing platform for C++ inspired by xUnit.net. If you are already familiar with xUnit.net you would feel home at defining new tests (Facts) and Theories in similar fashion of code syntax. However xUnit++ have only support for Visual Studio Test Explorer. Also it should be noted that it is compatible with Visual Studio 2012 and compatibility with other versions may vary. Even though it’s open source since XUnit++ is not actively maintained currently, support or additional features availability cannot be guaranteed.
Microsoft Unit Testing Framework for C++
If you are using Microsoft Visual Studio to build native applications on Windows, you could use Microsoft Unit Testing Framework for C++ which is bundled with Visual Studio. It supports integrated Test Explorer to manage unit tests you write. However it should be noted that it does not support Data Driven Tests (Substitute for value parameterized unit tests) like in Microsoft unit test framework for managed code. And since Microsoft Unit Testing Framework is a proprietary piece of software there is no visibility into maintenance and you’ll be mostly limited to community support.
You can read more on getting started with Microsoft Unit Testing Framework for C++ here. https://msdn.microsoft.com/en-us/library/hh598953.aspx
CppUTest[7]
CppUTest is another unit testing framework developed using a limited C++ set and thus well  suitable to be used in embedded systems. But it works for any C/C++ project. It also has a Test Runner plugin support for Eclipse CDT Test Runner[8].
Even though it is not a requirement of a unit testing framework, one notable feature in the CppUTest is the Memory Leak detection support on a per-test level[9]. In this regard, the developers have made it possible to use CppUTest along with Google Test[10] so that it is possible to have Memory Leak Detection support along with all the other goodies from Google Test so giving out the best of both worlds.
CppUTest also has a C Interface so that it is easy to use it with pure C projects[11]. Like many other open source unit testing frameworks CppUTest is also actively maintained and supported.
Mocking Frameworks
The key concept behind most C++ mocking frameworks is ability to override virtual functions in derived classes.
Google Mock[12]
If you are already using Google Tests, Google Mock is a good choice of mocking framework. Even though Google Mock is implemented on top of Google Test, and depends on it, you can also easily configure Google Mock to work with another testing framework[13]. Also it should be noted that, when using Google Mock, you must use the bundled version of Google Test if you choose to use Google Test.
You can read more on using Google Mock here: https://github.com/google/googletest/blob/master/googlemock/docs/ForDummies.md
One thing to note is that Google Mock resides in a place between manual mocking and automated mocking. Expectation settings and validations are automated, yet you have to write some amount of manual code compared to other mocking frameworks like HippoMocks or FakeIt. However since Google Mock is included in Google Test framework it is also actively maintained and supported.
HippoMocks[14]
HippoMocks is provided as a single header file. So it is no brainer to use it with any C++ unit testing framework out there. Just include the header and you are good to go. HippoMocks is occasionally maintained and supported on github.
You can read more on using HippoMocks here. http://hippomocks.com/Main_Page
FakeIt[15]
Like HippoMocks, FakeIt is also provided as a single header file. However there is a couple of additional features that you might sometimes find it useful. Specially the ability to Spy on existing objects using a single line of code[16]. It also has very expressive Arrange-Act-Assert syntax. Similar to HippoMocks, FakeIt is also occasionally maintained and supported.
You can read more on using FakeIt here. https://github.com/eranpeer/FakeIt/wiki/Quickstart
CppUMock[17]
CppUTest also has support for building mocks. However unlike other mocking frameworks, the main idea is to make manual mocking easier and it does not support making automated mocks like other frameworks. Thus with regards to this, CppUTest supports using Google Mock directly in CppUTest[18]. Also since CppUMock is included in CppUTest it is also actively maintained and supported.
Test Runner Plugins for IDEs
Eclipse CDT
Eclipse CDT has C/C++ Unit Testing Support plugin available from marketplace which supports both Boost Test Runner and Google Test Runner.
Note: It may require to separately install “C/C++ Unit Testing Support” package under “Programming Languages” category by choosing “--All Available Sites” in Help->Install New Software in Eclipse CDT.
Apart from that if you are using CppUTest you may also install CppUTest Tests Runner from https://github.com/tcmak/CppUTestEclipseJunoTestRunner However at the moment it is not actively maintained so support for newer versions or bug fixes cannot be guaranteed.
Qt Creator
Qt Creator has a good plugin for Google Test.
Qt Creator Google Test Plugin: https://sourceforge.net/projects/qtc-gtest/ It is also regularly maintained for new Qt Creator releases.
Microsoft Visual Studio
Apart from Microsoft Unit Testing Framework for C++, there are plugins for Microsoft Visual Studio Test Explorer for xUnit++, Google Test framework as well as Boost Unit Test Framework. Some notable plugins are listed below.
GoogleTest Runner plugin for VS 2015: https://visualstudiogallery.msdn.microsoft.com/cbd1a9b2-790b-4d49-905f-d128ca21d3fb It also have occasional support and maintenance on github.
Boost Unit Test Adapter for Visual Studio: https://visualstudiogallery.msdn.microsoft.com/5f4ae1bd-b769-410e-8238-fb30beda987f It is also actively maintained and supported
xUnit++ Test Adapter for Visual Studio 2012: https://visualstudiogallery.msdn.microsoft.com/1212037b-a608-450c-a578-627b93f1b336 Since this plugin is included in xUnit++ which is not actively maintained or supported, support for newer versions cannot be guaranteed.
If above still has not catered to your requirement, you can find an exhaustive list of unit testing and mocking frameworks at https://en.wikipedia.org/wiki/List_of_unit_testing_frameworks#C.2B.2B Also if you have any questions or think that anything else should be added please feel free to leave a comment below. I would also like to thank my colleague Ruvinda Dambarage for useful tips provided on compiling this post.
References
[1] Google Test: https://github.com/google/googletest
[2] Google Test Value Parameterized Tests: https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md#value-parameterized-tests
[3] Boost Test Library : The Unit Test Framework: http://www.boost.org/doc/libs/1_61_0/libs/test/doc/html/index.html
[4] Unary function based test case: http://www.boost.org/doc/libs/1_56_0/libs/test/doc/html/utf/user-guide/test-organization/unary-test-case.html
[5] Boost Test Library Memory Leaks Detection: http://www.boost.org/doc/libs/1_58_0/libs/test/doc/html/execution-monitor/user-guide.html
[6] xUnit++: https://bitbucket.org/moswald/xunit/wiki/Home
[7] CppUTest https://cpputest.github.io/
[8] CppUTest Tests Runner: https://github.com/tcmak/CppUTestEclipseJunoTestRunner
[9] Memory Leak Detection on CppUTest https://cpputest.github.io/manual.html#memory_leak_detection
[10] Running Google Tests in CppUTest https://cpputest.github.io/manual.html#gtest
[11] CppUTest C Interface: https://cpputest.github.io/manual.html#c_interface
[12] Google Mock https://github.com/google/googletest/tree/master/googlemock
[13] Using Google Mock with Any Testing Framework: https://github.com/google/googletest/blob/master/googlemock/docs/ForDummies.md#using-google-mock-with-any-testing-framework
[14] HippoMocks https://github.com/dascandy/hippomocks
[15] FakeIt https://github.com/eranpeer/FakeIt
[16] Spying: https://github.com/eranpeer/FakeIt/wiki/Quickstart#spying
[17] CppUMock https://cpputest.github.io/mocking_manual.html
[18] Using Google Mock with CppUTest https://cpputest.github.io/manual.html#gmock
[Published with Open Live Writer on Windows 10]

Saturday, September 26, 2015

My Car PC – Installing Android Auto

Smile
After the successful Beta stage of my Car PC build I could not add anything much due to workplace commitments. However one thing that fascinated me was the introduction of Android Auto by Google.Mobile phoneAuto
Still the problem in adopting Android Auto into my setup was that it is compatible only with the Hardware manufactured by partnering manufacturers and there was no way to obtain details about developing a head unit app by an average person. Of course the community quickly began to reverse engineer the workings of Android Auto mobile app and the provided Simulators and quickly surfaced an open source head unit app for Android Tablets working in OTG mode. Going on that direction, I was almost about to put Android x86 and port that so called head unit app into x86. Yet a web search for that app suddenly pointed to a recently announced desktop head unit app by Google itself. Hot smile
So I reinstalled the Windows 7 Embedded platform with required components (This time approx. 1.5GB image) installed JDK (which is a prerequisite for Android SDK) and Android SDK tools (which provides adb.exe) along with Android Auto desktop head unit app and Google USB drivers.
Still I’m using my old startup sequence of launching Centrafuse Auto from my own custom shell application. And made a batch script to forward tcp:5277 in adb and then launch the head unit app. I have then added this as an Application plugin titled as Android Auto to Centrafuce app. While in this video I have to accept the annoying Debug authorization prompt on my mobileMobile phone   I have get rid of that by selecting the checkbox for "Always allow from this computer". Only caveat with this setup is that I have to click on Maximize button to adjust the head unit app to screen since I’m running at 800x600 resolution. It also has a title bar on top of the screen yet. But apart from that it’s almost as the authentic Android Auto experience from that point onwards. AutoHot smile
And the usual disclaimer that goes with any project of this nature:
The method depicted in this post is only experimental and if you choose to follow the same you are fully responsible for any damages that may arise as a result. Also always stay fully aware of driving conditions and always obey applicable laws. In case system may become unstable and unresponsive do not try to handle you mobile while driving.

[Posted with Windows Live Writer™ 2012 on Windows 10 64bit]

Friday, August 8, 2014

Deploying a Service on Windows Mobile 6.x

Smile

In one of projects I’m working on at my workplace there is a service for Windows CE handheld devices (Motorola MC3x90 series)[1].Work This service has been developed following the instructions at http://msdn.microsoft.com/en-us/library/aa446909.aspx. While it says it apply to Microsoft® Windows® CE 4.0 and 5.0 it also works on newer Windows CE versions as well. Nerd smile

Unfortunately when I try to put it over to Windows Mobile Mobile phone(Which indeed based on the Windows CE platform) devices of the same manufacturer (MC3x90Z series) the service was not loading despite validating that dll can be loaded from another app as well as copying over exact registry settings which are the only two pieces that need to get it running. Thinking smile

Troubleshooting was also very painful since there was no command prompt app in these windows mobile devices so had to put some 3rd party console programs like the one you gets with Windows Mobile Developer Power Toys[2]. Still the services.exe was refusing to load and run service when warm booted and this was very frustrating. Annoyed

After lot of cursing Devilfinally found another one which also was developed by me long time ago and had a working service on Windows Mobile.Angel And a careful examination on the CAB file revealed that it need couple of work from our part to get a service running on Windows Mobile platform. Following is the findings.Light bulb

1. A compatible console.dll should be copied to \Windows directory. You can find the one I had been using (Don’t know exactly where I had found it) at my Google Drive

2. Following Registry settings apart from what needed for Service loading as described in the referenced msdn tutorial.

[HKEY_LOCAL_MACHINE\Drivers\Console]

”OutputTo"=dword:00000000

[HKEY_LOCAL_MACHINE\Services]

”AllowCmdLine"=dword:00000001

3. Last but not least. A shortcut at \Windows\StartUp folder to load the service. You can create one by creating a file with extention .lnk which contains a text in following format

<length of the text following after #>#services load <name of registry key of service>

e.g.

20#services load MTXSVC

Good luck and happy coding!Computer

 

References

[1] Handheld Computers http://www.motorolasolutions.com/US-EN/Business+Product+and+Services/Mobile+Computers/Handheld+Computers

[2] Windows Mobile Developer Power Toys http://www.microsoft.com/en-us/download/details.aspx?id=10601

[Published with Windows Live Writer on Windows 8.1]

Friday, December 27, 2013

My Car PC– Beta Build

Smile
After the success in the GPS receiver installation I thought, OK now it’s time to get serious and make a proper installation with some real H/W. The only obstacle preventing that was a way to import some decent H/W that was in my mind. Specially a good APU based system with low power consumption, touch screen display, SSD and what not.
Fortunately a couple of colleague from my workplace was returning from US on-site visit and I finally managed to source following H/W.
1. ASRock E350M1/USB3 Motherboard $109.99 from Amazon.com
2. OCZ Agility 3 - SATA III 2.5 60GB SSD $87.99 from Amazon.com
3. VM70 - 7" TFT LCD touchscreen monitor $119 from eBay store.
4. G.Skill DDR3 1333MHz 2GB (From local computer shop) (For around some LKR 2000+ I think)
5. Plastic Mini ITX VESA Mnt HTPC Car Computer Case(Black A) $37.50 from eBay.
6. For the power supply, I ordered a Pico PSU 12V 120W DC-DC MINI ITX ATX PC Power Supply as well from eBay. $24.99
following is the collection of above items along with other peripherals (OBD-II, GPS cables) I have sourced during previous builds.
IMG_20120703_112018 (800x448)
However unfortunately I found out it hard way (By blowing a voltage regulator IC of motherboard while testing it with a analog variable power supply, which was uncontrollable.Annoyed) that Pico PSU is not capable of operating in wide input voltage range of the vehicle. Sad smile
So had to wait yet another few months (Actually almost an year) to get a new Motherboard (This time, $87.55 from Amazon.com warehouse deals). I also got a M1-ATX Automotive DC-DC Power Supply, 90 Watt for $32.99 from eBay this time.
Once all the necessary items are sourced I test benched the entire setup. (This time using a better digital variable power supply. Hot smile)
IMG_20131024_235720 (2048x1535) (800x600)
For the software setup, I used following setup.
Windows Embedded Standard 7 (Minimalistic setup with Command prompt shell with custom shell support – Approx 1GB image size)
Centrafuse 3.5
Garmin Mobile PC
For mounting the touchscreen I sourced a 1DIN holder for few hundred rupees from local scrapyard (Panchikawaththa) for auto parts, since I did not wanted to drill holes on original 1DIN holder that was in the center console. After bit of dismantling and drilling few holes on 1DIN holder I bought I could mount the screen on it.
Once all the required items are ready, I moved into the vehicle. After pulling the panels on the dashboard I could access the center console for replacing the empty 1DIN holder with the screen.
f4609944 (800x600)
Once the screen is mounted, got the wires layered below the retrofitted carpeting in the vehicle to the backseat under which I plan to put the PC.
SAM_3962 (800x600)
Once all wired up, it’s time to fire up the setup and enjoy the fruits of hard work. Note
SAMSUNG CAMERA PICTURES
Few weeks later, I ordered a reverse camera as well from eBay (18 AUD) and hooked it up to reverse light power supply and connected to Aux input of the LCD monitor so it switch to reverse camera when I shift into reverse.
IMG_20131229_130606 (800x601)
IMG_20131229_140110 (800x599)
So that’s it?
I’m afraid it isn’t.Smile There are much more to do. I already have ordered a Parking distance sensor kit and a USB logic analyzer and couple more front/side view cameras. Ideas are boundless.Light bulb Only time is what I’m lacking of. Clock
[Posted with Windows Live Writer™ 2012 on Windows 7 64bit]