Mobile and Vehicular Network Lab
[2015-Fall] WNFA lab1 - CamCom
Camera Communication Hsin-I,Wu
2015/3/13
Mobile and Vehicular Network Lab
INTRODUCTION
Mobile and Vehicular Network Lab
VLC
• Visible Light Communication
Mobile and Vehicular Network Lab
Hw1 intro
Mobile and Vehicular Network Lab
TRANSMITTER
Mobile and Vehicular Network Lab
Tx-hardware
• Zigduino x2 →
http://goo.gl/TjM2uQ• LEDs x2
• Resistors 250Ω x6
• 麵包版 + 線 x1
Mobile and Vehicular Network Lab
Tx-hardware
Notice : there must be resistors ( 電阻 ) in the circuit
Mobile and Vehicular Network Lab
Tx
• message → bytes → behavior of LEDs
• You can use anything to represent bits:
– color, frequency, luminance, waveform, dup lication, ……
– Don’t forget the low sampling rate of cam era (30fps)
• Get extra score if people cannot notice the behavior of LEDs
• Range your score with data rate
Mobile and Vehicular Network Lab
Tx-Zigduino
• Delay()
int ledPin = 13; // LED connected to digital pin 13 void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output }
void loop() {
digitalWrite(ledPin, HIGH); // sets the LED on delay(1000); // waits for a second digitalWrite(ledPin, LOW); // sets the LED of delay(1000); // waits for a second }
Mobile and Vehicular Network Lab
Tx-Zigduino
• CTC mode
– Clear Timer on Compare (timer == OCRnA) – Generate accurate square waves
• all done by hardware, won’t affected by inte rrupt
• Can simultaneously use all 3 timers easily.
Mobile and Vehicular Network Lab
Tx-Zigduino
• CTC mode
– Set the corresponding bits in TCCRnX(n=1,2,3 X=A,B) re gisters 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
Tx-Zigduino
• CTC mode
void setup() {
// use Timer1, set control registers here pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(3, OUTPUT);
TCCR3A = _BV(COM3A0) | _BV(COM3B0) | _BV(COM3C0);
TCCR3B = _BV(WGM32) | _BV(CS32) | _BV(CS30);
OCR3A = 32767;
OCR3B = 16383;
OCR3C = 8191;
}
void loop(){
// change OCRnX values to manipulate frequency OCR3A = 32767, OCR3B = 16383, OCR3C = 8191;
delay(10000); // this may not be so accurate OCR3A = 16383,OCR3B = 8191,OCR3C = 4095;
delay(10000);
}
Mobile and Vehicular Network Lab
Tx-Zigduino
Mobile and Vehicular Network Lab
Tx-Zigduino
• 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)
Mobile and Vehicular Network Lab
Tx-Zigduino
• CTC mode
– For more details
– https://strawberry-linux.com/pub/doc8266.
pdf – https
://static.squarespace.com/static/511f4f0d
e4b09463c7605f13/t/5275c478e4b07e72f74c74
42/1383449720133/zigduino-v6c-schematic.p
df
Mobile and Vehicular Network Lab
Tx-frequency
stripes to get freq.
Mobile and Vehicular Network Lab
Rolling Shutter
• Global Shutter VS. Rolling Shutter
– A GLOBAL SHUTTER exposes the entire image
r simultaneously.
Mobile and Vehicular Network Lab
Rolling Shutter
• Global Shutter VS. Rolling Shutter
– The rolling shutter actually exposes diff
erent portions of the frame at different
points in time, “rolling” through the f
rame.
Mobile and Vehicular Network Lab
Rolling Shutter
Mobile and Vehicular Network Lab
Tx-luminance
• Fast PWM (with OCRnA top)
– Pulse-width modulation
– Can be used to control duty cycle
– http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM( pins are dif ferent )
– Differences in luminance and ratio of light/dark stripe width
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
Mobile and Vehicular Network Lab
Tx-color
• RGB
• HSV
Mobile and Vehicular Network Lab
RECEIVER
Mobile and Vehicular Network Lab
Rx-hardware
• Camera of your smart phone
Notice: 每支手機的相機 fps 不一定都是 30
Mobile and Vehicular Network Lab
Rx
• video ( → image ) → get LEDs behavior→
bytes → message
• 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-corr elation, ……
• 3 basic ways : DIP, FFT, auto-correlation
Mobile and Vehicular Network Lab
Rx-an example 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 FF T
get output bit by freq.
}
Mobile and Vehicular Network Lab
GRADE
Mobile and Vehicular Network Lab
Grade
• Deadline:4/2(Thur.) 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/9(Thur.)
– Please register the demo slot. And come to CSIE R424 at that time.
http://goo.gl/YyM8QF – All you should do are :
• 1. Transmit the character string given by TA
• 2. Record the videos
• 3. Decode and get the message
• Grade
– Tx (20% + 10% for not noticed by human eyes + 10% data rate) – Rx : Video Decode (20% + 10% for accuracy)
– Report : describe what team members have done(in detail), and probl ems encountered (20%)
– Bonus: real time... (5%)
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
• 情境 1 : 大家都認為彼此付出一樣心力
– 大家彼此都給 0 分,此組員成績 = Lab 團
體成績• 情境 2 : 1 個 Free Rider
– 大家都給 -2.5 ,共得 -10 ,此人成績 = Lab 團體成績 – 10
– 大家都給救火者 2.5 ,共得 10 ,此人成績 =
Lab 團體成績 + 10
Mobile and Vehicular Network Lab
• 假設 A 組全組認真參與; B 組存在 Free Rider(s)
• A 組在此機制下最高得分只有 90 % ,然而 B 組最高 分數卻較高 90% + 10% ,是否不公平?
– A 組最高分確實只有 90 % ,然而學期末總成績將依據常態分 佈給分,所以總分高低不是重點
– 課程安排上作業傾向需要五人團隊合作,理論上 B 組的 Lab 表現會較 A 組差,因而得到較低的 Lab 團體成績,即使加 上互評成績不見得會拿到較 A 組高的分數
– 假若 B 組救火者有能力將 Lab 表現得與 A 組相當甚至更
佳,那麼最後因為最高分數較高而得到較 A 組佳的成績是實
至名歸
Mobile and Vehicular Network Lab
• Contact to TAs :
– facebook https://www.facebook.com/groups/
wn15spring/
– Email : wn@csie.ntu.edu.tw
– Office hour : Thur. 16:00~17:00@ CSIE R42
4
Mobile and Vehicular Network Lab
APPENDIX
Mobile and Vehicular Network Lab
Zigduino
• First program – Blink.ino
Mobile and Vehicular Network Lab
Zigduino
COMx Zigduino
Mobile and Vehicular Network Lab
Zigduino
• serial port monitor – text I/O
– see Examples 08. Strings
– Use the serial monitor to communicate
Mobile and Vehicular Network Lab
ffmpeg
Ffmpeg.exe
video
Mobile and Vehicular Network Lab