Wednesday 17 June 2015

Stand-alone Surveillance Control Robot



The post demonstrates the second generation version of the previous post. The second generation robot communicates directly to the smartphone without the help of the router by making the smartphone, a WiFi access point. I have installed sensors to monitor the environmental parameters like temperature, pressure, Light intensity. The Raspberry Pi, the  PIC micro-controller and the sensors form hierarchical I2C bus architecture. To avoid the real time delay for the navigation of the robot, the driving control for the motors has been moved to Pi. The sensor data is available to the user in the smartphone.The block diagram depicts the system assembly.





Hierarchical I2C Bus Architecture:
Hardware Implementation:
Raspberry PI is a 3.3V system and requires a level shifter to communicate to PIC Microcontroller which is a 5V device. I could find a level shifter circuit as shown below in http://playground.arduino.cc/Main/I2CBi-directionalLevelShifter which helped me to build my own level shifter with transistors.




I2C is a communication protocol which allows data transfer among devices with help of two wire namely SCL and SDA which sends and receives data serially. PIC 18F25K22 has two independent I2C Bus network in which the one of the Buses is used for communication between RPI (master) and PIC (slave). The other I2C bus forms a communication path between PIC (master) and the I2C sensors (slave). Each device has its own address in I2C bus architecture through which the master and the slave devices communicate each other. With reference to my application, RPI acts as hierarchical master device which communicates to the sensors and servo motors indirectly through the sub-master PIC. PIC micro-controller communicates to the sensor and reads the sensor values continuously and when RPI gives commands to PIC to pass the sensor readings or to control the Tilt/Pan system, PIC stops its usual routine work and services the interrupt from RPI and resumes its work after the service.


System software design:
Libraries used in RPI for navigation and video streaming:
WEBIOPI              - WebIOPi is a REST framework which allows you to control Raspberry Pi’s GPIO from a browser. It’s written in JavaScript for the client and in Python for the server. You can fully customize and easily build your own web app. You can even use all the power of WebIOPi directly in your own Python script and register your functions so you can call them from the web app. WebIOPi also includes some other features like software PWM for all GPIO. In our application, the android smartphone communication with Pi through this library using Http Client services.

GSTREAMER       - GStreamer is a pipeline based multimedia framework which allows a programmer to create a variety of media-handling components, including simple audio playback, audio and video playback, recording, streaming and editing. The pipeline design serves as a base to create many types of multimedia applications such as video editors, streaming media broadcasters and media players. We use this library to decode the video information from the USB Webcam.


Basic algorithm:
  • Setting up the RPI as a wireless accessible device using a wireless USB adapter.
  • An android application is developed to command the robot and to get the video stream from the robot. The application communicates to the RPI through HTTP protocol for the navigation control and for receiving the sensor data using the IP address of the RPI.
  • Getting the data from the sensor to PIC through I2C bus communication and also interfacing servo based Tilt/Pan system where the camera is mounted.
  • Now the PIC is interfaced with the hierarchical master RPI to send the sensor’s values to the RPI as RPI requests for the data and to receive commands to control the Tilt/Pan system.
  • As the RPI get the values from PIC Microcontroller, it store in the memory which gets updated to the android application after 500milliseconds.
  • Interfacing DC motor with RPI through a L928 driver which is controlled as the commands are received from the android application. 



The below picture demonstrates how the light sensor data (Lux) changes according to the light intensity that falls on the sensor. In the first picture, the robot is roaming in the dark region, so that the light intensity is measured less. As the moves to the brighter region, the light intensity value increases in the second picture. 




Wi-Fi Controlled Surveillance Robot using Raspberry Pi


Surveillance robot have become popular in the recent years and making our own indoor based surveillance robot is a cool stuff, isn’t it? This post demonstrates my first surveillance robot project. It is a android smartphone controlled robot on which I have used Raspberry Pi to set up Linux based wireless interfacing system and PIC micro-controller to drive the robot. It is a 4WD system in which the motors (12V DC Motor) takes the control from the micro-controller through our most familiar motor driver L293D which delivers sufficient power for low torque DC motors. The video streaming and the mobility control is done with the help of the Android smartphone application. The basic block diagram of the overall system is given below
The IP address of the Raspberry Pi hub and its ports along with the resolution of the video are defined while starting the android application.



