Showing posts with label Sensors. Show all posts
Showing posts with label Sensors. Show all posts

Wednesday, September 27, 2017

Tracking AR Tags with ROS: Monocular Vision

If you've found this I am going to assume that you are familiar with ROS. What you might not be so familiar with is AR tags (Augmented Reality Tags). I am not going to go into how AR tags work, because frankly I am not an expert in them. What I can say is that I have used them, and it is very easy using ROS. They allow anyone with a cheap webcam to get a full 6 DOF position from a single reference, an AR tag. They can be printed on any home printer and are fully scalable. Below is a picture of what a simple implementation looks like. Search YouTube for some videos. People are doing some cool things with them, but enough talk. Lets get a demo working.

Tracking 3 AR tags with a Standard Monocular Webcam, a Logitech C615


This post is the documentation for how I got it working on my machine. It should be mostly complete, but I will admit that I have probably left out some things that I thought were self explanatory. If you have problems or suggest changes, please post those in the comments.

AR tag

Prerequisites

1) Installed ROS Kinetic. I am using a virtual machine as detailed HERE.
2) Setup Catkin Workspace (I'll assume it's called catkin_ws).
3) Know some basic ROS. If you don't you can likely Google your questions.

Setup

Install package ar_track_alvar

1) Open a terminal in catkin_ws/src
2) In the terminal type:

git clone -b kinetic-devel https://github.com/ros-perception/ar_track_alvar.git 
cd ..
catkin_make


Install package video_stream_opencv

1) Open a terminal
2) In the terminal type:

sudo apt-get install ros-kinetic-video-stream-opencv
sudo apt-get update


Create our custom package

1) Open a terminal in catkin_ws/src
2) In the terminal type:

catkin_create_pkg ar_tag_demo std_msgs rospy


Install package image_pipeline

This is likely already installed. You can check with <rospack list>. If it is not simply enter into a terminal:

sudo apt-get install ros-kinetic-image-pipeline

Then run another catkin_make.

Write Launch Files

Camera.launch

In your custom package "ar_tag_demo", create a new folder called "launch". Inside, create a file called camera.launch. Copy the code below into it. It is a modified version of the camera.launch file from video_stream_opencv. Note that video_stream_provider may have to be changed to 1 if you are using an external camera. If you are using a virtual machine like I am, you will need to enable the webcam under Devices>Webcam in the Virtual Box menu. If you have issues with this, install the Virtual Box extension pack as discussed in my previous post.

<launch>
   <arg name="camera_name" default="camera" />
   <!-- video_stream_provider can be a number as a video device or a url of a video stream -->
   <arg name="video_stream_provider" default="0" />
   <!-- frames per second to query the camera for -->
   <arg name="fps" default="10" />
   <!-- frame_id for the camera -->
   <arg name="frame_id" default="camera_link" />
   <!-- By default, calibrations are stored to file://${ROS_HOME}/camera_info/${NAME}.yaml
   To use your own fill this arg with the corresponding url, e.g.:
   "file:///$(find your_camera_package)/config/your_camera.yaml" -->
    <arg name="camera_info_url" default="" />
   <!-- flip the image horizontally (mirror it) -->
   <arg name="flip_horizontal" default="false" />
   <!-- flip the image vertically -->
   <arg name="flip_vertical" default="false" />
    <!-- force width and height, 0 means no forcing -->
    <arg name="width" default="0"/>
    <arg name="height" default="0"/>
   <!-- if show a image_view window subscribed to the generated stream -->
 <arg name="visualize" default="true"/>

   
    <!-- images will be published at /camera_name/image with the image transports plugins (e.g.: compressed) installed -->
    <group ns="$(arg camera_name)">
     <node pkg="video_stream_opencv" type="video_stream" name="$(arg camera_name)_stream" output="screen"> 
      <remap from="camera" to="image_raw" />
      <param name="camera_name" type="string" value="$(arg camera_name)" />
         <param name="video_stream_provider" type="string" value="$(arg video_stream_provider)" />
         <param name="fps" type="int" value="$(arg fps)" />
         <param name="frame_id" type="string" value="$(arg frame_id)" />
         <param name="camera_info_url" type="string" value="$(arg camera_info_url)" />
         <param name="flip_horizontal" type="bool" value="$(arg flip_horizontal)" />
         <param name="flip_vertical" type="bool" value="$(arg flip_vertical)" />
         <param name="width" type="int" value="$(arg width)" />
         <param name="height" type="int" value="$(arg height)" />
     </node>

     <node if="$(arg visualize)" name="$(arg camera_name)_image_view" pkg="image_view" type="image_view">
      <remap from="image" to="image_raw" />
     </node>
 </group>

</launch>


Track.launch

