profmason.com

June 4, 2010

Motor Driver Board

Filed under: Daily — profmason @ 12:51 pm

Objective:

The goal is to design a motor shield for the purpose of teaching motor control in a modern embedded computing environment.   The popular arduino platform has substantial support and straight forward development tools that allow students to concentrate on developing control algorithms instead of learning software tools.  This also allows students to leverage and improve their c programming while providing a gentel introduction to embedded systems.    While there are a number of motor shields available for the arduino, none of them surveyed allow for closed loop control where current sensing is integrated into the motor driver.  In addition, most of the boards are suitable for lower currents which eliminates their utility for controlling existing equipment.  This project will create  an arduino motor shield for the standard Duemilanove board which can control up the three motors (1 high current (30 Amps) and 2 lower current (2.5 Amp) all with integrated current sensing for closed loop control. In addition, the board will have interfaces for quadrature encoders with analog pre-processing to simplify their implementation.

Details:

The planned board will focus on closed loop control.  An external board (arduino) will drive one high current motor (16V 30amps based on STMICROELECTRONICS  VNH2SP30-E) and two lower current drivers (28 V 2.5Amp continuous 5 Amp peak drivers based on the FREESCALE SEMICONDUCTOR MC33887VW).  Both the controllers will have current sensors routed back the the ADC on the micro for the closed loop control.  In addition there will be three interfaces for quadrature encoders based on a 74XX74 flip flop.

First the schematic for one of the low  current drivers.  (Thanks to pololu and datasheet)

Will need to build this twice sharing the power caps, reverse protection mosfet and power input.

Here is the schematic for the high current driver (Again thanks to datasheet and pololu)

Student Task Sequence:

  1. Understand the Arduino environment.  Install the current arduino environment and work through the basic tutorials on Lady Ada’s site.   Get familiar with checking out equipment from Smeaton 303.    You may be able to do this quickly, but take the time to understand them to save yourself grief later!
  2. Attach the ArduMotor board and interface it with the arduino.  Use the sample sketch on the linked page.  Chat with Dr. Lopes about some suitable motors in the lab to control.
  3. Define some simple objectives that you want to achieve with your test code with the arduoMoto board.  This could be writing routinues to have the motor run for a specified time, forward backwards etc.  If you are waiting for the protoboards to arrive (see next)  rig up some encoders for the motor.  (Either optical or hall effect.)  Interface these to the ardumotor board.  Write some code for the ardumotor board to do position control of the motors based on the encoders.
  4. Check and see if the 33887 and 2SP30 protoboards have arrived.  Assemble these.  (IE solder on headers and connectors.)   Read all the available information on these boards.
  5. Write some arduino code to control the two motor driver boards.  Port what you have done for the ardumotor board to support each of these boards.
  6. Use the current sense outputs from each of the boards.  First connect these to the ADC.  Will you need an amplifier for the current sense output?
  7. Once you understand the proto boards, lay out schematics to include all the parts on one shield.  Meet with Shelia and the staff in SM303 to learn about this process at the Uni.  Do some research to find a default cad model for an arduino shield.  Think about all the things that need to go on the board.  Use all surface mount components.  Try to make the board with one controller(VN) and the other on the opposite(MC)  Minimize the number of vias between the two sides of the board!!!!!!!!  We can’t do plated thru holes.
  8. Order components.  The motor driver chips and mosfets are already ordered.  You will need to sort out all the small components with Shelia. Generate a BOM etc.
  9. Have the board made.  Work with Shelia Storm and Bob to coordinate this.
  10. Populate the board.
  11. Test the board.
  12. While you are waiting for the board to be made start thinking about control code using the current sense data and/or the encoder data.  Read about PID control.   Implement a P, PD, and PID controller on the board.    If you are stuck waiting on hardware, work in matlab and create a model of the transfer function of the system.  Dr. Lopes will advise you during this portion.
  13. Once your board is tested and bugs are worked out, design a final product that takes into account good design criteria relative to an end user perspective.  Convert the design to double sided and 2 or 4 layer using a much finer pitch.  Think carefully about optimal connectors and connector placement.  Get a set of quotes from local (Dr. Culverhouse is the inhouse expert on this.) and international vendors (olimex in romania and golden phoenix in china) to produce a set of 10 of the final board.
  14. Write your report!

June 3, 2010

Updated Competition Robot Code:

Filed under: Daily — profmason @ 3:16 pm

The Bioloid Gait Software has been ported to the new CM-700.  The software has been tested with AX-12+, RX28, RX24, RX64 and DX117 servos and can run them all interchangeably.   Note, no accommodations have been made for the different servo speeds so the servo group speeds will need to be recalculated.  In addition the software has been massively cleaned and streamlined.  All compiler warnings in main.c have been eliminated and substantial commenting has been introduced.  For detailed information see my report on the bioloid real time control software.

How to get started with the CM700:

  1. Unzip the zip file (2June2010ProjectFiles)
  2. Open AVR-Studio.
  3. Open the Project file  (bioloid.aps)
  4. You may modify main.c to implement changes.
  5. Choose Build->Build and wait about 30 seconds
  6. On conclusion it should report “Build Succeeded”
  7. In your project directory you now have a file called “bioloid.hex”
  8. Open Robot Terminal
  9. Hold the # key.
  10. Power cycle the CM700
  11. The prompt “SYSTEM-O.K. CM700 BOOTLOADER 1.51) should appear
  12. Type LD
  13. Select Files->Transmit File and select your bioloid.hex file
  14. It will report “Transmitting Data” and should conclude after about 30 seconds with “Success”

