Notifications
Clear all

Emergency Stop System Logic - Motor Control Board  

Page 6 / 6
  RSS

byron
(@byron)
Reputable Member
Joined: 1 year ago
Posts: 376
2020-05-02 5:20 pm  
Posted by: @frogandtoad

By the way... you keep referring to this as being a small program, but the code has yet to begin, and IMO, it will not be small by the time it's finished.  What do you consider small?

The robot design is made up of serval microprocessor boards.  Whilst the overall amount of code may be large, the motor control program running on the dedicated microprocessors for controlling the motors I would consider small.  So the 'black box' motor control program I consider small.   I doubt if it would take more than a couple of hours of your time, and probably a lot less to provide an alternative program. 

As for examples of using classes, small examples was not what I was suggesting you provide though thank you for the links.  Clearly I think it would be much more useful to present a fully worked example of the motor control program.  If you don't desire to do so thats quite understandable and whilst I do think it could be of greater interest to those looking to code their bots, I was not expecting you would do so just for my curiosity.  

Enjoy the building of your bot with or without classes. 😀 

This post was modified 7 months ago by byron

ReplyQuote
starnovice
(@starnovice)
Estimable Member
Joined: 1 year ago
Posts: 170
2020-05-02 5:35 pm  

@frogandtoad  @byron

So we are really starting to bog this thread down with programming philosophy versus ESTOP issues.  

Having said that let me add more to the discussion.  The reason I said the code for the motor controller is too simple to bother using a class is because it only controls one motor on the nano.  All of the code you would put in the class you can just as well list procedurally and wouldn't really use up any more coding space.  A class is primarily good for code reuse where you want more then one of an item, although it can also be used to encapsulate code and store it into a different file to make your make program look much simpler. 

In our case we are defining a "motor" to include the motor, the encoder on the motor, and the wheels.

Pat Wicker (Portland, OR, USA)


byron liked
ReplyQuote
frogandtoad
(@frogandtoad)
Honorable Member
Joined: 1 year ago
Posts: 540
2020-05-02 5:42 pm  

@byron

Well, the link I posted provides exactly what you asked for, and I think it clearly demonstrates the benefit of using classes even for small programs of less than 100 lines of code - Just look at the loop code in the before and after examples... the procedural version is more work and prone to error due to duplication, less readable and maintainable.

Do you not agree that using classes even in such a small example as that, it is more elegant, cleaner, and maintainable?

Again, what do you consider small code?, because in that example alone, incorporating classes made a big difference, even for ~60 lines of code, and I'm sure Bill's code will exceed that in the smallest of modules he creates.


ReplyQuote
byron
(@byron)
Reputable Member
Joined: 1 year ago
Posts: 376
2020-05-02 5:49 pm  

@frogandtoad

But no more than a simple function would do.   But I hear @starnovice (and probably others) note of bogging down threads, and we've been there before, so I will not go any further with this thread.  


ReplyQuote
frogandtoad
(@frogandtoad)
Honorable Member
Joined: 1 year ago
Posts: 540
2020-05-02 6:08 pm  

@starnovice

Posted by: @starnovice

So we are really starting to bog this thread down with programming philosophy versus ESTOP issues. 

This happens too often at any suggestions of using C++ classes under Arduino, yet it's the native language of choice promoted by the implementer's for the platform.  The irony is that people here think that C++ classes are advanced and not warranted, but somehow a lifetime of learning ROS is OK 🙂

I think I'll just let nature take it's course from here.

Cheers!


ReplyQuote
starnovice
(@starnovice)
Estimable Member
Joined: 1 year ago
Posts: 170
2020-05-03 12:14 am  

So, I have forked Bill's code out of GitHub using the GitHub Desktop App.  I have gone through and edited the code, but now how do I check it back in?  I can't seem to find the magic button on the Desktop App to do that.

Pat Wicker (Portland, OR, USA)


ReplyQuote
starnovice
(@starnovice)
Estimable Member
Joined: 1 year ago
Posts: 170
2020-05-03 12:25 am  

So until I learn how to use GitHub here is my code file.  I have not had the chance to function test it yet but there should be no major surprises, it does compile successfully.

 

Pat Wicker (Portland, OR, USA)


ReplyQuote
byron
(@byron)
Reputable Member
Joined: 1 year ago
Posts: 376
2020-05-03 1:17 pm  

