Mobile and Vehicular Network Lab
2016 WNFA LAB1
Chung-Lin Chan 2016.3.11
VLC:CamCom
Mobile and Vehicular Network Lab
Outline
• Intro
• Implementation
– Transmitter – Receiver
• Grading Criteria
Mobile and Vehicular Network Lab
Intro
Mobile and Vehicular Network Lab
Intro
The term VLC is from…
Visible Light Communication
• A kind of wireless network using visible light to transmit
• Apply field: vehicle network, Indoor positioning
: I’m
here!
Mobile and Vehicular Network Lab
Intro
The term CamCom is from…
Camera Communication
• Using a camera sensor for VLC
• In Lab1, we ask you to implement a VLC system applying LED as Transmitter, and Mobile phone’s camera as Receiver
×
Mobile and Vehicular Network Lab
Implementation
-Transmitter
Mobile and Vehicular Network Lab
• Tx: Zigduino board + LED Light
Implementation-Tx
Equipment List:
Zigduino x 1
3-color LED x 2 250Ω resistor x 6 麵包板 x 1
電線 x n
Mobile and Vehicular Network Lab
• 實驗器材圖
Implementation-Tx
Zigduino installation guide:
https://www.csie.ntu.edu.tw/~hsinmu/courses/_media/wn_16spring/
2016_zigduino_arduino_installationguide.pdf
Use Arduino to
program your
zigduino board!
Mobile and Vehicular Network Lab
Our First Zigduino Program (Blink.ino)
// Pin 13 has an LED connected on most Arduino boards.
int led = 13;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second
}
Implementation-Tx
Mobile and Vehicular Network Lab
• VLC Inspiration
– Computers know but we don’t!!
Implementation-Tx
Mobile and Vehicular Network Lab
• Global Shutter(G) & Rolling Shutter(R)
• G: Whole frame shot simultaneously
• R: Every row shot in different times (CMOS)
Implementation-Tx
Get stripes when flicker LED meet
rolling shutter camera
Mobile and Vehicular Network Lab
• Still a little confused to Rolling shutter?
• Here’re some examples
Implementation-Tx
Mobile and Vehicular Network Lab
• You can use anything to represent bits:
– color, frequency, luminance, waveform, duplication, ...
– Don’t forget the low sampling rate of camera (30fps)
• Get extra score if people cannot notice the behavior of LEDs
• Range your score with data rate
Implementation-Tx
message => bytes => behavior of LEDs
Read from monitor Zigduino
Mobile and Vehicular Network Lab
Implementation-Tx
CTC Mode
• Clear Timer on Compare (timer == OCRnA)
• Generate
accuratesquare waves
– all done by hardware, won’t affected by interrupt
– Can simultaneously use all 3 timers easily.
• Set the corresponding bits in TCCRnX(n=1,2,3 X=A,B) registers for
mode selection and timer prescaler
• Set OCRnX for“frequency”(OCRnA)or“delay”(OCRnB,OCRnC)
• Frequency = 16M / prescaler / OCRnA / 2
• Additional support : interrupt handler (see document)
Mobile and Vehicular Network Lab
void setup() {
// use Timer1, set control registers here pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
TCCR1A = _BV(COM1A0) | _BV(COM1B0) | _BV(COM1C0);
TCCR1B = _BV(WGM12) | _BV(CS12) | _BV(CS10);
OCR1A = 32767;
OCR1B = 16383;
OCR1C = 8191;
} void loop(){
// change OCRnX values to manipulate frequency OCR1A = 32767, OCR1B = 16383, OCR1C = 8191;
delay(10000); // this may not be so accurate
OCR1A = 16383,OCR1B = 8191,OCR1C = 4095;
delay(10000);
}
Implementation-Tx
Timer n 101 => 5 =>
prescaler 1024
Mobile and Vehicular Network Lab
Implementation-Tx
Some register definition
Mobile and Vehicular Network Lab
Implementation-Tx
Timer name Size of registers Control value
(fill TCCRnX) Prescaler Output pin name <-> pin in Zigduino Timer1 16-bit WGM = 4
COM1A/B/C = 1 CS = 1/2/3/4/5
1 / 8 / 64/
256 / 1024
OC1A <-> pin11 OC1B <-> pin10 OC1C <-> pin9
(pin11 need a jumper) Timer3 16-bit WGM = 4
COM3A/B/C = 1 CS = 1/2/3/4/5
1 / 8 / 64/
256 / 1024
OC3A <-> pin5 OC3B <-> pin6 OC3C <-> pin3 Timer2 8-bit WGM = 2
COM2A = 1 CS = 1~7
1/8/32/64 /128/256/
1024 OC2A <-> pin8
CTC Mode
For more details
• http://www.atmel.com/Images/doc8266.pdf (register definition)
• https://static.squarespace.com/static/511f4f0de4b09463c7605f13/t/
5275c478e4b07e72f74c7442/1383449720133/zigduino-‐v6c-‐schematic.pdf
Mobile and Vehicular Network Lab
• CSnX
– n:timer n
– X:所需的值轉成2進制,所對應的第X位為1
• 1/8/64/256/1024
→1/2/3/4/5→0001/0010/0011/0100/0101
• Ex. timer 3 →n=3→CS3X
prescaler=1024→5→0101→第2位和第0位為1 →_BV(CS32) | _BV(CS30)
Implementation-Tx
Mobile and Vehicular Network Lab
• PWM Mode(with OCRnA top)
– Pulse-width modulation
– Can be used to control duty cycle – http://arduino.cc/en/Tutorial/
SecretsOfArduinoPWM( pins are different )
– Differences in luminance and ratio of light/dark stripe width
Implementation-Tx
Mobile and Vehicular Network Lab
Implementation-Tx
pinMode(6, OUTPUT);
TCCR3A = _BV(COM3B1) | _BV(WGM31) | _BV(WGM30);
TCCR3B = _BV(WGM32) | _BV(WGM33) | _BV(CS32) | _BV(CS30);
OCR3A = 8191;
OCR3B = 2047; // 25% duty cycle
• PWM Mode(with OCRnA top)
– OCRnA define frequency
– OCRnB define duty cycle
Mobile and Vehicular Network Lab
Implementation-Tx
• Serial Monitor – text I/O
– Input your message here!
Mobile and Vehicular Network Lab
Implementation
-Receiver
Mobile and Vehicular Network Lab
Implementation-Rx
Notice:每支手機的相機不一定都是30fps
• Rx Devices: Mobile phone’s camera
Mobile and Vehicular Network Lab
• Rx Pseudo code
• for all images
{
read image;
find bounding box // where are the stripes calculate row power
count stripes to get freq. // through DIP or FFT get output bit by freq.
}
Implementation-Rx
Mobile and Vehicular Network Lab
• Video to image:
– ffmpeg –i input.avi ouput%d.jpg
(supported by windows, linux, and OS X)
• Counting Stripes : need some DIP
– find LED position, image diff, color histogram, edge detection, Fourier transform, auto-correlation, ……
• 3 decode basic ways : DIP, FFT, auto-correlation
Implementation-Rx
Video ( -> image ) -> get behavior of LEDs
-> bytes -> message
Mobile and Vehicular Network Lab
Grading Criteria
Mobile and Vehicular Network Lab
• Grade
– Tx : Transmit Message
• 20% Workable
• 10% No awareness
• 10% Data rate (Compete ranking as 0~10 credits)
– Rx : Video/Image Decode
• 20% Workable
• 10% Message Accuracy
– Report : describe what team members have done(in detail), and problems encountered ( also, how you solved it ? ) (20%)
– Bonus: real time... (5%)
Grading Criteria
Mobile and Vehicular Network Lab
• Deadline: 4/6(Wed.) 23:59 email to wn@csie.ntu.edu.tw – Email subject:[WN]lab1_teamXX
– [WN]lab1_teamXX.zip
• source code(tx + rx)
• Report(.pdf)
• Demo-4/6(Wed.)
– Please register the demo slot. And come to CSIE R424 at that time. (TBA)
– All you should do are :
• 1. Transmit the character string given by TA
• 2. Record the videos
• 3. Decode and get the message
Grading Criteria
Mobile and Vehicular Network Lab
特別評分機制
• 90% Lab 團體成績 ( 由各個作業負責的助教決
定 )
• 10% 小組互評成績
– 匿名
– 給分範圍為 -2.5 ~ 2.5
– 給分總和需等於 0 (ex 0.25/0.25/-0.25/-0.25)
• 目的
– Report 上的工作分配有時無法準確的表達各個組員 各自的想法,因此添加此機制作參考
Mobile and Vehicular Network Lab
• Contact to TAs :
– facebook https://www.facebook.com/groups/
wn15spring/
– Email : wn@csie.ntu.edu.tw
– Office hour : Tue. 13:20~14:10/TBA
@ CSIE R424
Mobile and Vehicular Network Lab