Notifications
Clear all

Keypad control not working

156 Posts
3 Users
24 Likes
9,224 Views
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2531
 
Posted by: @robotbuilder

@willΒ 

In one online example the positions are set by manually controlling the steppers to move the rails to the exact position required and pressing a button to record the value for that shed.

We'll deal with that if it becomes necessary. It should only need to be done once anyway πŸ™‚ It's almost inevitable Β that eventually the array of shed locations (in whatever form) will be moved into the rotateTable module anyway.

I'd till prefer to see that as newShedNo instead of steps.

Well the stepper function requires steps not a shed number.Β  But sure if used within a routine it makes sense to call the routine moveToShed(x);

The reason I'd rather see shed number is that's what's passed to the moveToShed and I'd like to contain the mess converting from shed to absolute step position into one single place. It has the potential to change is a nasty way later.

I thought all the display stuff was complete (except maybe for the I/R train sensing) ?

The display stuff is not implemented in the code I posted nor the command to flash leds and so on ...

That's not required. the goal here is for us to produce small pieces of code to be grafted into the existing sketch (currently ModSet0v3.ino).

We're not meant to be generating new code for the whole project, we're upgrading existing code. That's why I'm asking you to use the names of existing values, so it will more easily be retro-fitted into the existing code body.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2531
 

@robotbuilder FYI @kobusven95

I have adapted the values given in the source document from kobusven95. These are in the form of (required angle)/360 and need toby multipliedbq stepsPerRevolution to get the absolute step position of each of the 10 sheds.

float shedSteps[10] = {0,115/360,85/360,55/360,25/360,345/360,315/360,285/360,255/360,0.5}; Β Β Β Β Β Β // Array of steps to sheds

Β The angle values may change since it may be possible (more convenient) to place the sheds and then compute the angles afterwards.

If desired, we could change the name (edit and change all) from "shedSteps" to "shedRatios" which more properly represents the contents (which are the ratio of the angle to the shed as a proportion of a full turn).

So shed N's location in absolute steps is shedSteps[N]*stepsPerRevolution.

Β 

Anything seems possible when you don't know what you're talking about.


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

@willΒ 

Well we all operate differently.Β  I see no problem with two or more complete solutions which can borrow ideas from each other.Β  On a programming forum someone might post a program (say Conways game of life) and it is followed by posts by other programmers with their versions,Β  each with its own slant and programming techniques.Β  However I don't want to hijack this thread with the theory of programming design or how to work as a team on a programming project. This is @kobusven95's project and he can take what he wants from whoever responds.

The function (bugs and all) to move the turntable from a current Angle to a desired Angle was what was missing in the ModSet0v3.inoΒ  program.Β  Only by writing a complete working program could I test it. I only have the stepper motor, I do not have the keypad or the LCD display. You might like to incorporate your own version within the ModSet0v3.ino?

Ultimately I guess @kobusven95 wants code he has written with your help that he can understand and I think you are good at doing just that.

Β 


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2531
 
Posted by: @robotbuilder

@willΒ 

Well we all operate differently.Β  I see no problem with two or more complete solutions which can borrow ideas from each other.Β  On a programming forum someone might post a program (say Conways game of life) and it is followed by posts by other programmers with their versions,Β  each with its own slant and programming techniques.

I didn't realize that you were developing an independent solution to the whole sketch. All I was intending to do was work on the parts that are required but not yet developed, I'm much too lazy to design and write the whole project. Was under the mistaken impression that you were looking at it the same way.

Now I understand your comments about the difficulty involved due to the lack of well defined specifications, I was only concerned with the missing parts and they didn't seem all that misty to me. But now I can understand your position on that.

The function (bugs and all) to move the turntable from a current Angle to a desired Angle was what was missing in the ModSet0v3.inoΒ  program.Β  Only by writing a complete working program could I test it. I only have the stepper motor, I do not have the keypad or the LCD display. You might like to incorporate your own version within the ModSet0v3.ino?

Yes, it's a complete solution in that it allows you to simulate the operation of components you don't have available. I'm lazy, so I skipped that effort and just drove my tests with a couple of for loops. The outer one selects each of the ten sheds as the starting shed and the inner one selects each of the target shed and then prints the from and to sheds, the calculated angle and the corresponding change in angle (with stepCounts to match). Did I mention that Im lazy πŸ™‚

Ultimately I guess @kobusven95 wants code he has written with your help that he can understand and I think you are good at doing just that.

I think your version of the sketch will be quite useful to him as it will provide a second viewpoint of how to approach the modelling of the train operation in the software design. Also because you'll be supplying a much larger operating body of code performing the same functions as his, yours will be especially beneficial because it shows an alternative way of providing the basic commands without using a keypad. In other words, how to find a way to do what you have to when you don't have the part(s) you thought you needed πŸ™‚

I also suspect that we'd break the functionality down differently. I've kind of skewed that to my methodology having broken the original sketch down into component subs by collecting repeated code.

Anything seems possible when you don't know what you're talking about.


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

@kobusven95
@will

I didn't realize that you were developing an independent solution to the whole sketch.
Now I understand your comments about the difficulty involved due to the lack of well defined specifications ...

I have already changed and improved the previous code I posted and will make it better match the code solution supplied by @kobusven95.Β  It was only meant to demo a code solution to rotate the turntable the shortest distance between two points on the circle,Β  it was not meant as a replacement of @kobusven95's code.Β  @kobusven95 will want to get his code working which is something I think @will is good at.

So @kobusven95 if your program still has issues feel free to post your latest effort for any suggestions.