I have the following thoughts on the motor control program, and indeed the DB1 design as thus far envisioned. So I emphasise, just my thoughts that may we be quite worthless especially as I may have lost the plot as to what the current design of DB1 is.  (I have been following along, but it has been and extended process and memory may be lacking and I don't have time to revisit all the DB1 articles)

Where I am coming from is how I would think the commands from the 'thinking computer' that instructs on the robots movements would be issued. Something in its algorithms will trigger the issuing of a move command. To illustrate I give the example that a move in a straight line command is issued. Maybe this will be followed by a turn left command as the robots sensors indicate the end of a corridor is reached (whatever).

There are many ways to instruct the robot to move but it seems currently the design means the robots motors move by the 'thinking computer' instructing a microprocessor over i2c to to issue a command via both a PMW and a direction signal. It would appear to do this for 2 motors via 2 independent microcontrollers.

One thing we know about driving motors to send the robot in a straight line, even if both are given an identical PMW signal, is that they often don't drive the robot equally. So we monitor the encoders to check the rotation of each motor and through a PID mechanism the PMW sent to the motors is adjusted. We also know that during a turn manoeuvre where one motor is expected to both turn at a different rate and also direction, an encoder PID would not be wanted, though we may need a bearing PID to help ensure we achieved, say, a 90 degree turn.

So, where best to do the PID control? It would appear to be for the thinking computer. In this case we would require a continual stream of motor turn commands to vary the PMW sent to a motor at any one time. We would also need a continued stream of encoder feedback to be fed into the thinking layer. In this scenario it seems to indicate that the encoder connection is best connected directly to the thinking layer and not to the motor control microprocessor.

The PID control could also be done at the motor control level. This would indicate that perhaps a different command is sent to the microprocessor, something like 'go straight' or 'turn 90 degrees' (or 10 degrees etc). However in this case the microprocessor would really need to control both motors and receive the feedback from both motor controllers. The motor control program would need to recognise that 'go straight' meant the PMW PID was used and that 'turn 90 degrees' meant the compass bearing PID was used.

I think, therefore, before proper consideration of the motor control programming is given,  just how the thinking computer will issue commands, and what commands they will be, should be specified.


huckOhio liked
ReplyQuote
huckOhio
(@huckohio)
Trusted Member
Joined: 1 year ago
Posts: 84
2020-09-25 12:06 am  

@starnovice

Pat, quick question on Motor Controller code.  In Bill's test code he has the following definitions for the EM_Stops:

// Emergency Stop Inputs (Analog Inputs used as Digital Inputs)
#define EM_STOP_0 8 // Arduino pin 8 (ATMega328 pin 14)
#define EM_STOP_1 9 // Arduino pin 9 (ATMega328 pin 15)
#define EM_STOP_2 A0 // Arduino pin A0 (ATMega328 pin 23)
#define EM_STOP_3 A1 // Arduino pin A1 (ATMega328 pin 24)
#define EM_STOP_4 A2 // Arduino pin A2 (ATMega328 pin 25)
#define EM_STOP_5 A3 // Arduino pin A3 (ATMega328 pin 26)

If I am using the ATMega328P chips do I change the code to this?  The current code looks like it's for the Nano.

// Emergency Stop Inputs (Analog Inputs used as Digital Inputs)
#define EM_STOP_0 14
#define EM_STOP_1 15 
#define EM_STOP_2 23
#define EM_STOP_3 24
#define EM_STOP_4 25
#define EM_STOP_5 26

Thanks


ReplyQuote
starnovice
(@starnovice)
Estimable Member
Joined: 1 year ago
Posts: 170
2020-09-25 8:36 am  

@huckohio

While I am not familiar with the 328, yes you would change the pin numbers to which ever pins you plan to connect your E-Stop signals to.  Bill was planning on many sources for an e-stop signal, you may choose to have fewer of them. Yes the current code is for a nano.

Pat Wicker (Portland, OR, USA)


ReplyQuote
huckOhio
(@huckohio)
Trusted Member
Joined: 1 year ago
Posts: 84
2020-09-25 11:27 am  

@starnovice

thank you. I am working through the code to try and understand the function. I want to send simple commands from the Mega to the motor controller for basis movements. Hopefully Bill will publish the rest of the code. 


ReplyQuote
Page 6 / 6