Showing posts with label Userspace. Show all posts
Showing posts with label Userspace. Show all posts

Sunday, May 17, 2015

How to download all Gazebo models


Gazebo is a wonderful simulation tool widely used in robotics projects. The project includes a library of 3D models that are automatically downloaded on demand. However this makes the application pause each time a model is used for the first time, which can take a considerable time depending on connection speed and interfere with the flow of work.

In order to avoid this issue I wrote the below script to do a bulk download of all models in the Gazebo library, then copy them to the local model folder. Simply copy the lines below to a script file on a convenient local folder and run it from a command prompt.
#!/bin/sh

# Download all model archive files
wget -l 2 -nc -r "http://models.gazebosim.org/" --accept gz

# This is the folder into which wget downloads the model archives
cd "models.gazebosim.org"

# Extract all model archives
for i in *
do
  tar -zvxf "$i/model.tar.gz"
done

# Copy extracted files to the local model folder
cp -vfR * "$HOME/.gazebo/models/"

Monday, April 27, 2015

Building OpenCV's HTML documentation

OpenCV has become the de facto standard vision processing library, but the project remains surprisingly obscure in several areas, particularly in relation to building and installation tasks. For example, it took me a couple hours to discover how to build the project's HTML documentation (though to be fair, I was looking into it concurrently with other work).

For those also struggling with this, see this question in the OpenCV Q&A site. In short, it gives the following instructions:
  1. Install Sphinx;
  2. Run cmake on your OpenCV source base as explained in the installation instructions, perhaps adding the -D BUILD_DOCS=ON option for good measure;
  3. Run make html_docs to build the documentation in HTML format.
If everything goes well the HTML documentation will be built to the subfolder doc/_html/ inside the build output folder. If not, check if the output of the cmake call reported items Build Documentation and Sphinx both set to YES. You may also check the cmake script cmake/OpenCVDetectPython.cmake inside your OpenCV source base for potential problems.

Wednesday, April 8, 2015

Internet sharing for Intel Edison on Linux

Recently I got hold of an Intel Edison with accompanying Arduino Expansion Board. The awkward development setup process (which requires two separate USB cable connections to a host computer) didn't make for a stellar first impression, but the possibilities of a full x86-64 computer that fits in a matchbox are intriguing. Of course, the fact both Linux and ROS are more-or-less readily available for the platform made the whole proposition a lot more interesting.

After flashing Edison with ubilinux the first order of business was getting the thing connected to the Internet. Edison includes an on-board wi-fi card and can simulate an ethernet port through its USB connections to the host computer, but bureaucratic questions would make a direct connection to my lab's network difficult. So I set up my notebook (Edison's host computer) as a local gateway, enabling Internet sharing through the virtual usb0 interface.

The procedure documented below was developed on a Kubuntu 14.04 host and ubilinux Edison unit, but it should be adaptable to other Linux distributions. It is largely based on a previous post on wireless Internet sharing; in fact that may be a better option, if unlike me you have a wireless interface to spare.

First open a command prompt and start a root session with su, then follow the steps below:

Step 1: Install Dnsmasq

Dnsmasq is a tool for setting up small networks. Install it from the command line by typing:
apt-get install dnsmasq
As it is the dnsmasq service will be automatically started when the computer boots, but we need better control than that. So change the default settings to manual start:
update-rc.d -f dnsmasq remove

Step 2: Configuration Files

Create or update the following config file with the contents below:

/etc/dnsmasq.conf
# disables dnsmasq reading any other files like /etc/resolv.conf for nameservers
no-resolv
# Interface to bind to
interface=usb0
# Specify starting_range,end_range,lease_time
dhcp-range=usb0,192.168.100.100,192.168.100.199,12h
# dns addresses to send to the clients
server=8.8.8.8
server=8.8.4.4

Step 3: Interface Scripts

Add the scripts below to your system:

/usr/local/bin/usb0start.sh
#!/bin/sh

ETH=eth0
USB=usb0
IP=192.168.100.99
MASK=255.255.255.0

# Enable IP forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward

# Setup USB interface
ifconfig $USB up $IP netmask $MASK

# Start dnsmasq
/etc/init.d/dnsmasq start

# Enable NAT
iptables --flush
iptables --table nat --flush
iptables --delete-chain
iptables --table nat --delete-chain
iptables --table nat --append POSTROUTING --out-interface $ETH -j MASQUERADE
iptables --append FORWARD --in-interface $USB -j ACCEPT

/usr/local/bin/usb0stop.sh
#!/bin/bash

USB=usb0

# Stops DNS making service
/etc/init.d/dnsmasq stop

