Sunday, 29 June 2014

[x-post] Weekly Lab Tours

I wrote a guest post on the EPFL Research Internship blog today:

Weekly Lab Tours

The EPFL research internship places students in a unique setting, where the departments are extraordinarily interdisciplinary. When I first arrived, I began touring labs on my own, eager to find out more about ongoing work at EPFL. However, after conversations with other students, I realized that they too were interested in pushing the boundaries of their current knowledge. This curiosity is a characteristic of the group that I deeply respect, and in retrospect it could almost be predicted from people who are willing to uproot and relocate overseas for an entire summer.
From these experiences, I proposed a series of lab tours. Each week, a student leads his/her peers through an overview of ongoing work, giving the rest of us a chance to see what is going on outside the walls of our own labs. I am happy that people were receptive to these tours, because it exposes everyone to new information, inspiration, and ideas. On the flip side, it’s also a fantastic opportunity for the presenters to further develop their speaking skills and obtain a holistic picture of their lab. For me, it’s wonderful to see how diverse my cohort’s interests are, and to be able to learn about topics that I otherwise would not have a connection to.
Below are some pictures from when Manan, Jessica, and I presented the Reconfigurable Robotics Lab:
IMG_0390
Jessica, describing how pneumatic actuators behave.
IMG_2957
Manan, explaining his work on the rat exoskeleton.
IMG_0388
Ben, presenting an overview of the lab.
Benjamin Shih, Carnegie Mellon University
Reconfigurable Robotics Lab @ EPFL

Original post: http://epflresearchinternships.org/2014/06/29/weekly-lab-tours/

Thursday, 19 June 2014

Find and Replace in VIM

:%s/[find]/[replace]/g

http://vim.wikia.com/wiki/Search_and_replace


Monday, 16 June 2014

OpenCV: Video Properties

You can use the VideoCapture::get command in OpenCV to obtain video properties like time.



http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture-get

Manipulating OpenCV windows

namedWindow to open a new window.
moveWindow to move to a new location.
resizeWindow to resize - works only if you disable the flag that maintains the image ratio.

http://docs.opencv.org/modules/highgui/doc/user_interface.html?highlight=namedwindow


Assigning priority to a window:
http://stackoverflow.com/questions/5960968/opencv-window-always-on-top

Wednesday, 11 June 2014

Trimming videos on MacOS

OpenCV has codec issues with MacOS. Need to use ffmpeg or another encoder but there are lots of problems there with versions and libraries.

For a quick solution, open the video in QuickTime, use the trim function [cmd T], and drag and drop the boundaries of the video to what you want. Much simpler than OpenCV method.

Monday, 2 June 2014

Selecting Battery Type

