Monday, 26 January 2015

i3 Window Manager - After 7 months.

So I've been using the  i3 window manager for quite a while now. And once in a while I miss some of the functionality that certain programs in Ubuntu provided. Especially some of the functionality of the network settings tool. So just for one evening I decided to switch over to the Gnome Desktop Environment.

I had to switch over to i3 within a few hours because after the wonderfully customizable and workflow friendly key combinations that I had set up in i3 fiddling about with the mouse on the desktop environment felt really clunky and frustrating. It took me more than twice as much time to do a simple task like open a text editor and start writing some C code.

Rich desktop environments like Gnome and Unity are good if you're a beginner or if you don't plan on using your computer for anything other than web browsing. But if you're into programming or doing anything even remotely technical with your computer, keyboard friendly tiling window managers like i3 will definitely increase your productivity.

Tuesday, 6 January 2015

Setting Up a Cool Dr. Who Wallpaper That Changes Every Hour on Linux

I came across this really cool idea by someone on reddit to take this awesome wallpaper of the 12 regenerations of the doctor and highlight each Doctor by the hour. This is easy enough to do on Windows which has wallpapers which can change every minutes. Being a user of linux, I was interested in trying to get a similar thing to work on linux.

First here is the set of all the wallpapers.

https://imgur.com/a/av5TP

Download the wallpapers and put it all in a folder somewhere on your system. Say you put it in /home/ash/Pictures/whopaper/

Rename each picture so that the filename corresponds the the regeneration number. The first doctor's highlighted picture should be named 01.jpg and the second doctor's should be named 02.jpg and so on till 12.jpg.

Then set up a cronjob that is executed every hour that checks the hour on the clock and sets the background to that. For doing this I installed a program called "feh" (sudo apt-get install feh) which allows me to set my desktop wallpaper from the terminal. I also installed a program called gnome-schedule (sudo apt-get install gnome-schedule) which allows me to easily edit the crontab file.