Next we create the launch file that does the tracking. Again, this is a modified launch file from the ar_track_alvar package. Create a file called track.launch in your launch file folder and copy the following code inside it. Note that you will need to set the marker size. This is the length in centimeters of one side of the black part of an AR Tag.


<launch>
 <arg name="marker_size" default="6.9" />
 <arg name="max_new_marker_error" default="0.08" />
 <arg name="max_track_error" default="0.2" />
 <arg name="cam_image_topic" default="/camera/image_raw" />
 <arg name="cam_info_topic" default="/camera/camera_info" />
 <arg name="output_frame" default="/camera_link" />
 

 <node name="ar_track_alvar" pkg="ar_track_alvar" type="individualMarkersNoKinect" respawn="false" output="screen">
  <param name="marker_size"           type="double" value="$(arg marker_size)" />
  <param name="max_new_marker_error"  type="double" value="$(arg max_new_marker_error)" />
  <param name="max_track_error"       type="double" value="$(arg max_track_error)" />
  <param name="output_frame"          type="string" value="$(arg output_frame)" />

  <remap from="camera_image"  to="$(arg cam_image_topic)" />
  <remap from="camera_info"   to="$(arg cam_info_topic)" />
 </node>
</launch>


main.launch

Because this is a demo, you might only want to have to launch one file. This launch file simply calls the other two.

<launch>
 <include file="$(find ar_tag_demo)/launch/camera.launch" />
 <include file="$(find ar_tag_demo)/launch/track.launch" />

</launch>


Running the files

Camera Calibration

You will want to calibrate the camera using the camera_calibrate node (part of the image_pipeline package). You can follow the instructions found on the wiki for monocular camera calibration: http://wiki.ros.org/camera_calibration/Tutorials/MonocularCalibration

Here are the pertinent parts: 

1) Print the checkerboard pdf.
2) Open a terminal and type:

rosdep install camera_calibration
rosrun ar_tag_demo camera.launch
rosrun camera_calibration cameracalibrator.py --size 8x6 --square 0.0245 image:=/camera/image_raw camera:=/camera

Note that that the grid size (8x6) and square size (.0245) is for the above as printed on my printer. You may have to adjust it. The square size is in meters.

3) Complete the calibration by moving the checkerboard around the camera's field of view and rotating it in all directions.
4) When you are done, click commit to automatically save the camera calibration data. The camera node will now automatically pull that calibration file when you launch it.
5) ctrl + c in all terminal windows to stop camera and calibration nodes

Run the demo

In a terminal type the following command. 

roslaunch ar_tag_demo main.launch

This should bring up the camera and the tracking node. Feel free to rostopic echo ar_pose_marker to see the raw data, but RVIZ is probably more impressive. Launch RVIZ (type rviz into a terminal), and add TF to the data visualized on the left. Show the camera a marker, then set fixed frame to "camera_frame". You should now see something like this!



Show off your AR tag demo with pride! Don't tell anyone that Scott Neikum (the code maintainer) did all the hard work for you.

I hope this was helpful to someone. If it was, comment below and let me know. If you run into any problems or see anything that should be changed, comment below for that as well. 

Until next time,
Matthew

Saturday, December 27, 2014

Linearizing the Sharp IR Ranger (2YOA21) with an Arduino

Today I will be linearizing a Sharp IR Ranger. More specifically, I will be using the Sharp 2YOA21 F 04.


First, a quick word on why we would want to do this. The Sharp ir rangers are a very effective means of measuring distance. While ultrasonic sensors (for more about those see the Sensors label) can be fooled by textures and echos, ir sensors are more susceptible to interference from outside light sources and changes in material reflectivity. Therefore,  if a cheap measurement system is required in a varying environment (eg, a mobile robot) a combination of ultrasonic rangers and ir rangers can be quite effective.

If you have found this page, you probably already know this, but I will state it anyway. Sharp ir sensors have an analog output. However, the analog value does not have a linear relationship to distance. In this exercise we will find the function that does relate the two and use that to take an analog value and convert it to a distance.

Wiring

As stated above, the sensor has an analog output. Connect the red lead to +5V, black lead to GND, and yellow lead to A0.

Aquire Data


I used a simple sketch that took the average of 5 values and printed it to the screen. I then manually copied it into an excel spreadsheet along with the measured distance value. 


Fit Data

Once you have acquired the data, plot it. Some points will most likely fall outside of the trend. Exclude those points and fit the rest. My fit was Value = 1893.9*Distance^-0.92. 



Use Equation

Solving the equation I got above for Distance gets me this, Distance = (1893.9*Value) ^-1.087.

This is something we can plug into Arduino code. At this point it is only right to note that the method I am using will involve floating point math. There are methods that avoid that. If processing power is at a premium, you might want to check those out.