# Asked nice the first time...
killall dnsmasq

ifconfig $USB down
Make sure to create the scripts from the root account, so they'll have the right ownership. Also don't forget to give them running permission:
chmod +x /usr/local/bin/usb0start.sh
chmod +x /usr/local/bin/usb0stop.sh

Step 4: Edison Configuration

Connect Edison to the host computer and start a remote session. Change the following configuration file as below:

/etc/network/interfaces
# Disable auto connection, enable DHCP
iface usb0 inet dhcp
#auto usb0
#iface usb0 inet static
#    address 192.168.2.15
#    netmask 255.255.255.0

Usage

After performing the steps above, you should be able to start the local gateway by running the usb0start.sh script:
sudo /usr/local/bin/usb0start.sh

Then on the Edison environment, start the usb0 interface:
ifup usb0

After you're done with Edison, the gateway can be deactivated by running the usb0stop.sh script:
sudo /usr/local/bin/usb0stop.sh

Troubleshooting

If Edison cannot lease an IP from the host computer or see IP addresses beyond the gateway, you can enable logging on Dnsmasq by adding the following lines to the /etc/dnsmasq.conf file:
log-queries
log-dhcp

Then use tail -f /var/log/syslog to check for messages.

On Kubuntu the network manager tried to setup the usb0 interface using eth0's configuration every time it was turned on, messing the DHCP service. This was solved by explicitly binding the configuration to eth0 on the network manager's GUI.

Saturday, July 13, 2013

Setup a Wireless Access Point with Linux Mint 15 (Olivia)

In these days of tablets, smartphones and other "connected" devices, the ability to share a fast wired Internet connection via wi-fi can be very useful, specially at home or small offices. Wireless routers aren't very expensive and are simple enough to install – yet I have always thought they're kind of wasteful, considering most computers today ship with wi-fi interfaces, or can be fitted with USB cards that sell for pennies.

With Linux, wi-fi interfaces can be configured to operate in master mode, so they can accept client connections just like a dedicated router would. This is a huge improvement over "ad-hoc" wi-fi network sharing, because:
  1. Many mobile devices do not connect to "ad-hoc" access points;
  2. The WEP authentication standard used on those connections is known to be flawed, in contrast to the newer WPA standard used in "master mode" connections.
Today I updated my desktop to the latest Linux Mint 15 (Olivia), and as I went about configuring a Wireless Access Point (WAP) on it for my other devices, I took the time to document my changes to the system, so I can more easily reproduce them in future upgrades – and hopefully, also help others to setup a WAP with Mint.

The procedure I came up with was largely inspired by this blog post. It assumes the existence of a wired interface eth0 (which provides access to the Internet) and a mac80211-compatible wireless interface wlan0 (which will be configured to accept client connections in "master mode").

First open a command prompt and start a root session with su, then follow the steps below:

Step 1: Install Applications

Type the command below to install the required services:
apt-get install hostapd dnsmasq
As it is the services will be automatically started when the computer boots, but we need better control than that. So change the default settings to manual start:
update-rc.d -f hostapd remove
update-rc.d -f dnsmasq remove

Step 2: Configuration Files

Create or update the following config files with the contents below:

/etc/hostapd/hostapd.conf
interface=wlan0
driver=nl80211
ssid=hotspot # Your WAP name, change it to something more unique
hw_mode=g
channel=6 # You may want to change this if the channel is too crowded
wpa=1
wpa_passphrase=hotspot_password # Password for clients
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP CCMP
wpa_ptk_rekey=600

/etc/dnsmasq.conf
# disables dnsmasq reading any other files like /etc/resolv.conf for nameservers
no-resolv
# Interface to bind to
interface=wlan0
# Specify starting_range,end_range,lease_time
dhcp-range=10.0.0.3,10.0.0.20,12h
# dns addresses to send to the clients
server=8.8.8.8
server=8.8.4.4

Step 3: Interface Scripts

Add the scripts below to your system:

/etc/network/if-up.d/wapstart
#!/bin/sh

WIRE=eth0
WIFI=wlan0

# Only run script for wired interface
if [ ! "$IFACE" = "$WIRE" ]
then
    exit 0
fi

# Setup wireless interface
ifconfig $WIFI up 10.0.0.1 netmask 255.255.255.0

# Start dnsmasq
/etc/init.d/dnsmasq start

#Enable NAT
iptables --flush
iptables --table nat --flush
iptables --delete-chain
iptables --table nat --delete-chain
iptables --table nat --append POSTROUTING --out-interface $WIRE -j MASQUERADE
iptables --append FORWARD --in-interface $WIFI -j ACCEPT