Here is the main loop.  (Now should be readable!)

  1. //——————————————————————————
  2. // Main Function called each time Micro is restarted
  3. //——————————————————————————
  4. int main(void)
  5. {
  6. //——————————————————————————
  7. // Initialization (Done Once)
  8. //——————————————————————————
  9.         InitializeRobot();
  10.         int             Tick = 0;
  11.         RobotFlags = 0;
  12. //——————————————————————————
  13. // Main Loop (Never Terminates)
  14. //——————————————————————————
  15.         for(;;)
  16.         {
  17.                 if (RobotFlags & _BV(MSGRCV))       //Check to see if anything came in on the serial port
  18.                 {
  19.                         cli();   //Clear Interrupts
  20.                         RobotFlags=RobotFlags & ~_BV(MSGRCV);
  21.                         sei();  //Set Interupts
  22.                         if(CheckProtocol())
  23.                                 OnGoodPacket()//This function is in comms.c and is the main messaging function
  24.                 }
  25.                 if (RobotFlags & _BV(HBEAT))  //Check to see if a heartbeat happened, if it did, do the next Tick
  26.                 {
  27.                         cli(); //Clear Interrupts
  28.                         RobotFlags=RobotFlags & ~_BV(HBEAT);
  29.                         sei(); //Set Interupts
  30.                         Set_LED(LED_RXD, LED_OFF);
  31.                         ZigbeeHeartBeat();
  32.                         if(Tick==0)  //Ticks per pose is implemented so that the main motion only happens when Ticks is 0
  33.                         {
  34.                                 IMUReport(IMU_Report_Flag);   //Do IMU sensor reporting if set
  35.                                 ServoReport(Servo_Report_Flag); //Do Servo reporting if set
  36.                                 FootReport(Foot_Report_Flag);  //Do foot sensor reporting if set
  37.                                 if (UsingPoseSystem==2)  //If Usingposesystem = 2 then we are controlling servos directly
  38.                                 {
  39.                                         UpdateServosDirectly();
  40.                                 }
  41.                                 if (UsingPoseSystem==0)  //The UsingPoseSystem is used to turn on and off the dynamic gait.
  42.                                 {
  43.                                         DynamicGait();
  44.                                         PoseNum++;
  45.                                         if (PoseNum >= NumPoses) PoseNum = 0;
  46.                                 }
  47.                         }
  48.                         Tick++;
  49.                         if (Tick >= Ticks_Per_Pose) Tick = 0;  //Restart the Tick Counter
  50.                 }
  51.         }
  52. }

Repairing White Bioloid

Filed under: Daily — profmason @ 3:06 pm

Symptoms:

All servos work normally but when commands are sent rapidly to the robot, the system stutters as if there is an accumulated delay associated with each additional servo.

Solution:

Reflash the servos with the most current firmware:

  1. Open Roboplus
  2. Plug in a USB>Dynamixel
  3. Connect the servos to the USB->Dynamixel
  4. Connect the servos to power (Could be from CM5 with default firmware)
  5. Open Dynamixel Wizard
  6. Open the Port and connect to your USB>Dynamixel
  7. Start Search (If problems, make sure they have power, try them one at a time)
  8. After it finds the connected servos Click firmware update
  9. Update the servos.
  10. If you still have problems check the status return time (0) and the status return level (2) for each servo.

May 21, 2010

Introduction to Image Processing with Pens and Coins

Filed under: Daily — profmason @ 6:45 am

Aspect Ratio Based Object Identification

Martin S. Mason

School of Computing and Mathematics, University of Plymouth
Plymouth, PL48AA, UK

Abstract— A Canny filter is used to separate pens and coins from a high contrast background. Contours are calculated around the objects and the objects are discriminated based on two criteria, the aspect ratio of the bounding box around each object and the ratio of the area of the object contour to the area of the bounding box.