Prereqs: This guide assumes basic knowledge of voltage, current, charge. Knowledge of dimensional analysis is helpful. Chemistry and materials are mentioned, but not explored in-depth. I refer often to the analogy between electrons and water, so I apologize if that is unhelpful.
  • Common Ways to Power a Project
    • AC to DC power supplies.
      • Typically found as wall adapters.
      • Use case: when you have a fixed voltage/current. 
      • Because long distance transmission is AC, so the electricity from your wall is AC, while most electronics use DC.
      • Ex: computer, laptop.
    • Variable DC power supply.
      • Use case: regularly testing various circuits.
        • Good for imposing a current limit on sensitive electronics, using fuses.
    • Portable batteries.
      • Use case: portable projects.
    • USB cable.
      • Use case: Simpler projects that require a fixed voltage/current.
    • Voltage regulation: Great protection for your circuitry if you're unsure about the input voltage source.
      • Analogy (regulator): Let's say you have a watermill that will only spin if given a range of input flow. Regulators are like pipes that control the flow into your watermill, so that your initial water source can have a larger flow rate.
  • Create a Power Budget
    • Estimate the voltage, current, and duty cycle requirements for each system component.
    • Based on these estimates, figure out total energy requirements. (Units of W-h, equivalent to Joules). 
    • Factor in energy lost from converting voltages (approximately 5% to 80% loss).
      • Use switching regulators, rather than linear, to minimize this loss.
    • Add in a margin of error for the estimated power (10% to 20% should be good). 
    • Estimate how long the system should run for. 
      • Multiply your average current by the amount of time to get units of A-h.
    • Find a battery that contains more charge than what your system needs to run for the desired duration.
  • Battery Selection Parameters
    • Size
      • Cell
      • Coin
      • "Standard small" - AA, AAA
    • Weight and power density
      • Performance tradeoff: higher quality == higher price == higher power density.
      • If weight is an issue for your project, then it will likely be more expensive as you need high-density.
      • Units: Watt-hours per kilogram
    • Price
      • Directly proportional to power density and power capacity.
    • Voltage
      • Determined by internal chemistry.
        • Alkaline: 1.5V
        • Lead-acid: 2V
        • Lithium: 3V
      •  Often connected to obtain desired voltages. 
      • Nominal measurement, the actual voltage can fluctuate.
        • ex: 1.5V AA battery starts out at 1.6V and drops to 1.5V, then slowly drifts to 1.0V which is when the battery is considered dead.
          • Analogy (voltage drift): Think of it as a water tank application where you require a certain water pressure, but the water drains off at a certain point so once the water level falls below the second threshold the water pressure can no longer be used.
    • Re-usability
  • Battery Geometry Parameters
    • Capacity
      • Analogy (capacity): the size of the water tank.
      • Amount of energy stored in the battery (Watt-hours [Wh])
        • "The terms power and energy are frequently confused. Power is the rate at which energy is generated or consumed and hence is measured in units (e.g. watts) that represent 'energy per unit time'."
      • Equivalent to voltage that the battery provides * current battery provides * duration of the amperage provided.
      • Voltage is essentially fixed for a battery type due to the internal chemistry.
      • ex: 1 Ah means that in theory we can draw 1 Amp of current for one hour, or 0.1A for 10 hours, or 0.01A (also known as 10 mA) for 100 hours.
    • Capability or Discharge Rate
      • Analogy (capability): the size of the water tank's dispensing pipe.
      • Amount of current we can actually draw.
      • Often limited. "For example, a coin cell that is rated for 1 Ah can't actually provide 1 Amp of current for an hour, in fact it cant even provide 0.1 Amp without overextending itself. Its like saying a human has the capability to travel up to 30 miles: of course running 30 miles is a lot different than walking!"
        • This can be attributed to chemical properties and reaction rates.
        • Datasheet information of interest is a plot of Voltage (V) vs. Discharge Capacity (mA-h).
      • Power capability is measured in C (units are equivalent to Coulombs). Higher C means more current can be drawn from the battery without prematurely exhausting it. 
        • Lead acid batteries have high C values (> 10C).
        • Lithium coin cells have low C values (< 0.01C).
  • Battery Chemistry
    • Lead Acid
      • Pros: Cheap, powerful, rechargeable, high power output capability, high cycle count.
      • Cons: Heavy, low power density (form factor is large bricks). 
      • Commonly used in machinery, uninterruptable power supplies, robotics, and systems where a lot of power is needed and weight is not as important.
      • Manufactured in 2V cells, subsequently commonly packaged as 2V, 6V, 12V, or 24V.
      • Pricing: 12V with 7A-h of charge ~= $25.
      • Power density: 7 W-h/kg.
    • Alkaline
      • Pros: safe, long shelf life, lightweight.
      • Cons: Not rechargeable, low capability, low capacity, expensive.
      • Higher power density than NiCads, slightly better power density than NiMH.
      • Nice property of having multiple cell sizes with a standard voltage is that you can select a different size when you need different capacities and capabilities. 
      • Discharge at 0.1C.
      • 9V batteries are essentially made of coin cells, which means that they have low capacity, low capability, and high price. Not recommended if drawing more than 20 mA.
      • Pricing: AA size with 3 A-h charge capacity ~= $1.
      • Power density: 100 W-h/kg.
    • Nickel Cadmium (Ni-Cad)
      • Pros: cheap, rechargeable.
      • Cons: relatively low power density, requires periodic full discharge/recharge cycles to reduce memory effect (growth of crystals on the battery plates), contains toxic metal. 
      • Much lower power density than NiMH, although they are cheaper. 
      • Good for when performance is not as important as price. 
      • Slower discharge (shelf life) than NiMH.
      • Cells quantized to 1.2V, often bundled as 3 for 3.6V.
      • Prices: AA size with 1 A-h charge capacity ~= $1.
      • Power density: 60 W-h/kg
    • Nickel Metal Hydride (Ni-MH)
      • Pros: high power density, "standard small" sizes, higher capability than Alkaline, rechargeable, nearly negligible memory effect. 
      • Cons: More expensive than NiCad, shorter lifetime, rapid self-discharge.
      • 1.25V per cell.
      • Recommended discharge 0.1C to 0.2C.
      • Good alternative to Alkalines.
      • Prices: AA size with 2.5 A-h charge capacity ~= $2.
      • Power density: 100 W-h/kg
    • Lithium Ion (Li-Ion) and Lithium Polymer (Li-Poly)
      • Pros: Lightweight, high power, high power density, high capability, high cell voltage, rechargeable.
      • Cons: expensive, volatile, delicate.  
      • Common for consumer electronics.
      • Require special circuitry to prevent explosions.
        • Don't use unknown chargers. 
      • Individual cell is 3.6V, often stacked to 7.2V.
      • Ranges from 1C to 10C.
      • Prices: 750mA-h ~= $10.
      • Power density: 126 W-h/kg (LiIon), 185 W-h/kg (LiPoly).
    • Lithium Batteries and Coin Cells
      • Pros: lightweight, high power density, small form factor, inexpensive, high cell voltage, easy to stack in series, long shelf life.
      • Cons: Single use, low capability.
      • Good for small, low-power devices. 
      • Not rechargeable.
      • High internal resistance means they heat up easily due to heat dissipation.
      • Low capability before degradation: ~0.005C. Can provide higher current via PWM.
      • Typically found in 3V (lithium) or 1.5V (alkaline, zinc air, manganese) cells.
      • Prices: CR2032 size with 220mA-h ~= $0.35.
      • Power density: 270 W-h/kg.
  • Number of Batteries
    • Single
      • Pros: lighter, only need to maintain one battery.
      • Cons: May require voltage regulation, need to make sure circuit functions properly with single voltage available. 
    • Multiple
      • Pros: fewer design considerations
      • Cons: difficult to manage which ones are functioning properly, hassle to put in/remove.
    • Approaches regarding single vs. multiple:
      • Multiple: Select the batter(ies) you want to use, then use regulators to obtain all the other values you require.
      • Single: First select the devices you want to use in your circuit, then design electronics around the indicated nominal voltage. 
      • Never make assumptions regarding what voltage something operates at! Always check the datasheet.
        • Analogy (voltage): Voltage behaves similarly to pressure. If you use too high of a pressure on a water tank or balloon, it'll explode. 
        • Ex: if you choose to operate a motor at a lower voltage than rated, the rpm will be diminished (can be modeled proportionally), and the motor efficiency will be reduced.
  • Typical Voltage Ranges of Common Applications
    • Electronics
      • 9V to 12V. 
      • Recently trending towards 3.3V and 5V.
    • Actuators
      • 6V to 12V.
    • Sensors
      • 5V. 
  • Standard Battery Voltages
    • Analogy (voltage): The magnitude of the voltage represents how much water you have available to turn your watermill. The amount of water you pour must be enough to overcome characteristics belonging to the device, for example static friction with the watermill. Alternatively, if you pour too much water at once, then your watermill might break. 
    • 1.2 - one rechargeable NiMH AA or AAA.
      • Hard to do much with 1.2.
    • 1.5 - one Alkaline AA or AAA.
      • Not rechargeable.
      • Hard to do much with 1.5.
    • 2.4 - two rechargeable NiMH AA or AAA.
      • Hard to do much with 2.4.
    • 3 - two Alkaline AA or AAA.
      • Not rechargeable.
      • Hard to do much with 3.
    • 3.6 - three rechargeable NiMH AA or AAA.
      • Able to run microcontrollers.
    • 3.7 - one LiPo. 
      • Able to run microcontrollers.
    • 4.5 - three Alkaline AA or AAA.
      • Not rechargeable.
    • 4.8 - four rechargeable NiMH AA or AAA.
      • Able to operate standard hobby servo motors.
    • 6 - five rechargeable NiMH, or one rechargeable lead acid.
      • This voltage is the maximum for most hobby servos.
    • 7.2 - six rechargeable NiMH AA or AAA. 
      • Good for certain DC gear motors. 
    • 7.4 - two LiPo.
      • Good for powering both microcontroller and DC gear motor.
      • Incompatible with typical hobby servos.
    • 8.4 - seven NiMH AA.
      • AAA uncommon here because of lack of market for manufacturers.
      • Rarely used because this is a lot of batteries to manage at one time.
    • 9 - one NiMH or Alkaline 9V battery, or one lead acid.
      • 9V single rectangular cell - often used to power microcontroller along with sensors. 
      • Lead acid is heavy, but inexpensive and high capacity.
    • 11.1 - three LiPo.
      • Close to 12V, so devices like motors will still work.
      • Much lighter than 10x 1.2V cells or lead acid equivalent. 
    • 12 - one rechargeable lead acid battery pack.
      • Good for DC gear motors and microcontrollers. 
    • > 12 - for larger applications.
    • Notes:
      • Left off Alkaline after a while since you probably don't want to use large quantities of a single use battery.
      • Left off combinations that used a large quantity of batteries, period, since it's hard to manage.
    • Common Examples
      • Servo motors (for example, legged or arm robots) require 4.8V or 6V (NiMH). A voltage regular can be used in conjunction with those battery voltages to power a microcontroller (6V to 9V). 
      • Small robots usually use a 6V, 9V, or 12V NiMH battery pack (depends on the drive motors). Microcontrollers can often provide a 5V digital pin, but you will need to check if the current drawn from this pin is sufficient for your needs. 
      • Medium robots typically use a single 12V battery (lead acid or NiMH), or 11.1V (LiPo if weight is a concern). 
      • Large robots generally use 12V or 24V (lead acid). 
  • Selecting the Appropriate Battery
    • Priority: power hungry.
      • Examples: projectors, large sound systems, motors.
      • Recommended: lantern cells (single use), lead acid (rechargeable).
        • 'Marine deep cycle' for heavy usage or repeated full discharges. 
    • Priority: small size.
      • Lithium coin cell (single use) or small lithium polymer cells (rechargeable).
    • Priority: bulk production.
      • Alkaline because of low prices.
    • Priority: easy to replace.
      • 9V or AA size because they're common.
    • Priority: 5V input. 
      • 3 Alkaline (4.5V) or 4 NiMH (4.8V) for convenience. Check datasheets to make sure small differences are okay.
    • Priority: stacking batteries for uncommon voltages.
      • Only stack if the batteries have matching C and A-h capabilities
        • Analogy (battery stacking): Connect two water pipes of different diameters, and you'll have leaks.
      • Ex: if you stack a 9V and an AA to make 10.5V, the 9V will drain in 1/10th the time it normally does. 
    • Priority: longevity for rechargeable batteries.
      • Better chargers will have sensors to maintain proper charging conditions and handle trickle charging.
        • Trickle charging means to charge a battery at a rate equal to its discharge rate, which allows the battery to maintain full charge capability without overcharging.
        • Addressing trickle charging is especially important for LiIon batteries.
      • Cheap chargers will destroy cells.