The important piece of code looks like this:


  float Distance = pow((sensorValue / 1893.9), -1.087); 

If you want the whole thing, you can download my code HERE.

That's all I have. I hope it was useful.

-Matthew


Saturday, February 8, 2014

DHT11 on ATtiny85

Recently I got my DHT11 temperature and humidity sensor working with my Arduino Mega2560. If you are interested in that, check it out HERE. However, while that was all well and good, I found it a bit impractical. While I may someday decide to create some sort of weather logger using the DHT11, it is unlikely that I would dedicate an entire Arduino to the task. Enter ATtiny85.

The ATtiny85 is great because it is cheap, but the real question is, "Does it work with the DHT11?" Yes it does.

Now in my last post I used the DHT library from Adafruit. While that library served its purpose, it does not work with the ATtiny. Don't ask me why; I did not explore it. HERE is another report of it not working and a description of what will happen if you try it. It reads out all zeros.

What does work is the DHT11 library. To get it working you will need to modify the example code. Basically, you need to change everything that says "Serial" to the Software Serial equivalent. This will allow us to get the sensor readings back from the ATtiny. If you want more information on serial communication on an ATtiny, check out THIS post. Alternatively, you could just download my code (HERE), wire everything the way I say, and see if it works.

Now when you go to compile my example, there is a good chance you will run into a problem. As it turns out,  there is an issue with the tiny core when trying to compile sketches close to the maximum sketch size. Luckily there is a quick and easy fix. I won't go into the details, but follow the instructions HERE.

When that was straightened out I was able to upload my sketch successfully. I used my USBtinyISP and my ATtiny85/45 programming adapter.


The only thing left to do is wire it up and see the output. Basic wiring of the DHT11 is the same as in my last post.

Correct Wiring:
Pin 1: +5V
Pin 2: Signal. Connect to digital IO with a 5k ohm pull-up resistor
Pin 3: Nothing. Some people suggest grounding it if you run into trouble
Pin 4: GND

On the ATtiny side, PB3 is the software serial Rx and PB4 is the software serial Tx. Connect those to an FTDI (or some other serial receiving device). Connect 5V and ground.


Power it up and watch the show!



This of course could be modified to do other things with the temperature data. It could, for instance, transmit them via I2C. Maybe it could log them on an SD card. Those projects I leave to you (for now anyway). If you are interested in more ATtiny projects of mine, check out my ATtiny label. Let me know if this works or doesn't work for you. As always, I'm happy to help.

-Matthew

Monday, February 3, 2014

DHT11 with Adafruit Library and Arduino Mega 2560

In this post I will be playing with the DHT11 Temperature and Humidity Sensor with my Arduino Mega 2560. While a DHT22 could also be used, I used a DHT11 mostly because it and it was cheap. I think I got mine for around a dollar. They can also be found it premade breakouts, but there really isn't much to them. As you can tell from the picture in the link, the breakout merely removes the extra pin and adds the pull-up resistor and a decoupling capacitor.

Once you decide on which sensor to buy, you will be faced with yet another choice. What library should I use? There are approximately a lot of them out there. I chose the Adafruit DHT library found HERE. It worked for me (and supports multiple sensors), so I saw little reason to pursue any of the other libraries.
This does NOT work

Now when I bought my DHT11 from Ebay, a picture like this was on the listing. Quite frankly, I don't understand what this is getting at. It doesn't work. While I can't vouch for the rest of the world, my sensor is not analog. It is digital. You can even look at the datasheet.

Correct Wiring:
Pin 1: +5V
Pin 2: Signal. Connect to digital IO with a 5k ohm pull-up resistor
Pin 3: Nothing. Some people suggest grounding it if you run into trouble
Pin 4: GND



Once everything is wired up, open the example sketch. It does about everything I would want it to do, so there is not much to say. Uncomment the correct sensor and upload. Open the serial monitor and get testing. 

There isn't much to say about this sensor. It is slow and probably not too accurate, but with the hard work of making the library already done, this sensor is incredibly easy to use. If you don't like my description of this sensor, there are many others out there at your disposal. If you do like it, I'm glad I could be of help.

-Matthew

Thursday, January 9, 2014

I2C HC-SR04 Sonar Module: ATtiny85 I2C

In this post I will show you how to cheaply  make an I2C sonar sensor for your Arduino. This will be accomplished by making an I2C controller for an HC-SR04 sensor out of an ATtiny85 (or ATtiny45). Both the sensor and the microcontroller can be found online for a few dollars. Together these two parts can save you money while increasing functionality over premade solutions.

If you have not already done so, check out my previous post on a serial sonar sensor. It also discusses running the NewPing library on an ATtiny (my modified TinyNewPing library). I have also done a post on I2C communication. In fact, I even transmitted data from my PING sensor! Check it out HERE.