Run gnome-schedule and click on "New" to add a new cronjob. Select "A task that launches recurrently". Add a short description (like "Cool Doctor Who Wallpaper" and in the command field enter the following command:

env DISPLAY=:0 /usr/bin/feh --bg-scale "/home/rationalash/Pictures/Wallpapers/DRWHO/$(date +\%I).jpg">>sys.log Replace the path to the wallpaper in the command to the folder in which you saved the wallpapers. Under the "Time & Date" section select "Basic" and set the task to run every hour. And that's it! Now if you don't keep your computer on all the time the wall paper might be wrong for some time because the cronjob only runs every hour. If you want to be sure that the wallpaper is always the same as the hour on the clock even if your turn your computer on a lot edit the frequency of the cronjob so that it runs more often. (Say once a minute). The wrong wallpaper won't be there for longer than a minute. Monday, 8 December 2014 Using the ESP8266 WiFi module with an Arduino So I was pretty excited when I discovered the new cheap ESP8266 wifi module. It seemed too good to be true. I kept feeling that it's got way too many features for it's cost. There had to be a catch somewhere. But no! I had mine delivered to me a couple of days ago and it's the real thing! Of course, it's true that it's a bit difficult to get it working as the documentation available is mostly in Chinese but there are plenty of people working on a translation. I had a little trouble getting the thing working properly. So I'll give a short tutorial on how to get the module working with an Arduino so that others find it easier. First of all, here's the pinout of the module: That's the pinout when looking at the module from the side of the antenna. The antenna is that crazy trace that looks like a square wave. The module works on 3.3v. So wire up the Vcc pin of the module to the 3.3v pin of the Arduino. GND goes to ground. Both RST and CH_PD also goes to 3.3v. Now here's the tricky bit. The arduino is fine with reading incoming 3.3v signals on its digital input pins but the ESP8266 is NOT ok with incoming 5V signals from the Arduino. So use a simple voltage divider. (1k, 2k resistor) to step down the 5V signal from Arduino to 3.3V. Another point to note: The RXD of the ESP8266 goes to the RX pin of the Arduino (pin 0) and the TXD of the ESP8266 goes to the TX pin of the Arduino (pin 1). It looks like the Arduino has the labels the other way round. This is because when the Atmega IC is removed, the TX and RX pins are the RX and TX pins of the USB to UART bridge. When the IC is actually in the socket, I suspect that the TX of the module should go to the RX and the RX of the module to the TX of the Arduino board. I then removed the Atmega328 IC from the Arduino's socket and turned on the power. You should see a red LED light up on the ESP8266 indicating that the board is powered. A blue LED should briefly flash. That blue LED indicates serial communication. Now go to the Arduino IDE and open up the Serial monitor. Set the line ending to "Both NL and CR". Some ESP8266 modules come with old firmware that requires you to set the baud rate to 115200. Some modules come with the new version of the firmware and a default baud rate of 9600. So try out different baud rates if you get gibberish on the monitor. Once you find the correct baud rate try typing in "AT+RST" into the serial monitor. You should get some output. Here's what I get: The wifi module is controlled using "AT commands". There is a list of the available commands here. Say you want to connect to your home wifi network. First type in "AT+CWMODE?". This gives you the current mode the module is operating in. You need to set it to mode 3 if you want to connect to your home router. To set the mode to 3 use the command, "AT+CWMODE=3". Then type in "AT+CWLAP"(List Access Points). This will give you a list of available wifi networks. Hopefully, you see yours on the list. To join an Access Point I have to use the command "AT+CWJAP"(Join Access Point). The syntax is "AT+CWJAP="SSID","password". And there you have it! You've connected to your router with the ESP8266. There's all sorts of cool things you can do after this. You can set up a TCP or UDP server and start streaming sensor data for example. Maybe I'll write about that in the next blogpost. Wednesday, 5 November 2014 FPGA : A minor hiccup So I was happily working on my FPGA for a while on my Linux system. One day, due to some work I had to do on a piece of software that only worked on Windows, I had to boot into my windows partition. When one of my friends came over to take a look at the FPGA I plugged it right into the laptop because I already had a binary config file in the FPGA and all I needed was for the board to be powered up. Big mistake. The moment I plugged the fpga in, the red light on the board (which usually only comes on when the board i being programmed) came on and stayed on. And no matter how many times I re installed the drivers, the board just would not cooperate. I didn't really think much of it at the time. I thought that this was just a minor issue with the drivers on the windows side and thought that everything would be fine when I plugged my board in when I booted back into my Linux partition. The next day, I booted back into Linux and the board was doing the same thing. The red programming led was coming on but the board wouldn't work. I have no clue what happened but I wonder if it is related to that recent incident where the FTDI company pushed a driver update to windows that would brick fake ftdi chips that acted as a USB to UART bridge. The funny thing is, the Numato labs board doesn't have an ftdi chip on board. I think it has a PIC microcontroller programmed to do the USB to UART bridging. I wonder if the PIC device was emulating the ftdi chip? Or it could just be a coincidence. Whatever the case, the board was bricked. I sent an email to the Numato labs customer service people about the issue without really expecting a response. To their credit however, not only did they respond, they offered to replace my board with a new one if I shipped my bricked board back to them! :D Never expected that! So the new board arrived today and I plugged it in and everything seems to be working fine. Time to resume work on that project! :D Tuesday, 21 October 2014 An 8 bit counter on an FPGA So I finally got around to implementing an 8 bit counter on the FPGA that I recently acquired. Turned out to be a lot more difficult than I thought it would be mostly because I was a bit new to writing modules in verilog. I'm still at that stage of learning where I make silly mistakes which are simple but tedious to rectify. Also, the clock of the FPGA is 100MHz. So I also had to divide the clock down to some frequency that was visible to the human eye. But in the end I got it working! The FPGA itself is only just barely visible but I couldn't turn up the lights without completely washing out the blinking LEDs. Oh well ... I have this problem where I try to go to the advanced sections of new stuff too quickly and then give up because it looks too complicated. I have to keep telling myself to take things one step at a time and build up slowly to more advanced/complicated stuff. So now that this counter is done I think I'll search around for something that's a little bit more complicated than the counter but still within my reach. And slowly build up to something more complicated like Finite State Machines or VGA controllers. Sunday, 14 September 2014 Quality of YouTube Comments So it's common knowledge by now that if you want to see the most mind numbing, narrow minded side of humanity all you need to do is visit the comments section on an even slightly controversial YouTube video. However, I've noticed that the comments are not so bad at the start. I subscribe to a lot of popular channels on YouTube. That means I sometimes get to see the videos as soon as they're out. I've noticed that the comments are usually really nice and supportive at the start. But as the video gets more and more popular the racist/sexist/homophobic/narrow minded comments start pouring in. It's probably because at the start, most of the people who see the video are those who subscribed to the channel. And these will be people who actually like the person who makes the videos and appreciates them for putting in effort to make good content. Once the video percolates through to the general public however, mean people start spamming the section with comments. It's actually kind of sad to see the comment section slowly become filled with hateful negative comments and overwhelm the nice ones. Friday, 29 August 2014 Getting Started with FPGAs So after a lot of deliberation I've decided to start working with FPGAs. Ever since the Mojo came out I've been thinking about this. This semester I finally decided to go ahead and get an FPGA. I initially thought about getting the Mojo. I was reluctant because despite the claim that it is for hobbyists, it's not exactly cheap at Rs. 7500. So I decided to search for alternatives that used the same FPGA IC. After a lot of searching I found this FPGA development board called "Mimas" from Numato Labs. They were selling this board at Rs. 3000 on Amazon. That was less that half the cost of the Mojo! So after a lot of searching and comparison of specs I finally decided that I'd get Mimas instead of Mojo. This board also has the additional advantage of 4 on board switches. The Mojo has none. Here's the FPGA in all it's glory! :D After I got the board the next step was getting the Xilinx ISE from their website. This was a big Pain In The Ass. The installation file was 6.1 GB and would take ages to download using my sort of slow internet dongle. The download was resumable but something would always go wrong at about 4 GB and the download would start over. In the end I had to start the download at 4.00 am in the night (When the college wifi is fast) and I had it downloaded in about 2 hours. I think it's a real shame that Xilinx doesn't distribute the software over a protocol that is more suited to resuming large downloads (maybe a torrent?). Getting my hands on the FPGA was way simpler that downloading the software. Anyway, I started the installation after checking the md5sum of the download and everything seemed to be fine! I implemented some basic combinational logic circuits on the board to check if everything was working fine. I'll be implementing something a little bit more interesting (like a counter maybe?) and then I'll upload a video of the board working! :D Sunday, 13 July 2014 Inverse Kinematics: Part 2 On to part two of exploring inverse kinematics! This time I think I will add two additional degrees of freedom to the arm and calculate the inverse kinematics.$l_1$- Length of the first link$l_2$- Length of the second link$l_3$- Length of the third link$\theta_0$- The angle of the base drum.$\theta_1$- The angle of the first link from the ground$\theta_2$- The angle of the second link w.r.t the first$\theta_3$- The angle of the third link w.r.t the second First let's ignore the third link and consider the two links plus the rotating base. This extension is relatively simple to handle. If the value of$\theta_0$is found then the problem can again be reduced to a planar 2D problem which already has a nice solution. It's easy to see that:$\theta_0 = atan2(z, x)$Once this is found, then we can find the absolute distance in the x-z plane$d = \sqrt{x^2 + z^2}$. Then the inverse kinematics for the two links can be found by replacing$x$with$d$in all the equations. Now it's time to add the third link into the equations. This third link is special. It's not really an additional degree of freedom. Two links and a rotating base are all that's needed to reach any point in 3D space. So why the third link? Imagine that there was a gripper attached to the third link. This gripper grabs a glass of water. If that third link were not there, this gripper would tilt with the angle of the second link and whatever liquid is in the glass would spill all over the place. This third link in the arm will adjust its angle to the second link so that it maintains a constant angle from the ground plane. Now if the arm is holding a glass of water and moving around, the glass will always be pointed in the right direction. It won't tilt and spill its contents all over the place. Let the constant angle between the third link and the ground be$\phi$degrees. Applying this constraint we get:$\theta_3 = \theta_1 - \theta_2 - \phi$. So all we need to do is subtract the vector of the third link from the target coordinates, apply the 2-link plus base inverse kinematics on this coordinates and then calculate phi using the value of$\theta_1$and$\theta_2\$ that we get from those calculations.

I've implemented all this in the invkin4() function in this python script.

I'll post a processing simulation of this soon. I'm still fiddling around with the P3D. I haven't got used to it yet.