Introduction

Object identification is a common machine vision task. In order to identify particular objects in a complex image, it is first necessary to extract the objects of interest from the scene (figure ground separation) and then identify features on those objects that allow the objects to be uniquely classified. A variety of techniques including color filtering, thresholding, and edge detection can be employed to extract the objects of interest from background. After the objects are separated, unique features can be identified based on their geometric features including corners[1], edges[2], or blobs[3] and these features can be matched against a database of stored representations.

Computer vision has become much more accessible due to the introduction of high level computer vision packages such as OpenCV[4] and Roborealm[5]. These packages are best described as rapid prototyping systems that allow the user to quickly try out new computer vision techniques.

In this particular problem, the machine vision system is asked to discriminate between pens and coins positioned against a high contrast white background. (Fig 1.) This paper will describe the algorithms used to identify the pens and coins in the image, compare the speed of the algorithms, and discuss the limitations and possible extensions of these algorithms.


Figure 1: Sample image of pencil and coins used for testing the image processing algorithm.

Image Processing Algorithms

An image is read into a memory structure and converted to a greyscale by setting each pixel equal to the normalized average of the red, green and blue channels. [Fig 2]


Figure 2: Greyscale image created from the average of red, green and blue color channels.

A Gaussian filter[Fig 3] is then applied to the image which smooths the image but still preserves edges. The Gaussian filter is a employs the convolution of the image data with a convolution matrix equal to the Gaussian function. Since the convolution matrix is largest in the center and tapers off to the sides, this helps to preserve edge information in the image. This Gaussian filter is described as the first step in the implementation of a Canny filter in [2].


Figure 3: The Gaussian blur smooths the image while retaining edge information.

A Canny filter[2] is then applied to the image. [Fig 4]. The blurring in the previous step has served to remove any small discontinuities in the image. Now the directional derivatives are calculated for the image. This is done by just subtracting two subsequent left and right pixels for the horizontal derivatives and top and bottom pixels for the vertical direction. A non maximal filter is applied to the directional derivatives to only preserve only those edges that are on ridge, ie the directional derivatives should have opposite signs on either side of ridge. Finally, a threshold is applied to the ridges found from the non-maximal filter. Edges between the threshold value and half the threshold value are preserved if they connect to edges that are above the edge threshold.


Figure 4: Canny filter produces a binary image based on the edges determined from the directional derivatives of the images.

The image is then dilated[Fig 5] to connect any small areas that may be disconnected despite the large hysteresis in the Canny filter. The dilate function works by taking the binary image and if a pixel is white, setting the immediately adjacent horizontal and vertical pixels white(a 1:1 square kernel). This process is run through several passes to grow interesting features in a binary image.


Figure 5: The dilate fills in any small breaks in the image. This is an essential step for finding complete contours around the objects of interest.

Now contours are found around the objects of interest[Fig 6]. Contours are closed curves in the image as described in [4] pg 234-238. In this case only the external contours are objects are of interest.


Figure 6: Contours are found on the image. The contour will be used to discriminate between the pens and coins.

A this point all of the image processing is done. The complex original image has been reduced to a set of sequences of points which represent the objects of interests. These sequences will be used to discriminate between the pens and coins.

Object Identification

The previous section on image processing takes a complex scene and returns a set of sequences that represent contours around each of the objects of interest in the image. The list of contours is searched and any contour with a small area is removed to remove noise from the image as is illustrated below (Fig. 7)


Figure 7: The left image has many small contours that appeared due to noise early in the image. The right image shows that these have been removed by cutting on the minimum area of the contour.

A bounding box is generated around each contour. The geometry of this bounding box will be used to discriminate between pens and lines. The aspect ratio (the ratio of the width to the height) works to separate pens from coins in this and all the other test images.


Figure 8: The bounding boxes are drawn around the objects of interest.

The bounding box around a coin will be approximately square which means that the height of the box is approximately equal to the width of the bounding box. The aspect ratio is calculated as the bounding box width divided by the bounding box height. If this value is near one, then the object is labelled as a coin. If the value is far from one then the object is a pen. This condition is sufficient if the pens are oriented near vertically or near horizontally in the frame. However, if they are oriented diagonally, then the bounding box will have the same aspect ratio as the coins. As a second check, the area enclosed by each contour is calculated and that area is compared to the area enclosed by the bounding box. If the bounding box has a much larger area then the contour, then it is the case of a pen oriented diagonally. Based on these two criteria, the pens and coins are now labelled. [Fig 9]


Figure 9: The coins and pen are correctly labelled in the image as a result of the cuts on aspect ratio and contour to bounding box area.