The bottom left window of the application is used to navigate the robot with the help of video stream and the bottom right window is used to move the camera using Pan/Tilt system to have better viewing experience.






Sunday 28 December 2014

High Current DC Motor Driver Schematic Circuit and PCB

In the world of robotics, the mobile robots have got its own place in the hearts and minds of robotic developers and designers. Idea of the project is to develop a general purpose robotic mobile platform that can carry reasonable load (20Kg) in the outdoor environment.

One of the important components of the mobile robot platform is the suitable DC motor and drivers to control these motors. I  tried few motors normal DC motors and so called High torque motors. BTW, I have made a small indoor navigation robot using these motors and drivers that I will try to post later. I decided to re-purpose the two-wheeler starter motor. For the trial, I bought an old scooter starter motor, in the Bangalore, INDIA old scrap market for about INR 500. It consumes about 8A under no load condition. For the drivers, I tried few L298 based drivers but it did not meet my current (8A) requirement. Being a student, my funds are limited and I don’t learn anything when I buy an off-the-shelf driver. So I decided to make my own motor driver. This post explains the details of the design.

Driver Design

Motor drivers are used to deliver the required amount of power to the motors while at the same time enable the intelligent controllers like microcontrollers to control them. My plan is to design a motor controller that can deliver about 20A continuous current with locally available components. I purchased these P-channel FET (IRF4905) and n-channel (75NF75) FETs. These can deliver a reasonably high current (74A and 75A respectively) and low on resistance (20mΩ and 13mΩ respectively).  Direction control is achieved through 5V Logic direction control signals and speed control is achieved through PWM (Pulse width modulation) duty cycle control. Driver is a traditional H-bridge controller with P-FETs as high side controller and N-FETs as low side controllers. In addition, P-FETs and N-FETs are used for direction control while only N-FETs are used for speed control. The FETs chosen can operate up to 50V so the driver can operate at least at 12V and 24V. Discrete transistors (BJT) are used to implement the required logic (Detailed explanation below) and to drive P-channel FETs Gate terminals to 12V.  In addition, the driver has back EMF measurement for direction switching and driver current sensing feature when there is a need.

Control Logic

The driver has logic to control both direction and speed of rotation. Direction is controlled by the enable signals to the gate inputs of all the FETs of the H-bride. Speed is controlled by the PWM of the Gate input of the low side FET (N-channel). Further direction can be controlled either by a single input direction control signal or four independent input direction controls. Four independent input direction control has the advantages of support for braking the motor electronically. Single input or four independent input control can be selected through berg-stick jumpers (N1_JUMP, N2_JUMP AND P2_JUMP).  The complete driver circuit (including transistor control) works-off of 12V supply to avoid any requirement for 5V regulator. P-Channel and N-Channel FET’s gate terminals are logically complement to each other. In other words, P channel FET is turned ON when the gate terminal is low while the N channel FET is turned ON when the gate terminal is high.  Left and right side P channel FET gate control circuitry is complementary to each other so is N channel FET control circuitry. Schematic of the control circuitry is given below. The left P-FET (PL), the left N-FET (NL), the right P- FET (PR) and the right N-FET (NR) have transistor driven control inputs P1, N1, P2 AND N2 respectively.
High Current DC motor Control Schematic
High Current DC motor Control Schematic


Single Input Direction Control (JUMP_MODE-1)

PWM
DIR/P1
N1
N2
P2
M+
M-
DIRECTION
ON
HIGH
X
X
X
12V
GND
FORWARD
ON
LOW
X
X
X
GND
12V
REVERSE
OFF
HIGH
X
X
X
12V
-
STOP
OFF
LOW
X
X
X
-
12V
STOP

When the PWM is ON and based on the direction control (DIR/P1), the motor either runs in forward or reverse direction. When the PWM is OFF, the motor doesn’t run because it gets only the positive potential (12V) in either of the terminals depending on DIR but does not have the return path to the ground.

Independent Input Direction Control (JUMP_MODE-2)


