Showing posts with label BeagleBone Black. Show all posts
Showing posts with label BeagleBone Black. Show all posts

Monday, January 05, 2015

My QuickBot test with IR sensors

By following the Coursera course, Control of Mobile Robots[1] by Dr. Magnus Egerstedt, I've built my first QuickBot in which the BeagleBone Black is the core.

The course had been closed in several months ago, but I didn't get enough leisure time (and proper mood... maybe...) to complete the robot until these weeks. The following photos show the QuickBot:
Front view of my QuickBot
Top view; the BBB is on the left side

The mess of wires between the chassis
What I have done so far is to test the sensors and motors with the help of the testing code qb_test written by Mike Kroutikov. Because I've used the Sharp GP2Y0A41SK0F IR sensors which are different from the ones assigned in the course, I am not sure whether the output is identical to that given in the comment of the test code. Therefore, after some tests, I decided to modify the test code for the IR sensors to show the detected distances in centimetres[3].

I searched and found some conversion formulas for Arduino[2]:

source: http://www.dfrobot.com/wiki/index.php?title=File:Formulas.jpg

The trend of the output seemed right, but the absolute values were far from accurate. I might have to do some tests to find my own formula.

What I failed in the test was the communication between the host PC (running pysimiam) and the QuickBot's BBB (running quickbot_bbb). I have Wi-Fi adaptor connected to the BBB and it worked perfectly for accessing the internet, but I just couldn't connect the BBB wirelessly from my PC. I decided to postpone this part.

My next plans are:
  • To write some code to drive the motors with the IR readings as the reference;
  • to change the battery packs to the Li-Poly one.

---
[1] Without signing up the course, you may not be able to view the content. Here is the play list on YouTube: https://www.youtube.com/playlist?list=PLp8ijpvp8iCvFDYdcXqqYU5Ibl_aOqwjr . It has only the video course, however.

[2] http://www.dfrobot.com/wiki/index.php/SHARP_GP2Y0A41SK0F_IR_ranger_sensor_%284-30cm%29_SKU:SEN0143

[3] My modified code is here: https://github.com/hiankun/qb_test.git

Monday, November 10, 2014

Test OpenCV on BeagleBone Black using Logitech C920

Here are some basic trials in which I tested OpenCV running on my BBB.

The Logitech C920 webcam did some works which I don't know very well so that the loading on the BBB has been reduced significantly. Other webcams might too ``slow'' for the test program to run directly (I remember the terminal returned `select timeout' errors).

