Anything seems possible when you don't know what you're talking about.
Sorry for the delay in response, but there was issues out of my control, which I first had to handle.
Thanks for this, I have tested but pick up a few problems.
1. The IRA sensors and LED's is now working as expected, and I also changed
((IRAval1==0)&&(IRAval2==0)) to ((IRAval1<=0)&&(IRAval2<=0))
2. It seems that the stepper motor, after power on, resumes the last position it had. Even selecting 0 does not turn it to position 0, but rather does nothing as per zero = zero.
Also, selecting the same number on the keypad twice in a row, (say I select 7, wait for the script to run, and select 7 again), it actually moves the motor to a new position.
3. After the IRA's were triggered, it send out continues data to the serial monitor. (Is there a way to stop this, and only, when triggered, send the output once? This (I think) will also solve the issue when I display a "clean or occupied bridge on startup,) keep displaying the same information.
I will upload another video to show what I mean.
Sorry for the delay in response, but there was issues out of my control, which I first had to handle.
No problem.
2. It seems that the stepper motor, after power on, resumes the last position it had. Even selecting 0 does not turn it to position 0, but rather does nothing as per zero = zero.
That's because you have not set up a homing routine yet. I mentioned that as being a missing part in an earlier post. When the power is turned on all previous data is lost (except for the EEPROM) contents.
Also, selecting the same number on the keypad twice in a row, (say I select 7, wait for the script to run, and select 7 again), it actually moves the motor to a new position.
That's because nobody has yet set a global location value. Again, as I pointed out in an earlier post, the Stepper class does not maintain any location value, that is left to the caller. So you'll need to set one up and maintain it inside the turning subroutine.
The last sketch I saw was from robotBuilder on Dec 16 and it has no location and moveToShed has no code to update the location after the turn. So, basically, every move you make starts from zero and ends at zero. That's why your turns make no sense and will, even turn again when you select the same station twice.
3. After the IRA's were triggered, it send out continues data to the serial monitor. (Is there a way to stop this, and only, when triggered, send the output once? This (I think) will also solve the issue when I display a "clean or occupied bridge on startup,) keep displaying the same information.
It's doing that because you told it to 🙂 in the block labeled "Read and process sensors" you test the IR sensors and then set the LEDs accordingly and write to the serial output accordingly. You don't notice the LEDs flashing, but every time you go through the loop the sensors are tested and the results fed out to the LEDs and the monitor.
To stop that, you need to introduce some kind of state or condition indicator to tell the code which state it's currently in, so it doesn't need to rekey the LEDs and the monitor output unless the state changes. For instance, it looks like the two conditions are mutually exclusive, so lets suppose that we declare a variable a variable ...
int IRState = 0; // =1 if both IRAvals are 0 and =2 if both IRAvals are non-zero
So the test for
if ((IRAval1==0)&&(IRAval2==0))
becomes
if ((IRAval1==0)&&(IRAval2==0) && IRState!=1)
and you then add the line
IRState = 1;
inside the current set of instructions for this condition. This will prevent it from repeating the instructions until the sensors indicate state 2 hs begun.
Similarly, change the second set to
if ((IRAval1>=1)&&(IRAval2>=1) && IRState!=2)
and add the line
IRState = 2;
to the body of code for that case.
Anything seems possible when you don't know what you're talking about.
Found this for "homing".
https://www.brainy-bits.com/post/how-to-set-the-home-position-of-a-stepper-at-startup
You can't use this method directly because you need to be able to rotate freely in both directions and this requires you to effectively block office direction for location testing.
and
https://www.brainy-bits.com/post/homing-stepper-motors-using-the-accelstepper-library
You're using a different stepper library.
Anything seems possible when you don't know what you're talking about.
@will, great stuff, it works - is there a while statement that I can use - something like
for while IRState = 1; do "displayInfo("Bridge Occupied - Remove ","Locomotive from BRIDGE", RED );"
or a while to display the same until IRState = 2;
AND
Can I somehow keep the LED's on until the bridge completed the move instead of switching of before it actually starts to move the bridge? (Lines 259 - 263)
I upload the latest version as well. (I renamed it to txt.)
In the current script - can I test for a selection of 0 and 9 to make use of an additional display? Instead of using
"displayInfo("Bridge move to",shed+" selected",BLACK);"
to use
"displayInfo("Bridge move to", 0 degrees" selected",BLACK); (for 0)
and
"displayInfo("Bridge turn of", 180 degrees" selected",BLACK); (for 0)
Let me download the sketch and get back to you.
Anything seems possible when you don't know what you're talking about.
Here is an update (I've changed the name to v6). I think it addresses the faulty shed direction problems and I've changed the move commands to use different formats for sheds zero and nine.
It should also leave the 'remove' message in place until the bridge is clear now.
I have not yet implemented the flashing LEDs while the bridge is moving (I'm not sure that's possible because I think the Stepper class blocks while it's moving).
Please check if this version solves the other problems (or introduces new problems).
Anything seems possible when you don't know what you're talking about.
Can I somehow keep the LED's on until the bridge completed the move instead of switching of before it actually starts to move the bridge? (Lines 259 - 263)
I think that can be done, but turning the bridge will be even slower and I may have to diddle with the speed of the blinking as well. Will that be a problem, I know you said that slow motion was more realistic ?
Anything seems possible when you don't know what you're talking about.
@will Thanks Will, I will be testing it with a "temporary turn table", will update and post a video.
Hi Guys, I have uploaded the video, after I changed the following with regards to the angles / sheds:
int shedLocations[] = {0, 171, 341, 512, 683, 1365,1536,1707,1877,1024};
//int shedLocations[] = {0, 683, 512, 341, 171, 1877,1707,1536,1365,1024};
Regards