# Start the Wireless Access Point service
/etc/init.d/hostapd start

exit 0

/etc/network/if-post-down.d/wapstop
#!/bin/bash

WIRE=eth0
WIFI=wlan0

# Only run script for wired interface
if [ ! "$IFACE" = "$WIRE" ]
then
    exit 0
fi

# Stops Wireless Access Point services
/etc/init.d/hostapd stop
/etc/init.d/dnsmasq stop

# Asked nice the first time...
killall dnsmasq
killall hostapd

ifconfig $WIFI down
Make sure to create the scripts from the root account, so they'll have the right ownership. Also don't forget to give them running permission:
chmod +x /etc/network/if-up.d/wapstart
chmod +x /etc/network/if-post-down.d/wapstop

Usage

After performing the steps above, you should be able to start the WAP by stopping and restarting the wired interface:
ifconfig eth0 down
ifconfig eth0 up
From now on it will also be automatically started at boot time.

Troubleshooting

If your devices can see and connet to the wireless hotspot, but they cannot access the Internet, enter the command below:
sysctl -w net.ipv4.ip_forward=1
This will update kernel settings to enable IP forwarding, and only has to be issued once.

Depending on your distribution, hostapd may require that the wireless interface be either turned "on" in the network manager applet (e.g. Mint 15), or excluded from Network Manager control (e.g. Kubuntu 14.04). In the second case add the following to /etc/NetworkManager/NetworkManager.conf:
[keyfile]
unmanaged-devices=mac:mac_address_of_wireless_interface
Also check /etc/init.d/hostapd for whether the variable DAEMON_CONF is set; if not, set it to the path of the config file:
DAEMON_CONF=/etc/hostapd/hostapd.conf
If nothing else works, you can try to find the cause by running hostapd directly instead of in service mode, with extra logging options enabled. For example:
hostapd -d /etc/hostapd/hostapd.conf

Saturday, January 19, 2013

Genkou Youshi Template for OpenOffice / LibreOffice

Writing assignments on genkou youshi are a staple of Japanese language classes. Tradition and the need to practice Kanji writing often dictate that such works be handwritten, but there's no reason one couldn't first compose the text on a computer (where editing, revision and indeed writing itself are much easier) and only reach to paper and pencil when the final version is ready.

Experience has taught me that hand-copying texts from a computer screen is much quicker and less error-prone when both digital document and paper share the same layout, and of course it's best if I can print genkou youshi sheets at my own leisure, rather than go out and buy them (not many stationery shops this side of the world have them, anyway). Searching the web it is relatively easy to find a genkou youshi template for Microsoft Word, but Open Document Format equivalents are harder to come by – and while it's possible to use the Word templates on OpenOffice / LibreOffice, rendering problems such as misaligned grids and hidden hanging punctuation are often present, which is kind of frustrating for a die-hard Linux user like me.

Today as I sit down to try and create a genkou youshi template on LibreOffice, I decided to try and look it out one last time – and there I found a genkou youshi Open Template on the OpenOffice Templates web site. I'm kind of baffled as to how I didn't come across it earlier (apparently it was uploaded in 2009), so I thought I'd link to it here, so others who might also be looking for it have a better chance of finding it. So there.

Friday, April 9, 2010

Fixing Windows Live Messenger's Sign-in Issues

Possibly this is old news for everyone else, but until recently a lot of MSN users from where I work (including me) were reporting sign-in issues on Microsoft's Windows Live Messenger client. No definitive solution was ever found: I and a couple others switched to Pidgin – which works as long as it's configured to connect over HTTP – but most have simply stuck to older Messenger versions which are known to mostly work.

Today, while looking for references about Windows Mobile's Messenger client, I stumbled upon this article on a registry-based fix for the issue. I don't use Microsoft's client anymore, so I haven't tried it; but it's worth a shot if you'd rather not switch softwares. See also this comment about an alternative, if more radical, solution.

Friday, February 8, 2008

Reclaiming your memory from Windows XP

How about getting Windows XP to run into just below 70MB of memory?



Then follow these three steps:

1 - Disable the wallpaper

I've always used wallpapers, ever since I started using Windows (back in the 3.11 days). But I have to admit: these things eat up a lot of memory, are pretty much useless, and most of the time are buried under a stack of windows, where nobody can look at them! So our first step towards a lower Windows baseline is to give up a bit of aesthetics in favour of improved functionality.

2 - Lower color depth and screen resolution

This may not be acceptable to everyone, but if you are a software developer like me, chances are you'll barely notice the difference in color depth. And you may even be doing your eyes good by settling to slightly bigger visual objects. So, our second step is to lower video settings to something more affordable. If your machine uses a shared memory architecture, you may also lower the amount of memory reserved to video.