---
References

source: https://learn.sparkfun.com/tutorials/how-to-power-a-project/all
Ben summary: Didn't incorporate this as much. Article is more about topics to consider for powering a project, rather than what kind of battery to use.

source: https://learn.adafruit.com/all-about-batteries
Ben summary: This site focuses on characterizing batteries and the differences between the types specified below.

source: http://www.robotshop.com/blog/en/how-do-i-choose-a-battery-8-3585
Ben summary: Useful site explaining pros and cons of different approaches to battery selection. I especially liked the description of all the common voltages associated with batteries. 

source: http://www.intorobotics.com/guide-to-choose-suitable-battery-to-build-a-robot/
Ben summary: Some inaccuracies and disagreements with the author. Read but did not incorporate. 

source: http://electronics.stackexchange.com/questions/9389/what-to-consider-when-choosing-batteries-for-a-project
Ben summary: Additional information on battery chemistry and 'creating a power budget'.

source: https://learn.adafruit.com/li-ion-and-lipoly-batteries
Ben summary: Specific details on Lithium battery technology. Details not included in this document, but good source for further reading. 

Tuesday, 27 May 2014

Intuition: Jacobian

Use of Jacobian: mapping between two state spaces. Each element of the Jacobian matrix describes how much a change in one original state space parameter affects the parameters in the new state space.