Additional Techniques:

Since the coins are circular, a Hough Circles filter was applied [Fig 10]. This detected the coins in the image but was not as robust as the technique that was eventually employed. Large angles result in parallax distortions that the Hough circle is sensitive to. The Hough circle filter also identified a great deal of noise in the image as small circles leading to many false identification of coins.


Figure 10: Coins identified using Hough Circle Technique.

Discussion

The technique described consistently identified pens from coins in a wide variety of situations and orientations. (See Appendix 1) It is also not highly computationally expensive. However, in the interest of implementing computer vision on a small embedded platform, speed of the algorithm must always be considered. Replacing the Gaussian blur and Canny filter with a simple threshold [Fig 11] produced identical results with the test images with a much lower computational overhead. [Table 1]


Figure 11: Using a simple threshold to create a binary image. This image was then used to generate contours and the same

Technique

Time for 1000 iterations(s)

Iteration t(s)

Canny

73.0 ± 0.8

0.073

Threshold

59.0 ± 0.8

0.059

Table 1: The Threshold technique is faster within error then the Canny technique.

The Canny technique could only operate at 13.6 fps while the threshold technique could run at nearly 17 fps.

Limitations to Technique:

While the techniques described work well on all of the test images they fail in the presence of a similar background. For instance an image of the pen and coins on a dark wood table failed to recognize the objects from background. In addition as lighting conditions change, shadows can show up as additional objects are recognized and provide false positives in the system. Finally if the pen and coin are touching in the frame, they will be recognized as a single contour and be identified as either only a single pen or coin. An image with several of these difficulties is shown in Appendix 2. This image is outside of the image set, but the robustness of this technique is illustrated by its success with a more difficult image.

Conclusion

An aspect ratio based object system was developed that worked successfully on all of the test images. It is sufficiently robust that it works on more difficult images as is shown in Appendix 2. As is summarized in Table 1, the threshold based system required the least time to run. A webcam was also used for input to this system and it could successfully identify images given the limitations discussed above. This technique could be extended to deal with changing lighting conditions through the use of an adaptive threshold which changes the threshold value through the image based on the relative intensity of local pixels. The algorithm could be extended to deal with pens and coins that are touching through the use of contour geometry to define regions of interest and then successive erosion and dilation within those regions. Finally the problem of identifying the pen and coin on a low contrast background could be pursued by looking for corners within the image and using a classifier to match them against a library of known pens and coins.

References

J. Shi and C. Tomasi (June 1994). “Good Features to Track,”. 9th IEEE Conference on Computer Vision and Pattern Recognition. Springer.

Ferreira A., Engel P. “Positioning a Robot Arm: An Adaptive Neural Approach” Proc. NICROSP ‘96)

Canny, J. (1986). “A Computational Approach To Edge Detection”. IEEE Trans. Pattern Analysis and Machine Intelligence
8: 679–714. doi:10.1109/TPAMI.1986.

T. Lindeberg (1998). “Feature detection with automatic scale selection” (abstract). International Journal of Computer Vision
30 (2): pp 77–116.

Learning OpenCV, 1st Edition. By: Gary Rost Bradski; Adrian Kaehler. Publisher: O’Reilly Media, Inc. Pub. Date: September 24, 2008

S. Genter (2010) Roborealm: Vision for Machines: www.roborealm.com

Appendix 1: Processed Images:

All images were processed with the following settings:


Figure 1: The Gaussian Blur was set to use a 5×5 window. The Upper Threshold for the Canny filter was set to 150 with the Lower edge set to half of that or 75. The circle parameter for the Hough Circles was set to 35. The minimum distance between circles for the Hough Circle filter was 30 pixels. The dilate was set to run for 3 passes of a 1:1 kernel and the aspect ratio was set to 0.3 so that objects with an aspect ratio of less then 0.3 or greater then 3.33 would be considered pens.


Figure 4: coins1-small.jpg


Figure 1: coin2-small.jpg


Figure 3: pens1-small.jpg


Figure 4: pens2-small.jpg

Appendix 2: A more difficult image:

The following image [Fig 1] has shadows as a result of difficult lighting. The camera is at a significant angle relative to the subjects resulting in parallax of the image. The pens are at a near forty five degree angle and not entirely in the frame.


Figure 1: Source image.


Figure 2: The processed image with the Pens and Coins correctly identified.

May 11, 2010

HRI Validation Videos

Filed under: Daily — profmason @ 4:08 am

The aim of this project is to create an efficient personal, or service, robot that is able to accept commands from a user, and anticipate the user’s needs. Such social interaction between robots and humans might provide a useful tool in different contexts.

Video 1:

Video 2:

Older Posts »

Powered by WordPress