Mini Bowling Alley ...
 
Notifications
Clear all

Mini Bowling Alley Pin Setter coding project In need of tutoring...

169 Posts
7 Users
4 Likes
40.2 K Views
Dundervetter
(@dundervetter)
Member
Joined: 4 years ago
Posts: 75
Topic starter  
Posted by: @casey

pwm.writeMicroseconds(8, 1656);
is actually doing?  Does it turn the motor a fixed amount of time?

I am sorry for the long post here... just trying to tell the whole story...

ok so I got that from the Adafruit library...

◆ writeMicroseconds()

void Adafruit_PWMServoDriver::writeMicroseconds ( uint8_t  num,
    uint16_t  Microseconds 
  )    

Sets the PWM output of one of the PCA9685 pins based on the input microseconds, output is not precise.

Parameters
num One of the PWM output pins, from 0 to 15
Microseconds The number of Microseconds to turn the PWM output ON

so using microseconds has worked for me to map the location of where I want to start and stop each servo, even the small sg90 turning the scissor mechanism.

I got those numbers from using the HJ controllers.

I used this code here and it seems to work pretty accurately controlling the motorC to raise and lower the pinsetter:

 

#include <Servo.h> 

Servo myservoC;

void setup() 
{ 
  myservoC.attach(9);
  myservoC.writeMicroseconds(1655);
  delay(5000);
  myservoC.writeMicroseconds(1178);
  delay(5000);
  myservoC.writeMicroseconds(1655);
} 

void loop() {}
Posted by: @casey

Sequence:
1 Sweeper down.
2 Pin setter down.
3 Grasp pins.
4 Pin setter up.
5 Sweeper moves across and back.
6 Pin setter down.
7 Ungrasp pins.
8 Pin setter up.
9 Sweeper up.

So I think you got this from the video I embeded... so that I guess is only a small snap shot below I will list all of the desired steps...

so to clarify I really am trying to figure out how to do these three what I would call "trigger points" I have pointed them out below... I was just thinking I was going to need "if statements" sort of nested one after another ... plus really wasn't sure if I needed a debounce for first button press or not (I was trying to figure out how to incorporate that via Arduino's website, into what I had at top of my void loop and was having a hard time decipher how write in there... Plus using Adafruit's tutorial for the IR Beam Bream, I was having a hard transitioning that to my situation too... if you look at my code I commented them beam break stuff out... I was trying...

1

Would like to have a momentary switch here to trigger the actual setting down of the pins

This trigger

2

Servo C & A (full of pins) Down

 

3

Delay 5000ms (delays are here for travel time)

 

4

Servo D spins open (pins drop)

 

5

Delay

 

6

Servo C up and Servo A up same time

 

7

Delay

 

8

Ball Rolls Past IR Beam Break sensor to trigger the next sequence (picking up the pins clearing the downed pins and placing back down the remaining pins setting up for the spare bowl/roll)

This trigger

9

2000ms  delay

 

10

Servo A Down

 

11

Delay

 

12

Servo C Down

 

13

Delay

 

14

Servo D Spin (close to grab pins)

 

15

Delay

 

16

Servo C Up

 

17

Delay

 

18

Servo B Back

 

19

Delay 500ms

 

20

Servo B Front

 

21

Delay

 

22

Servo C Down

 

23

Delay

 

24

Servo D Spin (open to drop pins)

 

25

Delay 500ms

 

26

Servo C Up

 

27

Delay

 

28

Servo A Up

 

29

Delay

 

30

Ball Rolls Past IR Beam Break sensor to trigger the next sequence this then triggers the final clean up after spare sequence)

This trigger

31

Servo A Down

 

32

Delay

 

33

Servo B Back

 

34

Delay 500ms

 

35

Servo B Front

 

36

Delay

 

37

Servo A Up

 

38

Servo D Spin (close) in order to prepare to be refilled by me, by hand

 

39

Then this need Needs to loop back in order to restart sequence and the wait for the button press to start it all over again

image

   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
 

So it is unclear to me if the code you have posted does anything at all?

Have you tried working with one servo first such as this from,

https://howtomechatronics.com/how-it-works/how-servo-motors-work-how-to-control-servos-using-arduino/

 

/*
     Servo Motor Control using the Arduino Servo Library
           by Dejan,  https://howtomechatronics.com 
*/
#include <Servo.h>
Servo myservo;  // create servo object to control a servo
void setup() {
  myservo.attach(9,600,2300);  // (pin, min, max)
}
void loop() {
  myservo.write(0);  // tell servo to go to a particular angle
  delay(1000);
  
  myservo.write(90);              
  delay(500); 
  
  myservo.write(135);              
  delay(500);
  
  myservo.write(180);              
  delay(1500);                     
}

 


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
 

   
ReplyQuote
(@zeferby)
Member
Joined: 5 years ago
Posts: 355
 