3 - Turn off the virus scanner

It may be a bit of a temerity, this being Windows and all; but there are scenarios where you can sanely do without a virus scanner. Particularly, if you are (like me) working inside a virtualized environment, you can isolate the virtual machine from the network, relying on the host OS for all remote accesses.

If you follow all three steps, you'll end up with a much lower memory baseline – without having to resort to obscure (and in my experience, ineffective) tricks such as turning off Windows services. For some this may not be a viable long-term solution, but since it's easy to roll those changes back, it may do when you have an immediate need to get more free memory.

Monday, December 17, 2007

Fixing the "ever-changing prompt problem" on Mac OS X 10.4

The other day I fired xterm while hooked on my home Internet access, and found the hostname on my prompt changed from the machine name to some strange letters-and-numbers string. Apparently this is a known issue, and the traditional solution is to hard code the machine name into the prompt; there is, however, a more ellegant way. Using the scutil command to get the machine name from your System Preferences, not only will you get the right name, but it will also consistently reflect your Sharing settings.

The syntax for getting the machine name with scutil:

scutil --get ComputerName


So, for example, to have a prompt containing the user name, the machine name and the current directory, we could add to our startup script something like:

PS1='[\u@`scutil --get ComputerName`:\W]\$ '


Were you to ever change your machine name, this configuration would automatically reflect it on your terminal prompt.

Wednesday, September 12, 2007

Hacking my way to Parallels Tools for Linux

So it turns out both the Windows and Linux machines formerly used in the Artificial Vision project are dead, yet I am supposed to hack toghether a demonstration version of our software for a fair the company is to attend. Since there is no hope in waiting for replacements, I decided to take my own MacBook and continue development on a pair of virtualized environments created over Parallels Desktop – which would be the equivalent to VMware in the Mac world.

For the Linux environment, I picked Kurumin Light, a lightweight version of the Knoppix-based Kurumin Linux distro. Installation went almost without incidents, save for one: in order for the virtual environment's graphical resolution match the dimensions of the enclosing window (and thus make the best possible use of the display), a set of extensions bundled with Parallels Desktop, called Parallels Tools, needs to be installed. Problem is, when I tried to install it, the procedure ended abruptly with a Unable to get layout name error message. A quick Google search led to two forum threads discussing the error, but none getting to a solution; so I decided to try and solve it myself.

Peeking into the installation file, I found it to be a self-extracting GZip archive, which I later found gets extracted to a temporary directory called /tmp/selfgzXXXXXXXXX -- where XXXXXXXXX is an arbitrary number -- in the beggining of the procedure. Among the extracted files, there is a script called xserver-config.py, which rewrites the X Server confguration file: it is this script that fails to find the X Server layout name, causing the installation to fail.

With this in mind, I devised the following walk-around to the Unable to get layout name error. All these steps must be executed from a root account:
  1. Run sh parallels-tools.run, but don't confirm the installation just yet;

  2. Open the /tmp/selfgzXXXXXXXXX/xserver-config.py script file on a plain-text editor. Change line 273 from

    layoutId = None

    to

    layoutId = "Default Layout"

    or any other name to your liking. Don't forget to save;

  3. Confirm installation. Hopefully the script will now execute without errors;

  4. Open /etc/X11/xorg.conf (or the equivalent X Server configuration file on your distro) and locate the "ServerLayout" Section. You'll notice there are two Identifier entries, consequence of the configuration script not telling apart its elbow from its ass... I mean, telling apart the Identifier entry on the original config file. This situation is bound to crash your X Server upon restart, so comment the original entry off. Also, if you'd like to make sure your pointer device will work properly, locate all "InputDevice" Sections with an Identifier value of "Parallels Mouse" and comment them off, save for one -- which one will depend on your system settings, but the entry with an Option value of "Device" "/dev/input/mice" is probably your best guess, if you aren't X Server savvy;

  5. Restart your X Server, for example by hitting Ctrl + Alt + Backspace.

After executing these steps, I found pointer integration as well as dynamic resolution resizing were working – that is, until I restarted the virtual machine, and learned I would still have to add the "prluserd" service to the list of automatically started services. (Alternatively, I could start it by hand each time, by calling "prluserd" from a root terminal window, and then restart X. But I am not that crazy.)

I hope these steps work for others that are facing problems with Parallels Tools installation on Linux, though as usual I make no guarantees. Parallels Desktop is a wonderfully useful software, and with interface integration on, it enables a very pleasant virtualization experience.