Simultaneous possible?

So I have a robot project where it needs to drive around and pick up golf balls. The idea my team and I came up with is to use arms to push the balls when a sensor on the arm detects the robot. We are going to use a servo to control both arms by gear system. My question is while its driving forward and detects a ball, is there a way to keep driving forward while the servo arm sweeps the ball into a collector?

Thanks.

Yes.
I don't see the problem. Start the motors, the robot moves forward and does not need intervention from the Arduino to keep it going.
Now do anything you like with the Arduino.

You say that the robot will drive around. How will it know which way to go, when to turn and when to stop going forward because of an obstacle that is not a golf ball ?

You might look to simpler solutions with fewer parts. Final manufacture cost includes every part and everything that has to be done to it to build the solution.

Have you ever seen PacMan?

Yes it's possible, but note that the Servo library disables PWM output on some pins and some motor shields use those same pins to provide PWM speed control. If you want to use both in the same project, make sure your motor shield doesn't clash with the Servo library.

UKHeliBob:
Yes.
I don't see the problem. Start the motors, the robot moves forward and does not need intervention from the Arduino to keep it going.
Now do anything you like with the Arduino.

You say that the robot will drive around. How will it know which way to go, when to turn and when to stop going forward because of an obstacle that is not a golf ball ?

Basically the robot is just going in a square path. Id like to have a counter within the program that will turn the robot a certain counts since there is a set number of balls placed. So for example when the counter hits 3 it knows to stop and turn 90 degrees and continue to drive and collect til another number is reached then stop and turn, etc. The golf balls are placed at the same place for every trial run so it wont need to know to turn at different places.

GoForSmoke: Not really sure what your talking about? If you mean using the one servo to control both arms, the purpose for that is to free up ports on the arduino for other needed sensors.

PeterH: Thanks for the information. I have the arduino brand motor board rev 3, do you know if that will interfere? I am new to arduino and tried looking into libraries but from what I can see they are basically programs that act kind of like functions for scripts. Not sure what the servo library even does? If you have any information that would be great

Thanks everyone.

Turning the robot after a certain count or time is no problem. What will be a problem unless you have a means to control it is keeping it moving straight and turning 90 degrees when required.

Have you got any code written, even if it is only to turn a motor on and off ?

UKHeliBob:
Turning the robot after a certain count or time is no problem. What will be a problem unless you have a means to control it is keeping it moving straight and turning 90 degrees when required.

Have you got any code written, even if it is only to turn a motor on and off ?

There is a golf ball at each corner of the square path the robot needs to go around so when it senses the ball and the counter reaches a certain number then itll turn.

The coding I did was

#include <Servo.h>
Servo servoOne; // Define Servo

void setup() {
  
  //Setup Channel A
  pinMode(12, OUTPUT); //Initiates Motor Channel A pin
  pinMode(9, OUTPUT); //Initiates Brake Channel A pin

  //Setup Channel B
  pinMode(13, OUTPUT); //Initiates Motor Channel A pin
  pinMode(8, OUTPUT);  //Initiates Brake Channel A pin
  
  int ballsensor = 1 //Ball Sensor
  pinMode(ballsensor,INPUT); //Ball Sensor on pin 1
  servoOne.attach(10); // Servo on pin 10
}

b=0;

servoOne.write(45); // Turn Servo Left to 45 degrees


while(b<3){
  //Motor A forward @ full speed
  digitalWrite(12, HIGH); //Establishes forward direction
  digitalWrite(9, LOW);   //Disengage the Brake
  analogWrite(3, 255);   //Spins the motor at full speed

  //Motor B backward @ half speed
  digitalWrite(13, HIGH);  //Establishes forward direction
  digitalWrite(8, LOW);   //Disengage the Brake
  analogWrite(11, 255);    //Spins the motor at full speed

if (ballsensor=1){ //If ball is sensed, b increases by 1

servoOnen.write(90); // Turn Servo to center position (90 degrees)
servoOnen.write(45); //Turn Servo to 45 degrees

++b              //Increases b by 1

}}