Β 


   
kobusven95 reacted
ReplyQuote
(@kobusven95)
Member
Joined: 2 years ago
Posts: 60
Topic starter  

   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2531
 
Posted by: @kobusven95 FYI @robotbuilder

@will @robotbuilder

Please see attached the latest version. Not sure that i have incorporated everything I should.Β  Changes made - changed infrared sensor output behavior, changed PIN layout and breadboard layout.Β 

Looks good.

1) you can delete the calcBridgeSteps sub since it looks like we're skipping directly to an array for that.

2) I looked back in the original code and it had the test "IRAval1<=0" where it is now being tested for "==". It looks like that test may have been garbled somewhere.

Β 

Are the IR sensors working properly ? You were concerned about their operation before but I don't remember any exact statement about whether or how they were misbehaving.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2531
 
Posted by: @robotbuilder

@kobusven95
@will

I have already changed and improved the previous code I posted and will make it better match the code solution supplied by @kobusven95.Β  It was only meant to demo a code solution to rotate the turntable the shortest distance between two points on the circle

Since the array that provides the directions or absolute step values for use in your rotate sub won't ever be used anywhere else, do you think it's worth moving that array into your sub ?

Anything seems possible when you don't know what you're talking about.


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

@kobusven95Β 

So I am guessing your stepper motor is not turning?

The steps required by the stepper motor routine are computed by the current position of the turntable and the desired position of the turntable.

Imagine you are at shed 3 (location 341) and want to go to shed 5 (location 1877) you would take 512 steps in a clockwise direction. If however you wanted to go from shed 3 to the exit you would take 681 steps in the anticlockwise direction.

So you must know the current position of the turntable to compute the number of steps to turn it to another position.

Something like this although I have given a complete solution in my last posted code.

Β 

Β 

int shedLocations[] = {0,171,341,512,683,1024,1365,1536,1707,1877}

int calcBridgeSteps( int shedLocation ) {
 Β // calculate steps to get to shedLocation using current location
}


// move to shed num
stepCount = calcBridgeSteps(num);
StepMot.step(stepCount);

Β 

Β 

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

turnTableNumbers

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

@kobusven95

Messed up the snippit example.Β  It is the shed number to move to that is passed to the routine to calculate how many steps to get there.Β  The routine itself will use the Location of that shed number. The locations can be changed at any time in the array.

Β 

Β 

//shed numbers Β Β Β Β Β Β Β Β 0 Β Β 1 Β Β Β Β 2 Β Β Β Β 3 Β Β Β Β 4 Β Β Β 5 Β Β Β 6 Β Β Β 7 Β Β Β 8 Β Β Β 9
int shedLocations[] = {0, Β 683, Β 512, Β 341, Β 171, 1877,1707,1536,1365,1024}

int calcBridgeSteps( int shedNumber ) {
 Β // calculate steps to get to the location of shedNumber using current location
}


// move to shed num
stepCount = calcBridgeSteps(num);
StepMot.step(stepCount);

Β 

Β 

Β 

Β 

Β 

Β 


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2531
 
Posted by: @robotbuilder

@kobusven95 Β 

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

turnTableNumbers

Why do the shed numbers progress clockwise and their absolute step counts progress widdershins ? Isn't the default positive turn direction for the Stepper class clockwise also?

Anything seems possible when you don't know what you're talking about.


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

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

@willΒ 

Why do the shed numbers progress clockwise and their absolute step counts progress widdershins ? Isn't the default positive turn direction for the Stepper class clockwise also?

It is how @kobusven95 drew them except he used negative values and I made them all positive.Β  They are not steps they are locations.Β  Perhaps you could say the location value is the step value from the zero position? Thus the use of negative values.

3663 20211211160649

Β 

Β 

Β 


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2531
 

@robotbuilderΒ 

Ok, thanks. That's why they seem backwards.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2531
 
Posted by: @robotbuilder

@kobusven95Β 

This is your code modified (probably has bugs and will not work).

Files compilation with the line ...Β Β 

 Β Β Β currentLocation = 0; Β Β '<------------------- added

Β Looks like the comment is missing, should beΒ 

 Β Β Β currentLocation = 0; Β Β //<------------------- added

Β After that, compile fails again at

 Β Β Β Β Β Β Β Serial.println(1111); mnαΉ‡

Probably extra accidental characters introduced, changed to

 Β Β Β Β Β Β Β Serial.println(1111);

Compile fails atΒ 

int shedLocations[] = {0, Β 683, Β 512, Β 341, Β 171, 1877,1707,1536,1365,1024}

Missing closing ";", changed toΒ 

int shedLocations[] = {0, Β 683, Β 512, Β 341, Β 171, 1877,1707,1536,1365,1024};

Β Compile fails at

 Β currentLocation = shedLocations(shedNumber);

Β Using round brackets (sub call) instead of square brackets (index into array) changed toΒ 

 Β currentLocation = shedLocations[shedNumber];

Compile failed at line

 Β return stepCount

Β Missing ";" changed to

 Β return stepCount;

Compile failed at

 Β stepCount = calcBridgeSteps(shedNo); Β // <--- Β added

Because stepCount was not defined, changed to

 Β int stepCount = calcBridgeSteps(shedNo); Β // <--- Β added

Still fails at this line "void value not ignored as it should be". calcBridgeSteps was declared as void instead of int, changed

void calcBridgeSteps( int shedNumber ) { 

to

int calcBridgeSteps( int shedNumber ) { 

And it now compiles clean.

Because there were a number of changes, I'm attaching the updated sketch.

It appears that I can't attach the source in this post, so I'll try to post it in another post.

Β 

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Page 9 / 11