1) First off, we need an I2C library for your ATtiny. For this you have a few options, but I will only be using one of them. The regular Wire library will not work on the ATtiny side. However, thanks to some great work  by Arduino users BroHogan and Rambo we do have the TinyWire library. The original library by BroHogan can be downloaded HERE. I have used the Master library from it, but for the Slave library I will be using a fork by Rambo. He added a bit more functionality including an onRequest and an onReceive function (which I use in my examples). Find his library HERE (download zip link is in the bottom right corner).

You will also need the ATtiny core for whatever Arduino IDE you are using. In the past I have used the core from High-Low Tech. Now however I prefer the Google Code core. A recent update allows ATtiny support with Arduino 1.5. Anyway, if you need more details on getting an ATtiny running see my previous posts linked above or click on the ATtiny label.

You need to burn your ATtiny85/45 to 8MHz. This is important for stable I2C communication (consider making my ATtiny programming adapter!). You also need my TinyNewPing library installed.



2) Wiring is simple. Connect the 5V from the Arduino to the VCC of the ATTiny and the PING sensor. Connect all the grounds together. Then connect the Trigger and Echo pins of the PING sensor together and to pin 3 (PB3) of the ATtiny85. Next connect the I2C wires. Connect the ATtiny SCL (PB2) to the Arduino SCL (Arduino Uno: A5 , Arduino Mega2560: 21 , Arduino Due: 21). Connect the ATtiny SDA (PB0) to the Arduino SDA (Arduino Uno: A4, Arduino Mega2560: 20 , Arduino Due: 20). Finally, and very importantly, connect 4.7k (on 5V) ohm pull-UP resistors to the SCL and SDA lines.





3) Now you have the libraries installed. Everything is wired up. The only thing left to do is test it. THIS code goes on the ATtiny. It reads one HC-SR04 sensor and acts as the I2C slave. THIS code goes on your other Arduino. I used a Mega, but you can use whatever you have. It requests the data from the slave and then outputs it to the serial monitor.

That is about it. Assuming everything works, you are ready to go. Using this method, you should be able to get sensor data from many sensors at once using only 2 pins on your Arduino. One thing to remember, since they are not all being controlled by the same Arduino, the sensors are not synchronized. As such, they could interfere with each other if they are pointed in the same direction.

Also, I attempted to control multiple sensors with one ATtiny. This worked, sort of. It was buggy and crashed after 15 seconds or so, I suspect do to a I2C buffer issue. Regardless, it made the code more complicated on both sides and the system wasn't as reliable. Besides (I said to myself), ATtinys can be found fairly cheap (especially surface mount ones). My time is worth something. While I got tired of messing with it, if someone else gets it working let me know. I'd be interested to see your code.

There you have it. A cheap I2C ultrasonic ranger for an Arduino (or I2C master device of your choice). If you use this approach in any of your projects I would love to hear about it in the comments. Of course, if you have problems I will do my best to help you with them.

-Matthew

Friday, November 1, 2013

KY3361ABR-242 Mini Volt Meter

This is a mini review for a volt meter I picked up off eBay a while ago for about $1.50. I don't know that it has a name, so I have decided to call it the KY3362ABR-242 Mini voltmeter. I suspect KY3362ABR-242 actually refers to the display, but regardless it is written on the bottom of the volt meter. That is what I am calling it. As you can see in the pictures, V1303 and DV036A are also printed on the back, but I am ignoring those.

Not a whole lot of information was given with this purchase, but what the seller offered I saved for posterity below.
Specifications:
  • Measuring range: DC 0V--30V
  • Input range: DC 2.5V-30V (Max Input: DC 30V. The device can be damaged if input is over 30V)
  • Display Color: RED
  • Display: Three 0.36 "digital tube
  • Measurement accuracy: 0.1%
  • Refresh rate: about 300mS / times
  • Input impedance: About 100K
  • Dimensions:33mm*15mm*10mm
  • pitch of holes:28mm
  • aperture size :2.8mm
  • Operation Temp: -10℃-+65℃
Wiring:
  • red:power supply +
  • black:power supply -, measure -
  • white:measure +



I soldered on some nice male headers with some heat shrink and got to testing. Here are the photos.

Measuring the 3.3 V supply from my MB-102 power supply

Measuring the 5 V supply from my MB-102 power supply

Measuring the 5 V supply from my Arduino Mega powered over USB.

As you can see, the mini voltmeter consistently read close to the same thing that my craftsman meter read. Granted that is not the best benchmark, but it is what I have. It is also interesting to note that the KY3362ABR-242 can even measure the power supply from which it is being powered.

