Tuesday, December 24, 2013

IR Remote Demonstration

Final code used:
/*
* IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
* An IR detector/demodulator must be connected to the input RECV_PIN.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* http://arcfn.com
*/
//IR code:
#include <IRremote.h>
const int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

//Servo Code
#include <Servo.h>
Servo servoA;
Servo servoB;
//const int servospeedA = 81 /*Check value */; //roughly mid value in 0-180 should be no motion
//const int servospeedB = 86 /*Check value */; //roughly mid value in 0-180 should be no motion

void setup()
{
  Serial.begin(9600);
//Servo Code:
servoA.attach(9);
servoB.attach(10);
//servoA.write(81);
//servoB.write(85);

//IR Code:
  irrecv.enableIRIn(); // Start the receiver
}//end void setup

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }
//Servo code:
  if(results.value == 551485695){
    servoA.write(81);
    delay(100);
    servoA.write(0);
    delay(50);
  }
  if(results.value == 551518335){
  servoA.write(81);
  delay(100);
  servoA.write(180);
  delay(50);
  }
  if(results.value == 551499975){
  servoA.write(81);
  }
  
  if(results.value == 551502015){
  servoB.write(90);
  delay(100);
  servoB.write(0);
  delay(50);
  }
  if(results.value == 551534655){
  servoB.write(90);
  delay(100);
  servoB.write(180);
  delay(50);
  }
  if(results.value == 551506605){
  servoB.write(90);
  }
  //end if statement
/*if("(channel down) IR value is min"){
  servoA.write(0);
}//end if statement
 else(servoA.write(81));
  if statements controlling the motorspeeds need specifics on how to obtain high or low
 (up or down channel or volume signal) in order to write forward or backward speed to servo
 correctly. 

if("(volume up) IR value is max"){
  servoB.write(180);
}//end if statement
if("(volume down) IR value is min"){
  servoB.write(0);
}//end if statement
 else(servoB.write(86));
  */
}//end void loop

Wednesday, December 18, 2013

Sunday, December 15, 2013

Personal summary.
My main goal for the project was working on the physical parts. I created the chase out of k'nex and eventually reworked it 2 additional time. I did the solidworks for the tank track and with help from kevin made the gear in solidworks as well. I created the suspension out of legos and springs which I hot glued to the chase. Lastly I did the physical modifications to the servos to make them continous and mounted them and the ardunio to the chasy.
-Brendan McGonagle
Personal Summary

I purchased the servo motors and helped solve for the needed dimensions of the two driving gears for either tank tread chain. Additionally, I tested the servo motors once their potentiometers had been glued in roughly the middle of the 0 to 180 degree range. Using a potentiometer from the sparkfun kit, the degree value which became the middle of the range (0 rotational speed) was found and noted. Also, the IR sensor had to become functional through a few methods. The very first was obviously to download the IR library from Ken Shirriff's blog. Using some sample IR receiver code, and once the IR sensor had been plugged in correctly, the serial monitor which printed out what the IR sensor received from the TV remote revealed some combinations of numbers and letters. Through some help, we found out that the sensor was receiving numbers in hexadecimal. In order to incorporate the signals from the remote into the code, the numbers were converted to base 10 and used in the if statements which wrote to the servos. After this had been done, it was mostly trial and error and conversion. A forward, backward, and stop button on the remote was coded for each motor on the tank.

One motor did not have a clear center point in the range, so it didn't completely stop when the mid range servo.write function was used. This will require more testing. Overall, my focus was on the coding and motors, but I did help with the design of the tank's gears and treads.

-Kevin Cerritelli

Wednesday, December 11, 2013

Update from the past couple weeks:

-potentiometers inside servo motors have been glued
-both gears and the estimated 50 individual tank treads have been sent to be printed
-lego pieces have been ordered and will arrive soon
-approximate code for the servos and IR sensor has been created
The final implementation and testing will occur tomorrow.
The IR code and Servo code has been put into the same sketch, but the part missing from the code at this point is the frequency of the IR transmitter that is being used and the way to interpret a high or low signal from a button, i.e. channel up/down. The code could view these as two separate buttons.

The two servos have had their potentiometers glued roughly in the middle of each range, and the two approximate mid-values for each have been noted. This allows for the servo.write function to write a speed to the servo rather than an angle (position).

/*
* IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
* An IR detector/demodulator must be connected to the input RECV_PIN.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* http://arcfn.com
*/
//IR code:
#include <IRremote.h>
const int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

//Servo Code
#include <Servo.h>
Servo servoA;
Servo servoB;
const int servospeedA = 81 /*Check value */; //roughly mid value in 0-180 should be no motion
const int servospeedB = 86 /*Check value */; //roughly mid value in 0-180 should be no motion

