Notifications
Clear all

Questions about changing to array from buttons

111 Posts
5 Users
6 Likes
11.1 K Views
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1112
 

@robotbuilder

I think you meant to address your post to @gam, - the code post was not mine.

And while I'm here, @gam, I think you need to carefully consider what should happen when multiple tools get switched on.  I think you have it all working when you manually switch a tool on and off.

1. current is sensed on an analogue pin

2. sever is actuated to open the appropriate port.

3. vacuum is started

4. tool is switched off - no current sensed on analogue pin

5. after an appropriate delay to clear the pipes the vacuum is switched off

6. the port is closed - ready for next tool to be switched on.

But when automating all this, you have to decide and document what you want to happen if another tool is switched on

1. when the first tool is still switched on

2. when the first tool is off, but the vacuum is still on clearing the the pipes.

3. (presumable the answer to 2 above is the port will change and the vac switched on asap after completing the vac off and port off task in progress, but what if yet another tool is also switched on in the meanwhile. 

Sorting these dilemma's are vital for you code to function properly.


   
ReplyQuote
 GAM
(@gam)
Member
Joined: 3 years ago
Posts: 58
Topic starter  

@byron yes


   
ReplyQuote
 GAM
(@gam)
Member
Joined: 3 years ago
Posts: 58
Topic starter  

   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1112
 

@gam

Now I can see your code 😀.  The delay statement will halt your program until the time your delay stops and  in the meanwhile it will not loop to find if any sensors have triggered etc.  Instead of delay you need to use millis.  At random I pick a google on using milis from the raft of possible sites.

arduino-tutorial-using-millis-instead-of-delay

However I could have more to say about the structure of your code but this is pending any further input you may give on the questions I posed, and some more that are also worthy of considering like what should happen with the program if you get a power cut in the middle of moving a servo.  What should then happen on power on.  Them ruskies may hack into your power grid at any time 😎 

This post was modified 3 years ago by byron

   
ReplyQuote
 GAM
(@gam)
Member
Joined: 3 years ago
Posts: 58
Topic starter  

@byron

Good point! 

  • I just noticed it doesn't always take the shortest route (CW/CCW)
  • If going from 0 degree (holding the button down) and pressing a higher degree button it works as it should.
  • The opposite is not true. Holding the 270 degree button and hit any lower degree it tries to move to new lower position, till you let go of second button then returns.
  • On the other it is a one man shop and I'm not quick enough to get to another tool in 4 sec. But it would be nice just incase.

So I guess it's not Perfect yet!

 Still need to find Doc for that library so I can understand how to use it.


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1112
 

@gam

Well you may have had some fun looking a millis as opposed to delay which was triggered when you mentioned that when you issued a delay your sensor was not read.  But I have had a look at some of the posts and on consideration of what you are trying to do I suspect that a delay is actually more appropriate for your code than a millis. 

But it seems quite a while ago you stated this thread so before I comment on the code any further I summarise what I think the program logic you are look for is, without wading through all those back posts and code.

I think you are looking at the following logic.

1. check each current sensor until tool-on is found
 
2. when a tool-on is found then move the servo to the position appropriate to the tool that
   triggered the tool-on
 
3. when the servo has finished opened the gate issue a 'gate-opend' message
 
4. on a 'gate-opened message swich the vacuum on.
 
5  monitor the current sensor for the tool in question.
 
6  when the sensor indicates a tool-off initiate a pipe cleaning DELAY.
 
7. switch the vacuum off
 
8. move the gate to an off position ?? or just leave it where it is ?
 
And then go back to step 1
 
If another tool is switched on between steps 2 to 8 the current sensors will be ignored until the program goes back to step 1 and then the first current sensor that is found to be on will trigger the steps 2 to 8.  
 
During a tools 'tool-on' status and the program in going through steps 2 - 8 only the current sensor for that tool will be checked to see if the current for that tool is still on.  Only when the process is concluded for the tool in question will the current sensor be checked again, and then only the first current sensor to be found to be on will trigger the steps for the tool the current sensor is linked to.

Also, I not sure why you changed to another library as, apart from some issues you mentioned about trying to delay the vacuum turn off,  I thought your code was working.  Admittedly it could have done with being structured in a better way.  But the analysis proceeds the coding.  Write the program logic down in plain english to start with, it often throws up a lot of questions to be answered prior to coding and should give and indication as to the functions you need to code to achieve the goal. 

 


   
ReplyQuote
 GAM
(@gam)
Member
Joined: 3 years ago
Posts: 58
Topic starter  

@byron

Your out line is very accurate.  Number 8,  the gate remains where it is. Pretty common to use the same tool multiple times. 

Your correct that the other code was almost there except the delay which should be cured with nonblocking delay.  And correct that it wasn't the cleanest thing written. But not bad for me 😬.    My thought was, make it work then make it pretty. 

I received a reply with the library and a code to try.  Which I did and it ran right off with a few hitches.  Still needs some work and I may go back to my other code because I understood what was going on there. A lot of time invested and I felt it was more mine. 

Still things to add after this part is working.  Startup routine,  homing,  and as you said,  what about the Ruskies!   


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

@gam

Still needs some work and I may go back to my other code because I understood what was going on there. A lot of time invested and I felt it was more mine.

It is always easier to follow your own code. I got hold of a little stepper motor to test code out. Just a matter of assigning a LED as the vacPin and using the button switches as tool on inputs.

To enlarge image right mouse click image and open link in new window.

dustCollector

   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1112
 
Posted by: @gam

the other code was almost there except the delay which should be cured with nonblocking delay. 

If thats so then the program logic steps I outlined are not correct. 

This is what I have understood for the main loop:

1. current is sensed on an analogue pin
2. sever is actuated to open the appropriate port if required (not if correct port is already open)
3. vacuum is started
4. tool is switched off - no current sensed on analogue pin
5. delay for x seconds to clear pipes
6. vacuum is switched off

and back to step 1.  The steps take place in sequence and the next step should only commence once the preceding step has been completed.

If the same tool is switched off but then back on again immediately then the above logic dictates the vacuum will be switched off after the delay period (but still sucking merrily during the delay) but then immediately on again as the current sensor will find the same tool is back on. If its another tool thats switched on then a wait for the vacuum to clear existing dust port and for the dust ports to move and open another dust port is required.

Step 1 should be programmed as a function that loops until a tool-on is found, at which point it returns the angle to use or sets a global variable with this information.

Step 2 should only allow your code to proceed once the correct dust port has been opened.

Your comments would seen to indicate that during the step 5 (delay) you also want something else to happen. But the only thing that can effectively take place is to start moving the dust port if so dictated by another tool operating.  But do you want to start moving the dust port if the vacuum is still switched on and clearing the dust from the fist tool?   I presumed you would want to wait and take no action until the vac is switched off.

On a different design, where dust ports to multiple tools can be open at the same time, then my program logic would be different and would allow for different ports to be opening and closing simultaneously.

So why is the delay an issue for your program?  It would see apposite.

 

This post was modified 3 years ago 2 times by byron

   
ReplyQuote
 GAM
(@gam)
Member
Joined: 3 years ago
Posts: 58
Topic starter  

   
ReplyQuote
 GAM
(@gam)
Member
Joined: 3 years ago
Posts: 58
Topic starter  

@robotbuilder

Looking good,  what are all the leds for, expansion?


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1112
 

@gam

I h've only glanced at your code because its rather frustrating to follow programs that, to my mind are rather twisty to follow, hence the start point of getting the program logic settled first before providing any assistance with the actual program code.  No doubt you have also found you code a bit twisty to follow  as you cant easily identify why programming the delay means your program does not proceed as expected.

And as to my program logic steps it appears the only thing in my logic that is not correct is that even if the current tool is switched off and the delay is triggered, you wish to abandon the vac off if the tool is switched on again within the delay time.  In this circumstance you do not want the vac to be switched off and then immediately back on again, but just to continue to be on.  OK this can be catered for quite easily by adding a step just before the vac shutdown (and after the delay is initiated due to the tool being switched off) to check if the current sensor for the tool in question indicates its been switched on again.  But I rather doubt that you would switch off and on the same tool within 4 seconds very often so I don't really see this as an issue, especially as the programming logic I gave would automatically switch the vac back on again immediately.

I'm thinking that only providing example code that follows the programming logic I suggest will suffice so I will have a go later at providing some code.  It will, in effect, be your code but chopped into sequences that seem logical to me and you can then decide to make it yours or consign it to the forum dustbin.

But you need consider is what should take place on a program startup so as to know the physical position of the motor and which dust port is open if any.  (remember the ruskies and power cuts). It would probably involve actually moving the motor to ensure it starts off in the position your code can then follow on from. Angle 0 or dust port 270 ???

 


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

@gam

Looking good,  what are all the leds for, expansion?

It is just a test base I have for experiments. I just connected a stepper motor because although I knew all about them and how they worked I had never actually played with one.

One thought I had was what happens when you turn a tool on and the vacuum pump is off and the disc not in position for that tool? Really you need to prevent power to the tool until the vacuum outlet is opened (rotating disc to the right position) and the vacuum pump is turned on?

So I would imagine each tool would have a push button to turn the power on only after the disc was in position for that tool and the vacuum pump was on. Push the button again to turn off the power to the tool but keep the vacuum running long enough to clear the pipe of dust.

If you only use one tool at a time then why not just have a flap at each location that you can open and close manually and a button at each location to turn the vacuum pump on or off?


   
ReplyQuote
 GAM
(@gam)
Member
Joined: 3 years ago
Posts: 58
Topic starter  

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

@gam

I already have a program that turns the vacuum on when any tool is used.

I wrote:
One thought I had was what happens when you turn a tool on and the vacuum pump is off and the disc not in position for that tool?

Nothing happens until the tool is turned on and returns the high current reading. What I am saying is the tool shouldn't be going until the disc is in position for that tool. You can be using the tool while the disc is moving into position and thus the vac pump is off and the dust has no where to go.

 


   
ReplyQuote
Page 6 / 8