All in all, this is a very nice little purchase. I would definitely pick one up if you have a need. It is not going to replace your multimeter, but it is a very nice real time display for breadboard power supplies or similar. You can also do cool stuff like hack it into an I2C display.



Wednesday, August 7, 2013

Serial Sonar Sensor: ATtiny85, HC-SR04, and Arduino SoftwareSerial

In this post I will detail how I used an ATtiny85 as a controller for an HC-SR04 sonar module (Ping sensor). The controller reads the inputs from up to 3 HC-SR04 modules and transmits the readings to an Arduino Mega via serial communication. This allows the Arduino Mega to pick up the readings whenever it is convenient rather than having to worry about complex timings. Let's get started


First things first, we need to run the NewPing library on an ATtiny85/45/25. Until version 1.6 is released you will need to modify the library to do this. However, this removes some of the functions you might want to use on other boards. For this reason, I created the TinyNewPing Library. In it, I removed the parts that cause the errors on an ATtiny and gave it a new name so you can distinguish between the two. All the function names remain the same. If you still need more details check out THIS prior post.

Next we need the SoftwareSerial Library on the ATtiny. Luckily, this comes with the IDE and I already did a post on it. Funny how that works.

For a first attempt, try a single HC-SR04 sonar sensor. This simplifies the code a bit. Load THIS code on the ATtiny (sensor side) and THIS code on the Arduino Mega. Note the code uses both Serial and Serial1 (thus the Arduino Mega).

To wire it up, connect the echo and trigger pin together and then connect them to pin 0. Wire in 5V and ground to both the ATtiny and the HC-SR04. Then connect pin 4 (Software Tx) on the ATtiny to pin 19 (Rx1) on the Mega. Finally, plug the Mega into the computer via USB.

Now if this is working ok, we can move on to 3 sensors. For that, we need to load THIS code onto the ATtiny and THIS code onto the Arduino Mega. The ATtiny takes the readings and sends them to the Mega. The Mega updates it's variables and sends them to the Serial Monitor for us to see.

Wiring it is cumbersome but simple. Regrettably, I did not take a picture when I did it, but just do what you did before an extra two times. Note again that we are using the same pin for trigger and echo, so they need to be wired together. Then wire up power and grounds. Finally connect the ATtiny to the Mega and the Mega to the computer.

Now open the Serial Monitor and watch the numbers scroll by.

Potential problems: If the ATtiny gets out of sync with the Mega (it will), an occasional bad value will come up. I couldn't come up with a quick fix for this. If that is a problem, maybe you could take the median of a few readings. They are coming in pretty quickly. The plan is to make an I2C version of this soon, but I make no promises on a deadline. One last download, get the entire package of sketches used in this post in a zip file HERE.

A few quick notes before we go.

  • Why not I2C? That's next (Done! Check it out HERE). Serial is easier because it doesn't require a 3rd party library to work on the ATtiny line. 
  • Why only 3 sensors? Short answer, ease of use. You might be able to get 4 or even 5 out of an ATtiny45 if you're persistant. I don't have that many sensors nor that much patience. You have 5 regular IO pins plus the reset pin (which can be used as an IO). You might be able to use the serial Rx pin as an input as well. 
  • Why not just buy a I2C ping sensor and be done with it? Well this reduces the number of wires going to the Arduino Mega. It also gives you more options and increases the number of micro controllers on board your robot (cool factor). Other than that, it's cheap. With HobbyKing or Ebay, this project could be done for less than the price of one I2C sonar sensors.
