Distance Measurement Vehicle via Websocket
When you measure distance between two point general way is to use a ruler. But you can use a lot of other ways: by laser, map, foot or walking meter.
The walking meter is very useful when you are measuring curved (not straight) distance. But it might be very tired because you should walk the entire distance.
Here is a movie which is measuring distance. You can see that the vehicle is being controlled by the web browser and distance is displayed in the web page in real-time.
This project is about a distance measuring vehicle. It is remotely controlled through the WiFi network via Websocket and user can get the distance data from the vehicle in real-time via the Websocket.
Now, I am going to explain how I have implemented the system.
1. Assembling a vehicle
At first, I have assembled a vehicle from the DFRobot.
The vehicle kit was great because I could get everything from this kit. But when I assembled two encoders some parts were not fit so it was tough to fix.
2. Modifying a web page
I have implemented a web page by using a source code from hackster.io. It is a cool implementation of a joystick via Websocket.
I have added a function to display distance data from the vehicle.
And I have modified that it transmits control data to the vehicle only when joystick position is changed over predefined offset because there were a lot of data transmission with original web page.
3. Programming Arduino Uno
I have programmed one source code for the Arduino Uno and PHPoC Wifi Shield.
The PHPoC Wifi Shield supports Websocket so user can implement a real-time web-based system with Arduino Uno.
Data from the web browser through PHPoC Shield’s Websocket are text number from 0 to 100. But the PWM data for the DC motor driver are from 0 to 255. So there is a conversion routine after reading the data from the Websocket.
And distance is transmitted every 10cm through the Websocket. Distance is determined by counting the encoder on the wheel and calculating it based on the wheel’s diameter.
So I needed to count the encoder. But calculated distance is so large than I expected. I found that there are a lot of noise when I reading the encoder state from pin 2. So I programmed software filter. The algorithm is followed:
- Check the input port (digital port 2) ever 100us in ISR (Interrupt Service Routine) from the TimerOne library.
- If the read state is same to former state it increase a number and it decrease it when the state is not same.
- When the count is over to the predefined threshold it counts one.
For more detail: Distance Measurement Vehicle via Websocket
JLCPCB – Prototype 10 PCBs for $2 + 2 days Lead Time
China’s Largest PCB Prototype Enterprise, 300,000+ Customers & 10,000+ Online Orders Per Day
Inside a huge PCB factory: https://www.youtube.com/watch?v=_XCznQFV-Mw