Monday, 18 September 2017

Putting some of my Python knowledge to a good use: a Reddit reading bot!

One of the perks of knowing a programming language is that you can build your own tools and applications. Depending on what you need, it may even be a fast process since you usually do not need to write production grade code and a detailed documentation (although it might still be helpful in the future).

I’ve got used to read news stuff on Reddit, however, it sometimes can be a bit time consuming since it tends to keep you wandering through every and each rabbit hole that pops up. This is fine if you are commuting and have just some spare time to spend on browsing the web but sometimes I just need a quick glance at what’s new and relevant to my interests.

In order to automate this search process, I’ve written a bot that takes as input a list of subreddits, a list of keywords and flags and browses each subreddit looking for the given keywords.

If a keyword is found inside either the body or in the title of a post which has been submitted in one of the selected subreddits, the post title and the links are either printed in the console or saved in a file (in this case the file name must be supplied when starting the search).

The bot is written using praw.

Sunday, 3 September 2017

Let Python do the job for you: AutoCAD drawings printing bot

Recently I’ve been getting familiar with AutoCAD and at the same time I’m trying to improve my Python skills. Odd mix, huh?!

While trying to improve my Python skills I thought I could exercise myself on automating boring tasks. I remembered that a few years ago I was given a boring job which involved printing a lot of drawings directly in PDF format from Autocad. I was too lazy to print the drawings one by one and I knew the process could be automated. At the time I put together a Python script that did the job fine, but it was a bit messy. I thought I could make an improved version.

When nice APIs are not available, such as in the case of AutoCAD (at least that was the case a few years ago, nowdays things may have changed), using Pyautogui may help in the task of automating boring tasks.

Saturday, 2 September 2017

How would you make a very simple and rotating magnetic field starting from a three phase power supply?

Recently I had a brilliant idea :D why not make a rotating magnetic field that can rotate a needle of a compass? (or any other magnetic needle for that matter).

Ok but the design must be very basic. One possible option would be the following:

Image 34

Simulation of the electric field of a three phase cable using FEMM

Finding analytical solutions to physical problems is always nice and rewarding, however it can be a bit of a pain when the geometry of the problem (just to mention one possible hustle) becomes more complex than just a sphere, a cylinder or any other basic shape.
If you think of a simple cable, with a copper core and a PVC insulation, calculating the electric field generated in the insulation layer using pen and paper may still be feasible, however, using FEMM greatly improves your life when doing calculations as an engineer, student, or “just” curious person.
This simple cable can be modelled using FEMM as follows

Image 20

The cable has a total diameter of 7 cm, with a first PVC insulation with a radius of 2.6 cm, a 0.05cm air gap and another PVC insulation layer.

Friday, 1 September 2017

Magnetics simulation with FEMM

FEMM stands for Finite Element Method Magnetics, and it is a nice software for solving magnetics and electrostatics problems.

I’ve known FEMM for at least a couple of years but I’ve never tried  it out and used it at its full power! Now the time has come to do that!

Image 1

In this post I’m going to present the results of the following simulations:

  1. A C shaped electromagnet (detailed results).
  2. The magnetic field of the rotor of a 4 poles synchronous machine (brief overview).

Wednesday, 30 August 2017

Another typical control problem: balancing a ball on a beam

Balancing a ball on a beam is not a common problem you may face during your everyday life, however, this simple example of engineering can be extended to more complex problems and, in general, to other more interesting control problems such as

  • Control of temperature in a room
  • Control of robots
  • Control of automated cars
  • Control of industrial processes

The main problem tackled in this article is the design and implementation of a basic PID based controller to control the position of a ping pong ball on a beam. Ideally the controller should be able to set the position to whatever value of the x axis the user decides to apply. This is a simple scheme of the physical system

schema1

Modelling a DC motor using LTspice, Simulink and Matlab

Electrically speaking, a permanent magnet DC motor can be modelled as follows:

Image 1

applying LKT we obtain the following differential equation

$$v = Ri+L\frac{di}{dt}+e$$

where $R$ is the equivalent resistance of the brushes plus the windings, $L$ is the inductance as seen from the external terminals of the motor and $e$ is the back EMF. Usually R is very small and can be difficult to measure with a multimeter. The back EMF can be expressed as a function of the speed of the motor $e = k\phi\omega$.

Friday, 4 August 2017

Taylor series with Python and Sympy: Revised

More than 2 years ago I wrote a short post on Taylor series. The post featured a simple script that took a single variable function (a sine in the example), printed out the Taylor expansion up to the nth term and plotted the approximation along with the original function. As you can see on the right on the “Popular posts” bar, that post is one of the most popular and I’m told it appears among the first results on Google.

Figure_1-1

The script I wrote originally was a bit clunky, and there surely was room for improvement. Last week I received an email from a reader, Josh, who sent me an improved version of the original post.

Thursday, 18 May 2017

Lighting your garden with LED lights and the sun: a DIY project, part 2.

Some time ago I wrote a short article on a small circuit I made to power on and off my garden lights using only a handful of components and some patience. Since then, however, I’ve dug deeper and found out some other good solutions to the problem.

A quick recap of the problem: At dusk and dawn I’d like my garden lights (powered by 12V DC batteries) to switch themselves on and off without me doing anything: a first step towards total automation ;)

Image 2

My first try at accomplishing this task was using a simple BJT with a voltage divider specifically design to allow a certain bias current when it gets dark. See here for more information on this first raw trial.

Tuesday, 2 May 2017

Current sink: one of my first experiences with Eagle

I’ve learnt a few things the hard way while messing around with electronic circuits, here is a basic summary:

Sunday, 5 March 2017

Resizing spatial data in R

Here I am after a short break, writing again about R!

In december I worked on a project that required me to work on spatial data. This led me to learn about how R deals with this kind of data and to look around for ways to make my “spatial data experience” less painful. I discovered that R is, as always, full of options.

I’m used to dplyr for exploring data and manipulating it, however when it comes to spatial data, I think that gstat, raster and rasterVis are just some of the useful packages that will make your life a lot easier.
Rplot01