Hopefully someone will find this useful. If anything goes great, please comment! If anything goes wrong, contact your local internet service provider. I blame them (That's a joke. You can comment below as well).

-Matthew

Tuesday, July 16, 2013

Deer Defense System: PIR motion sensor

Today I will provide information necessary to build a Deer Defense System (DDS). The specific plans I will be using were leaked from an undisclosed source at the DoD and are highly classified. Continue reading at your own risk.

This summer has been a unique adventure at the family garden. First, for whatever reason our squash have grown huge this year. Second (and more relevant), the deer have been particularly aggressive and determined.

For those of you that may not know, in certain areas of the Southern United States white-tailed deer (Bambi) are quite prolific. What may be less known is that these deer love to eat bean plants and will tolerate eating squash, tomatoes, cucumbers, and anything else you don't particularly want eaten. I can vouch for this from experience. Feast your eyes on the destruction.

Well we explored several more traditional methods of repelling deer. We tried all sorts of smelly concoctions. Some worked until it rained. Planting garlic did not help. Marigolds and mothballs did not help. The .30-06 did not work (We didn't try. Deer are out of season. Babies). They sell motion activated sprinklers that would probably work, but they are $50 a piece. No dice.

Having too much free time, I set about making a motion activated deer scaring device (these plans weren't really stolen from the DoD). Here is an overview.

At the heart of the matter is a Pyroelectric InfraRed  sensor. Mine was purchased from Ebay for $1.98. It does work, but be warned, when I asked for the datasheet they said it was a "trade secret." Right. Several other vendors carry them. For details on how to use a PIR sensor see THIS link. Basically, a pin goes high when it senses motion.


 My sensor had several adjustments on it. I found the picture on the left that tells what everything does. By wiring up an LED as discussed in the link above, I then found the settings that worked best for me.

After getting my motion sensor working I had to decide what brains to put in it. I considered another ATtiny45 , but decided to try something simpler first. I just hooked a transistor to the output of the sensor and used it to turn on a bright LED and sound a buzzer. 


Now the biggest concern I have here is the power consumption. I am powering the entire thing on 3 AA batteries. I read online that most of these PIR sensors use about 1.2 mA while on idle. I need a way to shut it down during the day (deer eat gardens after dark). Basically I want a nightlight circuit. 

I had a photo-resistor, but unfortunately the only transistors I had were NPN. This led me to use THESE plans to turn on the power to the PIR sensor only when it is dark outside. When it is light, it supposedly uses in the realm of .1 mA. With this addition, the DDS should last a month or so depending on how often the alarm goes off. Below is a rough diagram of what I built. The circuitry on the left turns on the power at night. The stuff on the right scares the deer.
The switch is the PIR sensor
I soldered everything together and hot glued it into a nice watertight container. Now it is ready to go. I don't know if it will actually scare off the dear or not. I suspect it will not do too much. Regardless, it was a fun project. I hope you enjoyed it!

-Matthew 




Saturday, April 6, 2013

NewPing library on ATtiny

Well now we have come to the point where I need to address Problem 3. If you don't remember that one, it was mentioned back a few post ago.

We need to run the NewPing library (for my HC-SR04) on the ATtiny85. First things first, we will need some code to test it with so we know it is working. It doesn't have a convenient serial interface like the Mega. Enter NewPingLED.

Its purpose is to turn on an led when an object gets within 20cm of the sensor. This is something that the ATtiny85 can manage.

Next, I got it running on my Mega. Not too difficult. I did note that this sensor was a lot less accurate (and precise) than the other ones I got. Sometimes you get what you pay for. It was like $2.50 on Ebay.

I posted a video in case you don't believe me. Obviously, the Mega can also run any of the example programs that come with NewPing 1.5 as well.


Now on to the ATtiny. Well the code doesn't compile right out of the box. The problem is with some of the timers that the ATtiny doesn't have. This is discussed HERE. It sounds like a fix will be coming up shortly in version 1.6, but in the meantime you just have to comment out the stuff about the timers. If you want the library with that stuff pre-edited out, its HERE. Note that you won't be able to use those parts of the code on any other board until you change it back. Hopefully 1.6 isn't far away.

Now that we have that out of the way, we just need to change the pins to something usable, get rid of the serial stuff, and wire it up. I'm going to assume you can handle that (remember the resistor on the LED!). If you are having trouble with basic wiring and such, check out Jeremy Blum's stuff HERE.

The new code is HERE. As you can see, it works well. It's no miracle of science, but it's a step toward doing what I want to do. Just for fun I also did a Fade program. Next, I think it would be cool to do some basic communication with my Mega. Sending Ping values back and such. I also have some other projects on my mind though.


In case you didn't know, next week is National Robotics Week. That's sure to be a blast. Also, in the world of FIRST robotics, nationals are coming up. Be sure to check out the webcast HERE. There are sure to be some awesome Frisbee shooters there.

That's all I have for now. Check in again,
-Matthew

Monday, February 25, 2013

New Source for Cheap Parts?

Ok. I just found a great website online and had to tell people about it. I have never ordered from there but I no doubt will soon. http://yourduino.com. They have all kinds of cheap started kits and stuff I've been ordering from eBay for about the same prices.

They also have several Arduino Compatible micro controllers that I would look into. Some have built in servo connections and such. If I hadn't just ordered some stuff from elsewhere, I would probably be buying something from there.

Things that caught my eye:

  • Their shields (the motor controller shield)
  • Their micro controllers (YourDuinoRobo1- $17)
  • The pre-made drive platform
  • The cheap stepper motors
  • The various sensors
  • The starter kits.
  • The jumpers, resistors, etc.
Some of the starter kits actually looked pretty good. I didn't look too in depth. I'm sure some stuff is missing, but it might not be a bad place to start. The robot platform doesn't look to shabby either. I didn't check shipping on the heavier stuff, but some of you might want to look into it.

I realize this is a bit out of the blue, but I honestly am not affiliated with them in any way. I just stumbled across their site when looking for cheap stepper motors and then saw the micro controllers  Then I saw the shields. Then I starting going through practically every page.

That's all I have for today If anyone has bought stuff from there please comment. I would personally love to know what kind of service they provide. 

See you later,
Matthew

Monday, February 18, 2013

Differential Steer Robot: Wiring

Greetings once again. I said I would post some more details about wiring up the robot. Well this shouldn't take to long so here it goes.

The first place I started was the servos. Like I said last time, these are continuous rotation servos (now that I've modified them). They have three wires. Depending on what brand of servos you have, they will be different colors, I'll assume you have Futaba servos like me, but if you don't its not too hard to figure out.



  • Red: Power. These servos like 4.8-6V. These are based off of the nominal voltage for NiMh (or Ni-Cd)  batteries. So a 5 cell works fine even though its actually higher than that hot off the charger. Don't try to run them directly off the Arduino. 40mA per pin isn't a lot.
  • Black: Ground. This goes to the negative side of the battery. One important note. You must tie the negative side of the battery back into the GND port on the Arduino board. You will beat your head against the wall until you do this. I know this from experience..
  • White: Signal. This wire will go to a PWM enabled digital IO pin. By using the built in servo library you can transmit PWM signals to the servos. Different pulse widths correspond to different angles. The servo will attempt to turn to that position. This is how our servos work. We have disabled the potentiometer so that no matter how much the servo turns, it never thinks it has reached its destination. Some people claim that servos actually run on PPM. I don't really know which is correct, and it hasn't been worth my time to figure it out. The servo library works. If you want to see the servo wave form, Google it.
So I used my extensions to connect my servos so I could leave my servos mostly intact. White went to one of my PWM pins. Then I connected Red to the positive rail on my breadboard. Black went to the negative rail. I connected my 6V battery to the same rails. Then I tried it out! It jittered around and didn't work. After several hours of frustration I realized my stupidity. You MUST wire in a common ground. ie, connect your ground rail on the breadboard to the GND pin on the Arduino. I knew this but forgot and wasted lots of time chasing a problem that should have never existed. Anyway, the picture to the right should clarify if you're confused as to what colors are equivalent.

A quick note, I have been experiencing some odd fluctuations in my servos. A servo will stop until I tap it.Then it will come back on. I have not yet had time to track down the root of these problems. I believe it is a flaky connector somewhere. I have also considered that I need to filter some noise on them. If you know how to do this and wish to, then go ahead. At the moment, I have bigger fish to fry. I doubt that this is the problem anyway.

Ok. Servos are wired. The Arduino itself is much easier. Get a connector and solder it on as dictated HERE.  I scavenged one off of a old power supply, but if you find a good source for these cheap, feel free to email me or post in comments.

Now the ultra sonic sensors. These are pretty straightforward as well. Wire them as written on the board. I use the sensor shield and my female jumpers. Power (5V. Arduino power, not servo battery). Ground. One IO pin to trigger signal. One IO pin to listen for response.

That's about it. I also have the other rail of my breadboard wired in to 5V. This gives me a 6V rail for servos, LEDs and other high current draw stuff and a 5V rail for logic stuff. Be sure to tie all the grounds everywhere together.

That's about it for today I think. I had planned to begin with videos of object avoidance after this, but I have been met with a bit of a tragedy. I'll talk more about that later. Lets just say, stuff happens. Its not a bad idea to have an extra $20 Arduino sitting around. I may try to work around that. We'll have to see. I've got some tests early this week, but maybe towards the end I'll have time to write again. I will say this, I have gotten some ATtinys and am pretty excited about playing with them. Unfortunately they are at the end of a long list of things to do (including type this post).

With that, I think I shall end. If you have any questions, comments, rants, praises, or large sums of money for to give me, post in the comments or send me an email. If not, just follow so as not to miss out on the latest exciting installment! 

Until later,
Matthew

Saturday, February 9, 2013

Differential Steer Robot: Overview

     Greetings. Its been a while. For that I apologize. Today I decided to take a break from Calculus to type up a new post. So here it is! Anyway, you may have been wondering, "What could he have done with that Arduino?" Well I did something no other person in the world has ever done. Guinness is on his way. I made a differential steer robot. I know. One of a kind. No one else has ever thought of that. And there it is!

     Actually, that is not what it currently looks like. That is what it looked like a month or so ago. It now is sporting 5 more sensors and a real time clock module, but that will come later.

     So what are we looking at? Well its pretty simple really. In the middle we have the Arduino Mega previously mentioned. It is wearing the v4 sensor shield.

     To the left of the Arduino is a solderless breadboard. I got mine off of ebay and I haven't seen one cheaper anywhere else. Mine was called "Mini Solderless Breadboard Bread Board 400 Contacts Available Test Develop DIY." Really, just make it has the rails on the side. This one was $3.22. Radio Shack is more than that, but China takes a while. I just order in advance

     Above and below the breadboard we have two ultra sonic range finders (pictured on the left). Now you can buy these for $30ish at places like robotshop, but these two came from ebay as well. HC-SR04, they cost about $2 each. Mine worked flawlessly. They are a great introduction to thinking like a computer. They work like sonar and are pretty good. They don't like angles all that much, but this is a learning  process. We'll move on to the $2000 LIDAR module later (as soon as a reader buys me one).



     To the right of the Arduino we have the batteries. Now these batteries are pretty up for grabs. I used what I had. They are pictured to the right. The big one is a 7 cell NiMh battery made to go in a Traxxas Stampede RC Truck. It is powering the Arduino. Needless to say, it will power it for a long time. It provides 8.4V to the Arduino voltage regulator. I also put a switch in the circuit because that makes things much more convenient. I ordered these switches as well as some limit switches(and LEDs, etc) I used later from Pololu.com. I think they were 50 cents or something. Since then I have discovered BGmicro.com which also has cheap stuff, but I have never ordered from there and am getting off topic.
     The one below the large battery is a 5 cell NiMh that powers the servo motors. Long story short, the Arduino can't provide enough power through a digital IO pin to power them so we wire in external power through the breadboard. Hobby servos like 4.8v or 6.0v (nominal) so this is perfect. The battery is one I got from Hobbypartz.com. Its a China importer based in California( I think). Shipping is faster than China. The connectors are Deans (T-connectors) and Traxxas connectors from Hobbyking. Connectors like that are one of the things you have to buy from there. I've found that even if I only use 2 or 3 of them, I'll break even with the hobby shop. Find Deans HERE, Traxxas HERE. If you are using dedicated batteries for this project feel free to use whatever connector you want. Tamiya, EC3, XT60, etc. But I will say that Deans are easy to solder. If you want, you could even use rechargeable AA batteries. I already had these and the charger from my previous rc plane endeavors so this is what I used. I kept the Traxxas connectors so the big battery will still fit in the truck.

     Below deck is a set of fps-148 Futaba servos modified for continuous rotation. How to do this? I used instructions HERE. Its a 60 second procedure. Google search it. I also had these servos sitting around. If I had to buy everything I would probably go with servos from HobbyKing. I've used some of the HXT servos before for planes, and they work well. I'd go with THESE most likely, but do what you wish. I haven't researched it all that extensively. You want something with a futaba spline if you are going to use the wheels I did.

     Speaking of which.. The wheels came from Pololu as well. I got the ones found HERE. They screw on just like a servo horn. Easy as can be. While I'm at it, the front ball caster also came from there. I got the .75" version found HERE. Alternatively you could search for ball transfers on a site like McMaster-Carr.


      The white thing on the side is just part of an old computer I put on there for its switches and LEDs. We'll get into that later.

     Assembly is quite straight forward. Wood glue, hot glue, and some machine screws. My total dimensions are 8" x 11". The ultra sonic sensors are mounted on a little block that cradles it (mine is balsa because it was easy to shape) and a tab that rotates.
    The Arduino is held on with some little dowel rods that I made to fit the holes and a few metal standoffs. If you use metal standoffs, be sure to put some sort of insulator between the metal and the board. I used homemade washers made from a cereal box.


Other things you'll want:

  • female-->female jumpers. Get these on ebay. Search for dupont connectors. 40pcs for $3.
  • jumper wire: any 22 awg solid wire will do.
  • Resistors: again, I like ebay. I got 400 metal film resistors in assorted sizes for < $5.
  • *optional* THESE. They make connecting the servos more tidy.
  • Other stuff: Electrical tape, heat shrink, etc. 
  • Basic Tools: Soldering Iron, Wire Strippers, Digital Multimeter (Must have some variation of all these things. You just do.)
  • X-Acto Knife: These are dirt cheap at hobbyking. 50 cents. I have many of THESE. And extra blades HERE.

 
     Ok. Well this post is getting pretty long so I better wrap it up. I hope this has inspired you to greatness. If you have any questions, comment or send me an email. I would encourage you to check out Jeremy Blum's YouTube channel too(HERE). He has some great tutorials for Arduino and knows much more about electronics than I do. I have learned a lot from his videos.

     If you want to go ahead and stock up for the future, order some IR LEDs, IR photodiodes, and 2.54mm male headers from Ebay and some of THESE too. Next post I 'll try to get into more details of wiring this thing up. I'll start throwing out some free code soon too. See you later!

Have Fun!
Matthew