Hi there !

(trying to catch up, haven't been on the forum for 2 days)

I'm wondering if this code should be implemented as a finite state machine ?

I'll copy the code to study it.

Eric


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
 

   
ReplyQuote
Robo Pi
(@robo-pi)
Robotics Engineer
Joined: 5 years ago
Posts: 1669
 

DroneBot Workshop Robotics Engineer
James


   
ReplyQuote
Robo Pi
(@robo-pi)
Robotics Engineer
Joined: 5 years ago
Posts: 1669
 

@dundervetter

Steve @pugwash also suggested the same thing and even included the if statements for you.  He also broke the program up into methods to be called instead of putting everything in a single loop.  Either way will work since you only call each method a single time anyway.   It's a little neater to break it up into separate function calls.  But in this case nothing is saved since you only do each routine once per run anyway.  But it would probably be good for you to learn how to create named functions and call them from the main program.  It makes coding a lot more organized and easier to read.

DroneBot Workshop Robotics Engineer
James


   
ReplyQuote
Robo Pi
(@robo-pi)
Robotics Engineer
Joined: 5 years ago
Posts: 1669
 

@dundervetter

Jason,  By the way, when writing code always include comments of what the code is actually doing as Steve did in his example.   It helps others to better understand what the program is actually doing.   To just say that a servo is moving for a given time doesn't mean anything to someone who doesn't know what the servo is actually doing.

DroneBot Workshop Robotics Engineer
James


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
 

@robo-pi

Steve @pugwash also suggested the same thing and even included the if statements for you.

It may be just me, but I like to keep procedural code separate from the logic code. It makes it a lot easier to debug! And I believe that even beginners should be taught good practice.

Unfortunately, you have commented on @dundervetter 's first code offering, which was superseded by another sketch, where the objects have been correctly declared in post-#9104.

Also unfortunate is, that he has two threads going on the same subject. Most confusing ? ? ? 


   
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1037
 

Guys I'm going to back off for now as we seem to have a bunch of people helping Jason figure out a solution and I don't want to add any confusion.

I haven't used any servos like the ones for A, B, and C in Jason's design, so I'm having trouble understanding how just sending a command to move the servo for a particular amount of time handles changing direction.  Wouldn't you have to have something that controls direction?  If I'm confused then I'm surely going to add to the confusion.  I will continue to monitor the thread so that I can learn something myself.

SteveG


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
 

   
ReplyQuote
Robo Pi
(@robo-pi)
Robotics Engineer
Joined: 5 years ago
Posts: 1669
 

@dundervetter

Jason, just as an engineering comment:

Using timing delays will work as long as everything goes as expected.  However, if something is prevented from completing its task within the allotted time this can throw the whole system  out of whack.  This may not be a problem if someone is there to fix it.  But this problem of being out of sync would not fix itself and could only get worse if the system is continued to be used.

A better way would be to have sensors (or limit switches) that indicate every action as it is completed.  Then in your code you can also include timing counters.  If a limit switch isn't activated within a reasonable amount of time, you can have the whole system shut down and signal that something went wrong.

DroneBot Workshop Robotics Engineer
James


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
 

@codecage

I had to read the Adafruit site and look at some code to find out how this works. It is not as straightforward as the <servo.h> library, due to I2C involvement.


   
ReplyQuote
(@pugwash)
Sorcerers' Apprentice
Joined: 5 years ago
Posts: 923
 
Posted by: @robo-pi

@dundervetter

Jason, just as an engineering comment:

Using timing delays will work as long as everything goes as expected.  However, if something is prevented from completing its task within the allotted time this can throw the whole system  out of whack.  This may not be a problem if someone is there to fix it.  But this problem of being out of sync would not fix itself and could only get worse if the system is continued to be used.

A better way would be to have sensors (or limit switches) that indicate every action as it is completed.  Then in your code you can also include timing counters.  If a limit switch isn't activated within a reasonable amount of time, you can have the whole system shut down and signal that something went wrong.

I was thinking that the same could be achieved in code by having a boolean variable that goes "true" when the task is completed or calls while(1) to halt the program entirely. The next task is only called if the variable is true. Which would be cheaper than more sensors!


   
ReplyQuote
Robo Pi
(@robo-pi)
Robotics Engineer
Joined: 5 years ago
Posts: 1669
 
Posted by: @pugwash

I was thinking that the same could be achieved in code by having a boolean variable that goes "true" when the task is completed or calls while(1) to halt the program entirely. The next task is only called if the variable is true. Which would be cheaper than more sensors!

But without sensors how is the boolean variable going to know that a task was completed?

DroneBot Workshop Robotics Engineer
James


   
ReplyQuote
Page 2 / 12