Jump to content


Photo

modifying funduino robot code for project.


  • Please log in to reply
25 replies to this topic

#21 Si_Price

Si_Price

    Member

  • Members
  • PipPip
  • 15 posts

Posted 11 March 2015 - 12:11 PM

Also with the original code if I wanted to add a stop sequence before the robot turns after reading the distance sensor and turning left will this work?

 {
            // turn left
            
            rightMotor.write(90);
            leftMotor.write(90);
            
            delay (5000);
            
            
            rightMotor.write(180);
            leftMotor.write(180);
        }

The servo motors are quite noisy when they're running and this is for a sound art installation so I thought it would be useful to have pauses of silence so the audience can hear the composition, the only problem is when I have tried stopping the servo's in the past one still turns? it's like discharging voltage still or its receiving voltage from somewhere else (because it turns really slow).

 

Sorry to keep bombarding you with questions!


  • 0

#22 Nathan House

Nathan House

    Administrator

  • Administrators
  • 122 posts
  • LocationLynchburg, VA

Posted 12 March 2015 - 06:00 PM

Glancing at your program, one big problem that I see is this code:

digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second

You have the delay function blocking for two seconds in that code, which means the rest of the code doesn't get to run during that time. Try removing that code and see if the program works. If you want to flash an LED at a constant time interval, then you'll need to do it the same way the debugOutput() function works (check how much time has elapsed, and based on that toggle the LED).

 

 

Also with the original code if I wanted to add a stop sequence before the robot turns after reading the distance sensor and turning left will this work?

 

Yep, that would work perfectly. Just keep in mind that the delay() function is "blocking," which means none of the code elsewhere in the program is run until the delay() function is done executing. In this case, if you just want to make the robot stop and do nothing for five seconds, then it will work fine.

 

 

the only problem is when I have tried stopping the servo's in the past one still turns? it's like discharging voltage still or its receiving voltage from somewhere else (because it turns really slow).

 

The servo that is still turning when you set it to neutral (sending it 90) needs to be tuned. If you look at the side of the servo you will see a small hole with a screw inside it. When the servo is set to neutral, slowly turn the screw until it stops moving.

 

 

Sorry to keep bombarding you with questions!

 

No problem! It will take some effort, but I'm sure you can get this working over the next two weeks if you're willing to put time into debugging the program. As I mentioned before, the best way to debug an Arduino program is to put Serial.println() statements in strategic places so that you can read the output in the serial monitor and see exactly how the program is executing.


  • 0

#23 Si_Price

Si_Price

    Member

  • Members
  • PipPip
  • 15 posts

Posted 12 March 2015 - 07:03 PM

Yeah I think what I'm going to do is use your default robot code with a few modifications (LED light, stop delay) as a contingency in case I can't debug the code I've been trying to write, i've got a ton of other things on the project to work on at the same time (I'm writing the Max code as I type this)  so it'd be good to have a backup!


  • 0

#24 Si_Price

Si_Price

    Member

  • Members
  • PipPip
  • 15 posts

Posted 16 March 2015 - 11:48 AM

Hi Nathan, how do you change the distance at which the ultrasonic sensor works, my robot flips itself when it gets into corners?


  • 0

#25 Nathan House

Nathan House

    Administrator

  • Administrators
  • 122 posts
  • LocationLynchburg, VA

Posted 16 March 2015 - 01:08 PM

Hi Nathan, how do you change the distance at which the ultrasonic sensor works, my robot flips itself when it gets into corners?

 

You mean the distance at which it changes from the drive forward to the turn left state? That would be this code:

if(ultrasonic2Distance > 0 && ultrasonic2Distance < 6) { // there's an object in front of us

That code is saying to go into the IF statement if the distance measured is 6. Making that number smaller means the robot will have to get closer to the object before branching, making the number larger means it will branch sooner.


  • 0

#26 Si_Price

Si_Price

    Member

  • Members
  • PipPip
  • 15 posts

Posted 16 March 2015 - 04:54 PM

You mean the distance at which it changes from the drive forward to the turn left state? That would be this code:

if(ultrasonic2Distance > 0 && ultrasonic2Distance < 6) { // there's an object in front of us

That code is saying to go into the IF statement if the distance measured is 6. Making that number smaller means the robot will have to get closer to the object before branching, making the number larger means it will branch sooner.

 

Ah okay thanks, I tried increasing it but my robot still manages to flip himself sometimes, I think it's because of the angle he approaches the wall and the radius of the distance sensor only reading from the front. I have managed to implement the flashing LED and the stop sequence though so that's something! thanks :)


  • 1




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users