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.