Monday, 26 May 2014

Presenting CAD pieces to other people

Helps to turn off shadow and reflection, both found in display options.

CAD: mating cylindrical and rectangular pieces

Use the planar components of the cylindrical (and spherical) pieces to mate to the rectangular components.

Tuesday, 20 May 2014

Fixing pointers to renamed files in Solidworks

Use the 'Replace Component' command.

Source: http://help.solidworks.com/2012/English/SolidWorks/pdmworks/Fixing_Renaming_Errors.htm?id=fa740114198b43d681b773612498713e

Wednesday, 7 May 2014

Safely removing Arduino from Mac


"I’ve probably removed Arduinos from Macs and PCs a thousand times and it never did any harm.
The “remove safely” option is mainly interesting for hard drives etc., because a hard drive should always get the chance to write buffered data to the physical disk before it gets unplugged."

source: https://forums.pragprog.com/forums/129/topics/10216

Friday, 11 April 2014

Restarting Samsung S3 when power button doesn't respond


1. Disconnect the usb/power cord from the device.
2. Remove back cover from the device.
3. Remove battery, and leave the back cover off. You will place the battery back-in in a second.
4. Reconnect the usb/power cord to the device and then to your PC. 
5. Now, while the device is connected, plugin the battery. This is the key step.
At this point, the device shows the battery charging animation, the black/white one on fullscreen, the one that is shown when the device is powered-off and charging. The device had not shown this image in a very long time, while the power button issue was going on, so this looked promising.
6. Now, I pressed the power button, and then the phone started to boot-up.
7. I then went inot downloading mode, flashed it again with the default OS and it was good as new. 