PWM
DIR/P1
N1
N2
P2
M+
M-
DIRECTION
ON
HIGH
HIGH
HIGH
HIGH
12V
GND
FORWARD
ON
LOW
LOW
LOW
LOW
GND
12V
REVERSE
ON
HIGH
HIGH
LOW
LOW
12V
12V
ELECTRONIC BRAKE
ON
LOW
LOW
HIGH
HIGH
GND
GND
ELECTRONIC BRAKE
OFF
HIGH
X
X
HIGH
12V
-
STOP
OFF
LOW
X
X
LOW
-
12V
STOP
OFF
HIGH
X
X
LOW
12V
12V
ELECTRONIC BRAKE
OFF
LOW
X
X
HIGH
-
-
COAST














When the PWM is ON and all the independent inputs are HIGH, the motor runs in forward direction. When the PWM is ON and all the independent inputs are LOW, the motor runs in reverse direction. If the left side FET control inputs (P1 and N1) are HIGH and the right side FET control inputs (P2 and N2) are LOW, then both the motor terminals gets 12V. If the left side FET control inputs (P1 and N1) are LOW and the right side FET control inputs (P2 and N2) are HIGH, then both the motor terminals are connected to the ground. When the PWM is OFF, N-Channel FETs are always turned OFF, only P-Channel FETs undergoes switching based on the corresponding control inputs. In COAST mode, both the terminals of the motor becomes floating.

Back EMF measurement

Back electromotive force (EMF) is a voltage that appears in the opposite direction to current flow as a result of the motor’s coils moving relative to a magnetic field (when the motor acts as generator). The back EMF is an indication of the speed of the motor, so knowing the value of back EMF gives us an idea about the speed of the motor. The voltage divider networks on both the terminals of the motor gives their potentials and their difference gives us the actual back EMF. If there is a requirement, back EMF value can be used for direction switching.  The back EMF is available as two different voltages at the berg-stick connectors (BE1 and BE2).
Back EMF measurement
Back EMF measurement


Driver current measurement

Some times there is a need a for motor driver current measurement. The driver has a current sensing circuit that senses the current through the motor to the ground. The current is sensed through the current sensing resistor network. A set of eight 10mohm (1/4 watt) resistors are used to reduce the power dissipation through individual resistors and also provide enough conduction path for the current flow. The voltage drop is filtered and amplified using a non-inverting amplifier (re-used the circuit from here) and is available at the berg-stick connector (CURRENT SENSE). Considering the voltage drop at the resistors for maximum rated current of 20A, amplification factor (gain) is 180 so the maximum voltage will be 4.5V.

Current Sensing Circuit
Current Sensing Circuit

Note: Back EMF measurement and Driver current measurement circuit is re-used from here

Layout consideration

One of the important thing to consider in the PCB layout is managing the PCB trace width to handle the required current. To address this, the PCB trace width from supply to FET drain/source, through the motor terminal and then to the ground is made as wide as possible (10 mm approximately).  In addition, these traces are routed on both sides of the board and manufactured using 70um (2oz) thicker tracks. Assuming 35A/mm2, this should be able to carry much more than 20A current with bottle neck being the FET source and drain terminal connection to the board.
High Current DC Motor Driver PCB Layout
High Current DC Motor Driver Layout




Current Status

I tested this circuit on a bread board and a general purpose PCB (for FET wiring) and the circuit seems to be working and deliver consistently about 8A. The P-channel FET surface temperature was about 28 Deg C  without any heat-sink.I have got my PCB board after it took a long time to manufacture. In course of time, I will update you with the working PCB Driver Model. Here is my PCB!
High Current DC Motor Driver PCB_Front-side

High current DC Motor Driver PCB_Back-side


I have Assembled my PCB and updated with circuit connections of the driver with the DC Motor.
PCB Board Connections

Here we go for the first trail tested with scooter self start motor. The speed of the motor is controlled from the PWM signal from the Micro-controller.








Comments and feedback are welcome.






Keywords: h-bridge, dc motor driver, motor driver, high current driver, motor control, robot, robotics, back emf, current sense, driver, fet, mosfet,dc motor control, dc motor controller, dc motor drive, h bridge motor driver, dc motor drives, motor driver, motor driver ic, motor driver circuit, dc drive, h bridge circuit, motor control.