void setup()
{
  Serial.begin(9600);
//Servo Code:
servoA.attach(9);
servoB.attach(10);
servoA.write(servospeedA);
servoB.write(servospeedB);

//IR Code:
  irrecv.enableIRIn(); // Start the receiver
}//end void setup

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }
//Servo code:
if("(channel up) IR value is max"){
  servoA.write(180);
}//end if statement
if("(channel down) IR value is min"){
  servoA.write(0);
}//end if statement
 else(servoA.write(81));
 /* if statements controlling the motorspeeds need specifics on how to obtain high or low
 (up or down channel or volume signal) in order to write forward or backward speed to servo
 correctly. */

if("(volume up) IR value is max"){
  servoB.write(180);
}//end if statement
if("(volume down) IR value is min"){
  servoB.write(0);
}//end if statement
 else(servoB.write(86));
 
}//end void loop

Thursday, December 5, 2013

Tank tread design along with diameter which could vary depending on quality of print.

Designed by Brendan McGonagle

Thursday, November 21, 2013

Code Similar to what we will be using(this code has an led output rather than dual servo motor outputs):


//define pins. I used pins 4 and 5
#define irLedPin 4          // IR Led on this pin
#define irSensorPin 5       // IR sensor on this pin

int irRead(int readPin, int triggerPin); //function prototype

void setup()
{
  pinMode(irSensorPin, INPUT);
  pinMode(irLedPin, OUTPUT);
  Serial.begin(9600); 
  // prints title with ending line break 
  Serial.println("Program Starting"); 
  // wait for the long string to be sent 
  delay(100); 
}

void loop()
{  
  Serial.println(irRead(irSensorPin, irLedPin)); //display the results
  delay(10); //wait for the string to be sent
}

/******************************************************************************
 * This function can be used with a panasonic pna4602m ir sensor
 * it returns a zero if something is detected by the sensor, and a 1 otherwise
 * The function bit bangs a 38.5khZ waveform to an IR led connected to the
 * triggerPin for 1 millisecond, and then reads the IR sensor pin to see if
 * the reflected IR has been detected
 ******************************************************************************/
int irRead(int readPin, int triggerPin)
{
  int halfPeriod = 13; //one period at 38.5khZ is aproximately 26 microseconds
  int cycles = 38; //26 microseconds * 38 is more or less 1 millisecond
  int i;
  for (i=0; i <=cycles; i++)
  {
    digitalWrite(triggerPin, HIGH); 
    delayMicroseconds(halfPeriod);
    digitalWrite(triggerPin, LOW); 
    delayMicroseconds(halfPeriod - 1);     // - 1 to make up for digitaWrite overhead    
  }
  return digitalRead(readPin);
}
http://playground.arduino.cc/Main/PanasonicIrSensor
Arduino code for including and utilizing an IR sensor/IR controller

/*
* IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
* An IR detector/demodulator must be connected to the input RECV_PIN.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* http://arcfn.com
*/

#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }
}
Credit given to Ken Shirriff for creating the code.
Progress as of 11/21/13
 
 
 
Tank frame with spot for arduino board in the center.
 
Built by Brendan McGonagle using Kinects.
 
 
 Goals determined by Brendan McGonagle and Kevin Cerritelli
 
Immediate goals now that that tank frame has been built:
 
-Buying servo motors, optimally with required voltage of 4.5-6 V, since the battery voltage will be brought to 5 V using the arduino board
-Mounting the servo motors along with front driving gears and the back driven gear
-Design tank treads or buy tank treads

Thursday, November 14, 2013

Drawing by Brendan McGonagle
Top view drawing of our proposed tank design.

A is where the arduino board and breadboard will sit.
M marks the location of the two servo motors powering the treads.
On either side, the diagonal lines mark where the treads will be located.
The battery pack is shown on the opposite end of the tank structure.
The entire length of the tank is estimated to be about 10-12 in.
Current Objectives:

  • Establishing an initial structure design for:
    • the tank's frame
    • placement of breadboard/arduino board on the tank
  • Purchasing two relatively cheap motors and measuring dimensions needed for design
  • Designing mounts for the motors on either side of the vehicle
  • Generating ideas for use of 4 cubic inches of abs plastic using the 3D printer

Outline

The main goals of our project are as follows:

  • Provide controlled power to the tank treads on either side of an assembled vehicle
  • Remotely control speed, turning, and forward/backward motion using an IR sensor
In order to acheive these goals, the following challenges/design steps are expected to take place:

  • Mounting two motors on either side of the vehicle to power the treads
  • Designing/using tank treads with proper motor-driven gears to allow the vehicle to move over obstacles
  • Coding the IR sensor to receive the transmitted signals from the remote control and then causing each tread of the tank to have three states, possibly mapped over a range of values with a potentiometer.
    • Three states include: Clockwise motion, Counterclockwise motion, and no motion.
  • The middle of a range of potentiometer values mapped to motor rotation may be coded to be 0 rpm, and either end of the range of potentiometer values will be the positive and negative maximum angular velocity of the motors.