Difference between revisions of "Project details"

From PHYSpedia
Jump to: navigation, search
 
(31 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Authors: Soobum Kim and Jack Maseberg
+
Authors: Jack Maseberg
  
 +
Arduino Uno code file:
 +
[[File:Kinect bot.ino]]
  
Here is my recent arduino code for our robot.
 
  
/*
+
Install CodeBlocks 10.05 WITH mingw (gcc)  <br />
prototype_unified_test
+
Install openFrameworks (http://www.openframeworks.cc/download/) <br />
*/
+
Read the openFrameworks "setup guide" for your OS and add the extra include and library files to your CodeBlocks install. <br />
 +
Create a "myApps" folder in "of_preRelease_v007_win_cb\apps" <br />
 +
Copy the serialExample folder from "of_preRelease_v007_win_cb\apps\examples" into your "myApps" folder. <br />
 +
Open the "serialExample.workspace" file in CodeBlocks and click to expand the "src" folder. You can double click on each of the three files (main.cpp, testApp.cpp, and testApp.h) and start modifying them! On windows, we had to change the serial.setup line to be: serial.setup("\\\\.\\COM17", 115200); in the testApp.cpp file to connect to our Arduino using Bluetooth! <br />
  
#include <Wire.h>
+
Kinect: use git: git clone git://github.com/ofTheo/ofxKinect.git
  
 +
Following the instructions here: https://github.com/ofTheo/ofxKinect
  
char val;        // variable to receive data from the serial port
+
Put the ofxKinect folder in your of_preRelease_v007_win_cb\addons folder and copy the example folder inside of the ofxKinect folder to your of_preRelease_v007_win_cb\apps\myApps folder. Before you run anything plug your Kinect in and update/install drivers found in the of_preRelease_v007_win_cb\addons\ofxKinect\libs\libusb\win\inf folder. Then you can run the example ofxKinectExample_win.workspace file!
int ledpin = 13;  // LED connected to pin 13 (on-board LED)
+
 
int HMC6352SlaveAddress = 0x42;
 
int HMC6352ReadAddress = 0x41; //"A" in hex, A command is:
 
int headingValue;
 
const int LMDir = 12;  // Left motor direction       
 
const int RMDir = 13;  // Right motor direction
 
const int LMSpeed = 9;  // PWM for Left motor connected to digital pin 9
 
const int RMSpeed = 10;  // PWM for Right motor connected to digital pin 10
 
  
  
 +
Kinect: LPF-00004 (has usb and external power adapter) ($145) <br />
 +
Arduino Uno http://www.mouser.com/ProductDetail/Arduino/A000066/?qs=sGAEpiMZZMtE4ePzUE8d2JuFIVM5Ac0l  ($25)<br />
 +
Motor Driver Sheild http://store.nkcelectronics.com/freeduino-arduino-motor-control-shield-kit.html ($11) <br />
 +
Aluminum standoffs: http://www.mcmaster.com 93505A102 ($0.44x8 = $3.52) <br />
 +
Motors: Mini Metal Gearmotor 100:1 http://www.sparkfun.com/products/8912 ($13x2 = 26$) <br />
 +
Wheels: Wheel 32x7mm (7mm D shaft) http://www.sparkfun.com/products/8901 ($7 for pair) <br />
 +
Battery: Polymer Lithium Ion Battery - 1000mAh 7.4v http://www.sparkfun.com/products/10472 ($7) (this will run the bot for about 1 hour)<br />
 +
Battery Charger: "iMax B6 Balance Charger" Li-Ion/Polymer Battery Charger/Balancer - 50W, 5A http://www.sparkfun.com/products/10473 ($33) (use NiMH setting when battery is too low to charge with Li2S setting)<br />
 +
Digital Compass HMC6352 http://www.sparkfun.com/products/7915 ($35) <br />
 +
Bluetooth Modem BlueSMiRF Silver http://www.sparkfun.com/products/10269 ($40) <br />
 +
Total Materials Cost ~ $333 plus shipping! <br />
  
void setup()
 
{
 
  pinMode(2, OUTPUT);
 
  pinMode(ledpin = 13, OUTPUT);  // pin 13 (on-board LED) as OUTPUT
 
    TCCR1B = TCCR1B & 0b11111000 | 0x01; //set PWM freq to 31250 Hz on pins 9 and 10
 
  pinMode(12, OUTPUT);  // sets the pin as output
 
  pinMode(13, OUTPUT);  // sets the pin as output
 
  pinMode(LMSpeed, OUTPUT);  // sets the pin as output
 
  pinMode(RMSpeed, OUTPUT);  // sets the pin as output
 
    // "The Wire library uses 7 bit addresses throughout.
 
  //If you have a datasheet or sample code that uses 8 bit address,
 
  //you'll want to drop the low bit (i.e. shift the value one bit to the right),
 
  //yielding an address between 0 and 127."
 
  HMC6352SlaveAddress = HMC6352SlaveAddress >> 1; // I know 0x42 is less than 127, but this is still required
 
  Wire.begin();
 
  
 
  Serial.begin(115200);      // start serial communication at 115200bps
 
 
 
}
 
 
void loop() {
 
  digitalWrite(2, LOW);
 
  if( Serial.available() )      // if data is available to read
 
  {;}
 
    val = Serial.read();        // read it and store it in 'val'
 
 
  if( val == '0' )              // if '0' was received led 13 is switched off
 
  
  {
+
Uno schematic:
  digitalWrite(ledpin, LOW);    // turn Off pin 13 off
+
[[File:Uno schem.png]]
delay(200);                  // waits for a second 
 
Serial.println("13 off");
 
  }
 
  
if( val == '1' )              // if '1' was received led 13 on
 
 
  {
 
    Serial.println("13 on");
 
  digitalWrite(13, HIGH);  // set the LED on
 
  delay(200);              // wait for a second
 
  
 
 
}
 
  
if(val == 'f' )
+
H-bridge schematic:
 
+
[[File:Hbridge.png]]
{
 
  Serial.println("Motor Forward");
 
  digitalWrite(LMDir, LOW);  // digital write to set direction (LOW or HIGH)
 
  digitalWrite(RMDir, LOW);  // digital write to set direction (LOW or HIGH)
 
  analogWrite(LMSpeed, 200);  // analogWrite values from 0 to 255 correspond to 0% and 100% duty cycle
 
  analogWrite(RMSpeed, 200);  // analogWrite values from 0 to 255 correspond to 0% and 100% duty cycle
 
  delay(10);
 
}
 
 
 
if(val == 'b' )
 
{
 
  Serial.println("Motor Backward");
 
  digitalWrite(LMDir, HIGH);  // digital write to set direction (LOW or HIGH)
 
  digitalWrite(RMDir, HIGH);  // digital write to set direction (LOW or HIGH)
 
  analogWrite(LMSpeed, 200);  // analogWrite values from 0 to 255 correspond to 0% and 100% duty cycle
 
  analogWrite(RMSpeed, 200);  // analogWrite values from 0 to 255 correspond to 0% and 100% duty cycle
 
  delay(10);
 
}
 
 
 
if(val == 's' )
 
{
 
  Serial.println("Motor Stop");
 
  digitalWrite(LMDir, LOW);  // digital write to set direction (LOW or HIGH)
 
  digitalWrite(RMDir, LOW);  // digital write to set direction (LOW or HIGH)
 
  analogWrite(LMSpeed, 0);  // analogWrite values from 0 to 255 correspond to 0% and 100% duty cycle
 
  analogWrite(RMSpeed, 0);  // analogWrite values from 0 to 255 correspond to 0% and 100% duty cycle
 
  delay(10);
 
}
 
 
 
if(val == 'r')
 
{
 
  Serial.println("Motor Rotation Right");
 
  digitalWrite(LMDir, HIGH);  // digital write to set direction (LOW or HIGH)
 
  digitalWrite(RMDir, LOW);  // digital write to set direction (LOW or HIGH)
 
  analogWrite(LMSpeed, 200);  // analogWrite values from 0 to 255 correspond to 0% and 100% duty cycle
 
  analogWrite(RMSpeed, 200);  // analogWrite values from 0 to 255 correspond to 0% and 100% duty cycle
 
  delay(10);
 
}
 
 
 
if(val == 'l')
 
{
 
  Serial.println("Motor Rotation Left");
 
  digitalWrite(LMDir, LOW);  // digital write to set direction (LOW or HIGH)
 
  digitalWrite(RMDir, HIGH);  // digital write to set direction (LOW or HIGH)
 
  analogWrite(LMSpeed, 200);  // analogWrite values from 0 to 255 correspond to 0% and 100% duty cycle
 
  analogWrite(RMSpeed, 200);  // analogWrite values from 0 to 255 correspond to 0% and 100% duty cycle
 
  delay(10);
 
}
 
 
 
 
 
  //"Get Data. Compensate and Calculate New Heading"
 
  Wire.beginTransmission(HMC6352SlaveAddress);
 
  Wire.write(HMC6352ReadAddress);              // The "Get Data" command
 
  Wire.endTransmission();
 
 
 
  //time delays required by HMC6352 upon receipt of the command
 
  //Get Data. Compensate and Calculate New Heading : 6ms
 
  delay(6);
 
 
 
  Wire.requestFrom(HMC6352SlaveAddress, 2); //get the two data bytes, MSB and LSB
 
 
 
  //"The heading output data will be the value in tenths of degrees
 
  //from zero to 3599 and provided in binary format over the two bytes."
 
  byte MSB = Wire.read();
 
  byte LSB = Wire.read();
 
 
 
  float headingSum = (MSB << 8) + LSB; //(MSB / LSB sum)
 
  float headingInt = headingSum / 10;
 
 
 
  Serial.print(headingInt);
 
  Serial.println(" degrees");
 
 
 
  delay(100);
 
 
 
 
 
}
 

Latest revision as of 15:16, 3 March 2012

Authors: Jack Maseberg

Arduino Uno code file: File:Kinect bot.ino


Install CodeBlocks 10.05 WITH mingw (gcc)
Install openFrameworks (http://www.openframeworks.cc/download/)
Read the openFrameworks "setup guide" for your OS and add the extra include and library files to your CodeBlocks install.
Create a "myApps" folder in "of_preRelease_v007_win_cb\apps"
Copy the serialExample folder from "of_preRelease_v007_win_cb\apps\examples" into your "myApps" folder.
Open the "serialExample.workspace" file in CodeBlocks and click to expand the "src" folder. You can double click on each of the three files (main.cpp, testApp.cpp, and testApp.h) and start modifying them! On windows, we had to change the serial.setup line to be: serial.setup("\\\\.\\COM17", 115200); in the testApp.cpp file to connect to our Arduino using Bluetooth!

Kinect: use git: git clone git://github.com/ofTheo/ofxKinect.git

Following the instructions here: https://github.com/ofTheo/ofxKinect

Put the ofxKinect folder in your of_preRelease_v007_win_cb\addons folder and copy the example folder inside of the ofxKinect folder to your of_preRelease_v007_win_cb\apps\myApps folder. Before you run anything plug your Kinect in and update/install drivers found in the of_preRelease_v007_win_cb\addons\ofxKinect\libs\libusb\win\inf folder. Then you can run the example ofxKinectExample_win.workspace file!


Kinect: LPF-00004 (has usb and external power adapter) ($145)
Arduino Uno http://www.mouser.com/ProductDetail/Arduino/A000066/?qs=sGAEpiMZZMtE4ePzUE8d2JuFIVM5Ac0l ($25)
Motor Driver Sheild http://store.nkcelectronics.com/freeduino-arduino-motor-control-shield-kit.html ($11)
Aluminum standoffs: http://www.mcmaster.com 93505A102 ($0.44x8 = $3.52)
Motors: Mini Metal Gearmotor 100:1 http://www.sparkfun.com/products/8912 ($13x2 = 26$)
Wheels: Wheel 32x7mm (7mm D shaft) http://www.sparkfun.com/products/8901 ($7 for pair)
Battery: Polymer Lithium Ion Battery - 1000mAh 7.4v http://www.sparkfun.com/products/10472 ($7) (this will run the bot for about 1 hour)
Battery Charger: "iMax B6 Balance Charger" Li-Ion/Polymer Battery Charger/Balancer - 50W, 5A http://www.sparkfun.com/products/10473 ($33) (use NiMH setting when battery is too low to charge with Li2S setting)
Digital Compass HMC6352 http://www.sparkfun.com/products/7915 ($35)
Bluetooth Modem BlueSMiRF Silver http://www.sparkfun.com/products/10269 ($40)
Total Materials Cost ~ $333 plus shipping!


Uno schematic: Uno schem.png


H-bridge schematic: Hbridge.png