Notifications
Clear all

Code and Wiring for DB1 Motor Control  

Page 1 / 3
  RSS

Robo Pi
(@robo-pi)
Robotics Engineer Moderator
Joined: 1 year ago
Posts: 1767
2019-11-12 2:57 pm  

@dronebot-workshop

Hi Bill,

Is there a way to get the code and wiring for the complete motor control system?   You had promised some time ago to make the code available on GitHub but I never saw that happen.

I'm ready to wire up and program the Arduino Mega and the two Nano's or Atmega328 chips (I'll actually be using STM32 boards in place of the Nano or Atmega chips) but the code should be similar enough.

I'd like to get the motors up and running with the nice smooth acceleration you had talked about in a previous DB1 episode.    I could figure out how to do this on my own, but since this is what you are also planning to do I thought it would be nice to use your scheme so we can be on the same page.  I'd like to see how you did this anyway.  I think you also had emergency stop routines, etc.   I wanted to duplicate all of that too so when it comes time for higher-level control we'll be on the same page.

It sure would be nice to get these robots up and running.   There sitting here waiting to be wired up and programmed.  I've been waiting for this wiring and code all summer. ? 

DroneBot Workshop Robotics Engineer
James


Quote
Spyder
(@spyder)
Prominent Member
Joined: 1 year ago
Posts: 780
2019-11-12 6:53 pm  
Posted by: @robo-pi

nice smooth acceleration

I found this...

https://www.airspayce.com/mikem/arduino/AccelStepper/AccelStepper_8h_source.html

The main page...

https://www.airspayce.com/mikem/arduino/AccelStepper/examples.html

The main arduino page...

https://www.airspayce.com/mikem/arduino/

The main main page...

https://www.airspayce.com/mikem/

He's probably got an index with an actual web page in there someplace, but I didn't bother to look for the fancy bits, just the important parts


ReplyQuote
Robo Pi
(@robo-pi)
Robotics Engineer Moderator
Joined: 1 year ago
Posts: 1767
2019-11-12 8:29 pm  

@spyder

Thanks.  But I'm driving PM motors.   Besides, I want to see Bill's larger scheme.  He's using a Mega to control two smaller microcontrollers, each one dedicated to a PM  motor.   And he also has an Emergency Stop system set up, as well as possible other features.   So I want to try to duplicate  what he's doing as closely as possible.   This way when we get to the other layers I'll be in harmony with how he intends to give commands to the Mega to control the robot.

DroneBot Workshop Robotics Engineer
James


ReplyQuote
Robo Pi
(@robo-pi)
Robotics Engineer Moderator
Joined: 1 year ago
Posts: 1767
2019-11-12 9:05 pm  

@spyder

By the way.  Thanks for the link to the stepper motor control library.   That's a nice site, I saved the link for later possible use.  I plan on building a stepper motor driven arm  so these routines may indeed come in useful  for that project.   That's a really well-organized site.

DroneBot Workshop Robotics Engineer
James


Spyder liked
ReplyQuote
Spyder
(@spyder)
Prominent Member
Joined: 1 year ago
Posts: 780
2019-11-13 1:26 am  

@robo-pi

You're welcome 🙂

Even if you can't immediately use it, you might be able to at some point, or it might be of use to somebody else, considering how many other Random Robots we're Collectively Constructing 


ReplyQuote
Bif99
(@bif99)
Eminent Member
Joined: 11 months ago
Posts: 40
2019-11-21 12:33 am  

@dronebot-workshop

I too have been waiting patiently for Bill's sketches for the DB-1 project that were referenced in Ep-11. I would like to test the two Nano motor control even though I will probably upgrade to the 328P when available.  BTY, I posted a method for making cable assemblies using aviation connectors some time ago.  It is quite elegant.  Please check it out and let me know what you think of my method.


ReplyQuote
Fire Chief
(@fire-chief)
Active Member
Joined: 7 months ago
Posts: 14
2019-12-22 6:34 pm  

Having an issue with the Code for the Motor Test, when I download I get an error message 

"Exit Status 1"

"Unterminated Comment"

Its referring to Line 73 and (/*) at the end of the line. I tried removing it and it downloaded fine. The only problem is the test starts at the end of the code where DB1 spins for 2 seconds and then motors run continuously. Not sure what to do to correct this. Any suggestions would be appreciated.


ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 1 year ago
Posts: 660
2019-12-22 7:49 pm  

@fire-chief

Which "Code for Motor Test" are you referring to Richard?

SteveG


ReplyQuote
Fire Chief
(@fire-chief)
Active Member
Joined: 7 months ago
Posts: 14
2019-12-22 10:19 pm  

The Code in Episode 7 Motor Test.


ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 1 year ago
Posts: 660
2019-12-22 11:29 pm  

@fire-chief

I think I was successful with that sometime ago, but I'll see if I can revisit during this Christmas week.

Thanks for the reminder where to find it!

SteveG


ReplyQuote
Fire Chief
(@fire-chief)
Active Member
Joined: 7 months ago
Posts: 14
2019-12-23 12:10 am  

@codecage

Thanks for the assistance, have a Merry Christmas.


ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 1 year ago
Posts: 660
2019-12-23 12:22 am  

@fire-chief

Yes that '/*' does seem to be some errant characters and I don't remember them from when I tried this code earlier, but then I some times have trouble remembering what I had for breakfast two or three days ago.

But looking at the code, I see that the following lines need to be added or the motors will continue to run spinning DB1 constantly:

74
75 delay(2000);
76
77 // Stop motion
78
79 analogWrite(leftpwm,0);
80 analogWrite(rightpwm,0);

The code as found in the Motor Test article has nothing to stop the motors after the spin starts, even though the comment says "// Spin for 2 seconds" there isn't code to stop the motors

I'll have to wire up my Mega to the Cytron controllers as in this sketch again and see what results I get.  Hopefully in the next couple of days.

I also noticed that in the article the "leftpwm" pin is defined as pin 11 and the "rightpwm" pin is defined as pin 10.  In the sketch these are just reversed, but as long as you wire correctly this should be an issue.

SteveG


ReplyQuote
Fire Chief
(@fire-chief)
Active Member
Joined: 7 months ago
Posts: 14
2019-12-23 3:33 am  

@codecage

Thanks Steve, I’ll give this  try and let you know.

 

Richard


ReplyQuote
Fire Chief
(@fire-chief)
Active Member
Joined: 7 months ago
Posts: 14
2019-12-23 7:37 pm  

@codecage

Hi Steve, I added your suggestion to the code and it worked. I found some other errors that needed to be changed such as the left and right motor direction. On line 38 & 39, 55 & 56 and 72 & 73 the direction is incorrect, that way when I started DB1 it would spin right than spin left and then go forward. So the direction in the code should be:

38  digitalWrite (leftdir,0);

39 digitalWrite (rightdir,1);

55 digitalWrite (leftdir,1);

56 digitalWrite (rightdir,0);

72 digitalWrite (leftdir,0);

73 digitalWrite (rightdir,0);

Thanks again for your assistance.

Richard

 


ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 1 year ago
Posts: 660
2019-12-23 9:34 pm  

@fire-chief

I will keep that in mind when I get mine wired up to do the test.  Was working towards that end earlier this morning, then all of a sudden the day got shot full of holes!  Maybe I can get back to it in the morning.

Also, on your code changes, I'm wondering if it could be just the wiring of the gear motors.  Remember that one motor has to spin the opposite of the other for forward and reverse due to the way they are mounted.  Maybe you had yours wired the opposite of how Bill had his, so you had to reverse your rightdir and leftdir values from his.

SteveG


ReplyQuote
Page 1 / 3