Saturday, December 14, 2013

Coding is so fun.

SO for Mr. Marvin I was able to get both components working.

 Unfortunately I was not able to get them to work together.
 So I was able to get the trigger and sound fx working, and the motors to work with code, but couldn't get them in unison.

 Here is the very simple code that was used to move Marvin. (note: a separate Adafruit library has to be installed in order for it to work.)


#include <AFMotor.h>

AF_DCMotor motor3(3, MOTOR34_64KHZ); // create motor #3, 64KHz pwm

AF_DCMotor motor4(4, MOTOR34_64KHZ); // create motor #3, 64KHz pwm


void setup()
{
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Motor test!");
 
  motor3.setSpeed(200);     // set the speed to 200/255
  motor4.setSpeed(200);     // set the speed to 200/255
}

void loop()
{
  Serial.print("tick");
 
  motor3.run(FORWARD);      // turn it on going forward
  motor4.run(FORWARD);      // turn it on going forward
  delay(1100);

 Serial.print("tack");
  motor3.run(RELEASE);      // stopped
  motor4.run(RELEASE);      // stopped
  delay(1000);

  Serial.print("tock");
  motor3.run(BACKWARD);     // the other way
  motor4.run(BACKWARD);     // the other way
  delay(1000);
 
  Serial.print("tack");
  motor3.run(RELEASE);      // stopped
  motor4.run(RELEASE);      // stopped
  delay(1000);
}





 This is the code that was written for 'everything' and it was very quickly garbage because the motor controller that we used didnt follow the Arduino format at all. And thats OK, you win some and lose others.



int valm=0;
int valm1=0;
int trigger=0;
int triggerlock=0;
const int pwmA=3;
const int pwmB=11;
const int brakeA=9;
const int brakeB=8;
const int dirA=12;
const int dirB=13;
const int relay=2;




void setup()

{
pinMode(relay, OUTPUT);

digitalWrite(relay, HIGH);

delay(500);//leave relay on .5 second--makes "eek" sound
digitalWrite(relay, LOW);
}


void loop()

{

    trigger=analogRead(3);
    if(trigger<500 or triggerlock>0) {//light shining on sensor now or previously
   
      triggerlock=100;//don't check light again
   
   
  pinMode(dirA, OUTPUT);
  pinMode(brakeA, OUTPUT);
 
  pinMode(dirB, OUTPUT);
  pinMode(brakeB, OUTPUT);
 
  digitalWrite(dirA, HIGH);//forward A
  digitalWrite(brakeA, LOW);//release brake A
  analogWrite(pwmA, 150);//set speed A
 
  digitalWrite(dirB, HIGH);//forward B motor
  digitalWrite(brakeB, LOW);
  analogWrite(pwmB, 150);//set speed B
 


valm=analogRead(0);
valm1=analogRead(1);
if(valm>520 or valm1>520)

{

      digitalWrite(relay, HIGH);//turn on "eek" sound
      delay(100);
      digitalWrite(relay, LOW);
      digitalWrite(brakeA, HIGH);//stop motor A
      digitalWrite(brakeB, HIGH);//stop Motor B
     
      digitalWrite(dirA, LOW);//reverse A
      digitalWrite(brakeA, LOW);//release brake A
      analogWrite(pwmA, 150);//set speed A
     
      digitalWrite(dirB, LOW);//reverse B
      digitalWrite(brakeB, LOW);
      analogWrite(pwmB, 150);//set speed B
     
      delay(300);
     
      digitalWrite(brakeA, HIGH);//stop one wheel
     
      delay(400);
      digitalWrite(brakeB, HIGH);//stop other wheel



    //start both wheels forward
    digitalWrite(dirA, HIGH);//forward A
    digitalWrite(brakeA, LOW);//release brake A
    analogWrite(pwmA, 150);//set speed A
   
    digitalWrite(dirB, HIGH);//forward B
    digitalWrite(brakeB, LOW);
    analogWrite(pwmB, 150);//set speed B
   
    delay(700);//get past startup current

}
}
}

Friday, December 13, 2013

12/13/2013 Update

After trying several different ways to get our mechanism to start running properly, we realized that we couldn't using the materials that we had. The 6V battery that we have was not enough to power the circuit. Given more time, we would trade that for a higher voltage battery. Also, the motor shield that we got did not have the sensing capabilities that we wished for, so if we were to do this again, we would have gotten a better motor shield. Under these circumstances, we were only able to get one part of our circuit running at a time. For our project, we were hoping to get a light sensor to turn on the recording module and to turn on the motor to get the RC car running. With the battery we had, we were unable to get both parts running. In other words, we could have gotten the photosensor to turn on the recording module, or we could have used the power to get the car moving, but not both at the same time.

However, here are some photos of the assembled project and a video of the car moving:






Wednesday, December 11, 2013

Almost There..