source: http://forums.androidcentral.com/samsung-galaxy-s3/234582-samsung-galaxy-s3-will-not-turn-5.html

Fixing MATLAB compiler error with Simulink function blocks in 2013a

The problem is with compiler updates in xcode 5.1. The 5.0.2 version still works by downloading it from the developer store and renaming the versions to different paths.

source: http://stackoverflow.com/questions/22563533/downgrade-xcode-to-5-0-2

Monday, 10 March 2014

Sunday, 23 February 2014

How to fix MATLAB and mex version incompatibilities

1. In the MATLAB Command Window, execute the following commands:
cd(matlabroot)
cd bin
edit mexopts.sh
2. Save a backup copy of this file somewhere in case you make a mistake and you need to revert your changes.
3. Scroll down to the Mac (“maci64”) section of this file, beginning around line 120.
4. Replace all instances of 10.7 with 10.8; there are four of these in all (a fifth may be found in comments only)
5. Save the file, then execute the following command in the MATLAB Command Window:
mex -setup


Source: http://www.mathworks.com/matlabcentral/answers/103904-can-i-use-xcode-5-as-my-c-or-c-compiler-in-matlab-8-1-r2013a-or-matlab-8-2-r2013b

Tuesday, 18 February 2014

Acquiring data via FFMPEG

Only one connection can exist at a time when reading video data from FFMPEG, otherwise the program will freeze while attempting to pick up the data. Once one connection has been established, you can use:

ffmpeg -i tcp://[ip:port] [outputfile]

In addition, there seem to be some errors with the Jan 14 2014 version of FFMPEG where the recorded data is either sampled or slowed. I updated to the Jan 16 2014 and no longer had this issue.

Monday, 17 February 2014

Installing ffplay on OSX

Download the most recent static FFplay binaries for Mac OS X Intel 64bit at http://www.evermeet.cx/ffplay/. (If this gets disabled, leave a message and I can mirror my copy from this date.)

Use something that can unzip 7z files, like The Unarchiver for Mac (h/t: Ren). Move the ffplay binary into /usr/bin/ or some other folder on your $PATH.

Now it should be accessible from terminal!

Decibel

'Decibel' can also be used to denote when some value is 1/10 of some other value.

Checking FFMPEG version

ffmpeg -version

Checking file paths on OSX

$PATH to check what is included in your path.

Monday, 20 January 2014

What is Node.js?

Node.js is a server-side javascript interpreter that is useful for receiving and responding to http requests. Node itself isn't javascript, but the code that it handles is javascript. Node is actually a c program, and uses javascript as a way to send instructions to the c program and drastically simplify the server networking code required in c.

source: http://radar.oreilly.com/2011/07/what-is-node.html

Sunday, 19 January 2014

Python: input() vs raw_input()

raw_input() reads everything as a string and you have to process it yourself.

input() functions as eval(raw_input()) which can lead to vulnerabilities in injection code.

Blocking websites on Android phones

Goal: Want to stop lying in bed reading facebook and 9gag so that I will get out of bed sooner in the morning.

Solution: I used an app called safebrowser which allows you to black/whitelist specific websites. I also hid the default internet browser so that I wouldn't be tempted to bypass the safe browser.
https://play.google.com/store/apps/details?id=com.cloudacl