while (b==3){
    //Motor A brake
  digitalWrite(12, LOW); //Stops forward direction
  digitalWrite(9, HIGH);   //Engages the Brake
  analogWrite(3, 0);   //Stops the motor

  //Motor B brake
  digitalWrite(13, LOW);  //Stops forward direction
  digitalWrite(8, HIGH);   //Engages the Brake
  analogWrite(11, 0);    //Stops the motor

I have no idea if this will work since we havent had the change to hook any motors or sensors up yet, but this is the hopefully beginning of the coding. I looked around to find coding and based whats written off of that so not sure if this will sync up or what but theres the start.

use the code tags when posting code!

You can't use Servo with a standard motor shield (they both try to make use of the timer on pin 9).

Mark

holmes4:
use the code tags when posting code!

You can't use Servo with a standard motor shield (they both try to make use of the timer on pin 9).

Mark

Didnt realize, modified my post. Anyway, so I just cant use the servo library then? What exactly does that library do? Is there any special coding I will have to include to make servos work correctly?

Thanks

mwebby93:
There is a golf ball at each corner of the square path the robot needs to go around so when it senses the ball and the counter reaches a certain number then itll turn.

The question still remains, how are you going to ensure that it runs straight and turns 90 degrees ?

I have no idea if this will work since we havent had the change to hook any motors or sensors up yet,

That doesn't mean that you couldn't have at least tried to compile it. That would alleviate any concern about whether it would run, or not.

}}

Don't come back with code like this. Each } goes on its own line. I prefer each { on a new line, too. And you definitely need to learn about Tools + Auto Format.

It won't compile anyway because the code posted comes to an abrupt end like this

  //Motor B brake
  digitalWrite(13, LOW);  //Stops forward direction
  digitalWrite(8, HIGH);   //Engages the Brake
  analogWrite(11, 0);    //Stops the motor

UKHeliBob:
It won't compile anyway because the code posted comes to an abrupt end like this

  //Motor B brake

digitalWrite(13, LOW);  //Stops forward direction
 digitalWrite(8, HIGH);   //Engages the Brake
 analogWrite(11, 0);    //Stops the motor

I am in the middle of writing up some of the coding, I havent finished which is why it stops there.

UKHeliBob: The track we have to run on doesn't have a line for it to follow and get the outside balls.


I . . . I
I . I
I _ I
I .---.---I_I---.---. I
I I
I . I
I . . . I
I___________________I

Hard to show but each . is a golf ball. The only lines are a cross horizontal and vertical intersecting through the box in the middle. I didnt put in the vertical line but it is in the middle of the track where the four . are lined up vertical.

The one idea we had was to have two distance sensors on one side of the robot (front and back) that is closest to the outside wall of the track and if they are the same value the wheels spin the same speed. If one is greater than the other then the wheels spin different speeds to correct it then continue at the same speed when the distance is the same again.

Any input or opinion of that idea would be greatly appreciated.

Thanks for everyones help so far. I am very new to the arduino coding. The only background I have is a digital electronics class where we used the board of education. But then again we only had little time with the board doing some very basic programs.

Using the outer walls to provide a distance measurement and keeping the robot parallel to them sounds like it could work.

Is the objective to collect as many/all of the golf balls in the shortest possible time or something else ? Using the vertical and horizontal lines would allow you to collect 8 of the balls using a line follower and the distance of the outer balls on the lines indicates the distance to maintain away from the wall to get the other 4.

What you need to do is to work out the shortest path for the robot to travel to collect all the balls using the lines and the walls as reference points. What sort of size is the pattern and how big will your robot be ?

UKHeliBob:
Using the outer walls to provide a distance measurement and keeping the robot parallel to them sounds like it could work.

Is the objective to collect as many/all of the golf balls in the shortest possible time or something else ? Using the vertical and horizontal lines would allow you to collect 8 of the balls using a line follower and the distance of the outer balls on the lines indicates the distance to maintain away from the wall to get the other 4.

What you need to do is to work out the shortest path for the robot to travel to collect all the balls using the lines and the walls as reference points. What sort of size is the pattern and how big will your robot be ?

The design that my team has come up with involves driving down the middle of the balls and collecting the balls on each side of the bot at the same time. Basically you have 8 balls on a large outside square and 4 on the inside, smalled square. Our idea is to have the robot do a path in the middle of these two squares and when it senses a ball on the outside arm (on the "large square") it will swing both arms on each side to collect any balls there.

The track is 8'x8' with the outside perimeter of the 8 golf balls 16" from the outside wall. The balls on the out most "square" are spaced 36" apart and the balls that line up on the lines are 16" apart. We have already designed how to collect the balls on one trip around the track. Our robot is 7.5" wide before the arms swing out. Once they swing out, it will have a "wing span" of about 18". Provided the wall sensor(s) mounted on the chassis of the robot, it would have to read the wall from about 20" away.

Our task is to collect all 12 balls and deposit them in the middle box under a minute. Our goal is to do this in under 30 seconds. We think it can be done a lot quicker but that is the goal we have set for now. Its the reason that we are trying to collect all of the balls on one trip around so its quicker and less travel the robot would need to do.

*edit: the robot's dimensions are 11.5" long x 7.5" wide which is set by the design we have and then the height can be up to 10" but with our design to get the balls into the center box we will have a chassis plate about 4" high and then another, smaller, plate at about 7" high that will hold the micro controller and circuits.

BTW, the outside walls and center box are made from 2x4s