On Monday, the build began. We finished all sub-assemblies by soldering the batteries and needed wires to control sensors, motors, and recording module. After many attempts, we finalized the segment of song that will play when the box begins to move. The motor shield is attached to the Arduino board and the schematic for the motor shield is followed when wiring the project together. The frame that was 3D printed was attached to the R/C car with screws. The outside “Christmas present” was designed and manufactured then wrapped with Christmas paper.  This was made out of an old poster board and will rest on top of the laser printed part to be able to cover the whole R/C car. The whole project has been set up and functions. We still run into a problem with the sensor not stopping the program on the board. We have started the paper for our project. 

Friday, December 6, 2013

PARTs, parts, partS.

So as from the title you can see that some parts have come in.

Here's how they came out.


These are all the parts.


This is used to keep the battery in place.


This in the 3-D Printed superstructure. Looks awesome btw.

And this is the base plate that all the electronics are going on, 
But it also serves as the top of the box.

Monday, November 25, 2013

11-25 Fine Tuning

In our lab time, the group worked on tweaking the arduino code and finalizing our parts to be submitted. Erek and Jeannie added some final details to make the frame of our present to make sure the frame can withstand the car running into a wall if the sensor does not work properly. The laser printed material was also designed. Tyler and Kari-Ann attempted to make the arduino work when the light is on the sensor rather than when the sensor is covered. We spent the whole time digging through the arduino forums to try to find some help. We also took part in making our blog functional with pictures and videos embedded into the blog.

11/17/2013 Arduino Update

Our group met to publish our code onto GitHub and upload the code onto an arduino. After figuring out the Github website, the code was uploaded and few errors were fixed. The group then added comments to tell what the arduino is going to do.


analogRead(2) //values determine the trigger point for the photocell.
 analogRead(0) and analogRead(1) //values determine the current which will cause the Arduino to think the package has hit an obstacle.  If you run on carpet, the values may need to be higher.  If you run the motors faster, the value may need to be higher.
 
//Note that the "startup current" on motors is greater than the "run" current--that's why there is a delay on forward before checking the current values.
 


int valm=0;
 int valm1=0;
 int trigger=0;
 int triggerlock=0;
 const int pwmA=3;
 const int pwmB=11;
 const int brakeA=9;
 const int brakeB=8;
 const int dirA=12;
 const int dirB=13;
 const int relay=7;
 
void setup() {
 

pinMode(relay, OUTPUT);
 

digitalWrite(relay, HIGH);
 
delay(2000);//leave relay on 2 seconds to play song
 digitalWrite(relay, LOW);
 }
 
void loop() {
  
   trigger=analogRead(2);
   if(trigger<900 or triggerlock>0) {//light shining on sensor now or previously
    
     triggerlock=10;//don't check light again
   
    
     pinMode(dirA, OUTPUT);
 pinMode(brakeA, OUTPUT);
 
pinMode(dirB, OUTPUT);
 pinMode(brakeB, OUTPUT);
 
digitalWrite(dirA, HIGH);//forward A
 digitalWrite(brakeA, LOW);//release brake A
 analogWrite(pwmA, 150);//set speed A
 
digitalWrite(dirB, HIGH);//forward B motor
 digitalWrite(brakeB, LOW);
 analogWrite(pwmB, 150);//set speed B
 


valm=analogRead(0);
 valm1=analogRead(1);
 if(valm>520 or valm1>520) {
  
 digitalWrite(relay, HIGH);//turn on sound
 delay(100);
 digitalWrite(relay, LOW);
 digitalWrite(brakeA, HIGH);//stop motor A
 digitalWrite(brakeB, HIGH);//stop Motor B
 
digitalWrite(dirA, LOW);//reverse A
 digitalWrite(brakeA, LOW);//release brake A
 analogWrite(pwmA, 150);//set speed A
 
digitalWrite(dirB, LOW);//reverse B
 digitalWrite(brakeB, LOW);
 analogWrite(pwmB, 150);//set speed B
 
delay(300);
 
digitalWrite(brakeA, HIGH);//stop one wheel
 
delay(400);
 digitalWrite(brakeB, HIGH);//stop other wheel
 


//start both wheels forward
 digitalWrite(dirA, HIGH);//forward A
 digitalWrite(brakeA, LOW);//release brake A
 analogWrite(pwmA, 150);//set speed A
 
digitalWrite(dirB, HIGH);//forward B
 digitalWrite(brakeB, LOW);
 analogWrite(pwmB, 150);//set speed B
 
delay(700);//get past startup current
 
}}}




Our program successfully can get the recording module to work with the photosensor. Our problem is that it plays when the light is off of the sensor. We then decided to begin working on the frame design while we wait for our pieces to be mailed to us.

11/19/2013 Part Update

Today we started designing the Solidworks part that will be 3D printed based off of our sketches that we drew yesterday. Erek and Tyler took the dimensions from the RC car and determined the overall size of the frame that we are building. KariAnn began the part creation using Solidworks and after that, Erek and Jeannie completed the part, changing the design slightly. The final part after 11/19/2013 is posted below:

 


 


The part has some flaws. Although the measurements are pretty good, the measurements will be retaken next week just to double-check. The part was hollowed out, although this may not be the best method as the structure may be too weak so we will have to rethink what we will do about the volume/overall structure.