[NOTE: the following videos were boring and showed nothing exciting... :-p]
[Sorry for the small view of the videos. I will find how to enlarge them later...]
[I've uploaded the video clips so that you can view them with better resolution.]

The first one was the result shown via VNC. The image stream was laggy, but the processing time showed it was about 100 to 200 ms.


The second one showed the result without cv::imshow() via VNC. The processing time seemed reduced, but not significantly.



The last one showed the result without cv::imshow() via ssh. The processing time was no more than 100ms.



It seemed that the VNC costed most of the computing resource.


The test code was:

#include <stdio.h>
#include "opencv2/opencv.hpp"                                                                         
                                                                                                      
int main() {                                                                                          
    cv::VideoCapture cap(0);
                                                                          
    if(!cap.isOpened())
        return -1;               

        
    int64 e1,e2;
    double time;
                                                                                                      
    for(;;) {                                                                                         
                                                                                                      
        e1 = cv::getTickCount();
        cv::Mat frame;
        cap >> frame;           

        cv::imshow("match result", frame);                                                            

        e2 = cv::getTickCount();
        time = (e2 - e1)/cv::getTickFrequency()*1000.;

        printf("time: %f ms\n", time);
                                                                                                      
        if(cv::waitKey(30) >= 0) break;                                                               
    }                                                                                                 
                                                                                                      
                                                                                                      
    return 0;                                                                                         
}  

BeagleBone Black Wifi connection and VNC settings (Debian)

As mentioned in my previous post (Setting up the Wifi connection of BeagleBone Black (Angstrom)), I couldn't make Wifi connection with the Angsrom images, and decided to test Debian image again.

[A brief note for my first test with the Debian image]
Actually I installed the Debian image several days ago, and did set the Wifi connection successfully. When I tried to update the system, however, the terminal replied with error message said that my system had no enough space. So I went back to Angstrom. And now I'm back to Debian again.

The Debian image was large. After the installation, I checked the disk usage by typing ``df -h''... 93% used... It's crazy.


So, after reflash the on-board eMMC of BBB, I removed something like /usr/share/doc, Chromium, and even Vim (there's vi for later usage). This time, the system updated without errors.

The following paragraphs were my note on the Wifi settings of the BBB with Debian image, and then the VNC settings. Most of the steps were following the guide: BeagleBone Black Ubuntu WiFi Installation and Troubleshooting Guide.

PART 1 Wifi settings


Step 1: Make sure the system know the Wifi adaptor. Use ``lsusb'' and the system return the detected devices. In my case, it's the line with ``Ralink Technology, Corp.''

Step 2: Check ``/etc/rcn-ee.conf'' and make sure it contain the following settings:
Step 3: Edit ``/etc/network/interfaces'' with the following settings:
auto ra0
iface ra0 inet dhcp 
wpa-ssid your_network_name
wpa-psk your_hashed_password 
Finally, restart the BBB system.

PART 2 VNC settings

This part was easy. All the steps were the same as that of my another previous post (Connect to Beaglebone Black via VNC client in Ubuntu 12.04). The only different setting was the starting command of the VNC server (the BBB):
x11vnc -bg -o %HOME/.x11vnc.log.%VNCDISPLAY -auth /var/run/lightdm/root/:0 -forever

Tuesday, November 04, 2014

Failed to ssh into Beaglebone Black

Yesterday when I was trying to update the OpenCV in my BBB, a strange thing happened. After downloading and unzipping OpenCV 2.4.9 in BBB [1], I couldn't log into my BBB via ssh (but using the webpage still worked). The terminal responded nothing, and it just hanged there without logging in.

The Cloud9 IDE helped in the test. It connect to your BBB and allow you to do something with JavaScript (I tested two of them which will be listed below).

I searched and tested, the first script given in the mail list [2] didn't work to me. It returned ``it seems that you have another problem, sorry.''

Then I tested the second script [3]. After running that script I logged in BBB via ssh again.

Actually I still have no idea what'd happened. Maybe the resource of BBB had been run out after the downloading of OpenCV? Maybe something else caused the problem.

---
Edit:

I read the mail list again and found the post which listed the second script had said something may be useful. It talked about systemd-journal settings.

---
[1] I wouldn't do it again. At the beginning, I was planning to build OpenCV 2.4.9 in my BBB. Later, I read VAT's article and knew that I should use cross-compilation.

[2] The script:



var fs = require('fs');
var destroyed_key_file = '/etc/dropbear/dropbear_rsa_host_key';

fs.readFile(destroyed_key_file, function (err, data) {
  if (err) throw err;
  
  if( data===null || data.length===0 )
  {
    console.log("we have a corrupted host key file... try do delete it");
    fs.unlink(destroyed_key_file, function (err) {
    if (err) throw err;
        console.log('successfully deleted ' + destroyed_key_file);
        console.log('you should now reboot your beaglebone.');
        console.log('the /etc/init.d/dropbear script will create a new rsa host key file for you.');
        console.log('after the reboot you should be able to login over ssh');
    });
  } else {
      console.log("it seems that you have another problem, sorry");
  }
});

[3] The script worked for me:

var exec = require('child_process').exec;
function puts(error, stdout, stderr) { console.log(error); console.log(stdout); console.log(stderr); }

// 1 - Clear journal space
exec("df -h; rm -rf /var/log/journal/; df -h", puts);

// 2 - Remove Dropbear file
exec("rm /etc/dropbear/dropbear_rsa_host_key", puts);

// 3 - Stop Dropbear
exec("/etc/init.d/dropbear stop", puts);

// 4 - Start Dropbear
exec("/etc/init.d/dropbear start", puts);

Monday, November 03, 2014

Connect to Beaglebone Black via VNC client in Ubuntu 12.04

I am planning to run OpenCV sample code in the BBB, and some graphic outputs are necessary.

After some searches and tests, I made it. Here is the minimal steps.

Step 1: Make sure there's x11vnc in BBB which acts as the VNC server.

Step 2: SSH to BBB and run the following command:
x11vnc -bg -o %HOME/.x11vnc.log.%VNCDISPLAY -auth /var/run/gdm/auth-for-gdm*/database -display :0 -forever
The terminal will return the following message:

Step 3: Install xvncviewer in Ubuntu as the client viewer.

Step 4: Run xvncviewer and use ``192.168.7.2:5900'' to connect to BBB.

Here is the desktop of BBB:

Sunday, November 02, 2014

Setting up the Wifi connection of BeagleBone Black (Angstrom)

The Wifi adaptor was UWN200

Several months ago, I've followed the course of ``Control of Mobile Robots'' on Coursera. Although I've finished the course, but the hardware part has been postponed for these months.

I determined to record the tests on the hardware, and here is the first post on the topic.

The following procedure based on the course lecture.

Step 0: I used my mobile phone as the Wifi hotspot for the BBB internet connection.

Step 1: Connect the USB cable between the BBB and the PC. Plug the Wifi adaptor as well.

Step 2: Log in BBB using ssh. Just type the follows in the terminal of host PC:
ssh 192.168.7.2 -l root


Step 3: (from now on, all the commands will be working in BBB) Use the following command to get the hashed string which will be pasted in the configuration file:
wpa_passphrase "your network name here" 'your password here'
Step 4: Paste the hashed string into /var/lib/connman/wifi.config. The content of the wifi.config looks like:
[service_home]
Type = wifi
AutoConnect = true
Favorite = true
Name = your network name
Passphrase = your hashed password


Update:
I have encountered problems in the Wifi connection when I reflash my eMMC with new Angstrom images. I tried the newest version (2013.09.04) and an old one, but got no luck.

The newer Angstrom could identify the Wifi adaptor (by using lsusb, the terminal returned a message with the Wifi adaptor's company name), but all the same settings just couldn't make BBB connecting to the internet.

After trying for several days, I decided to go back to the Debian image again, and here is the note: BeagleBone Black Wifi connection and VNC settings (Debian).