Position Control of...
 
Notifications
Clear all

Position Control of dc motor with encoders

10 Posts
3 Users
5 Reactions
187 Views
robotBuilder
(@robotbuilder)
Member
Joined: 7 years ago
Posts: 2571
Topic starter  

This is the start of my first attempt in Position Control using motorized wheels with encoders.

I am using this source as a guide:

https://curiores.com/positioncontrol

This is my current setup:

To enlarge image right click image and choose Open Link in new window.

testSetup

First to check the encoder was working. Instead of using the plotter tool as shown in the above tutorial I used two LEDS. The output of each of the two encoder sensors would turn its LED on or off as I turned by hand the encoder wheel. If the left LED came on before the right LED then I was rotating the wheel one way and if the right LED came on before the left LED then I was rotating the wheel the other way.

It worked as expected.

I was going to post a video clip but online providers that didn't require signing up to an account and providing an email address only kept the video available for viewing for maybe two weeks depending on how frequently it was viewed. Now I know why some links to videos just show a black image. This doesn't mean I will never sign up to an online video storage some time in the future as I know it is fun to see a project actually doing something.

Step one done!

This is the simple test code I used:

 

#define LED1 25
#define LED2 24
#define BTN1 23
#define BTN2 22

#define ENCA 2
#define ENCB 3

void setup() {
  pinMode(LED1, OUTPUT);
  pinMode(LED2,OUTPUT);
  pinMode(BTN1, INPUT_PULLUP);
  pinMode(BTN2, INPUT_PULLUP);

  pinMode(3,INPUT_PULLUP); // set as input
  pinMode(2,INPUT_PULLUP); // set as input

}

void loop() {
  if (digitalRead(ENCA) == HIGH) {
    digitalWrite(LED1, HIGH);
  }
  else {
    digitalWrite(LED1, LOW);
  }

  if (digitalRead(ENCB) == HIGH) {
    digitalWrite(LED2, HIGH);
  }
  else {
    digitalWrite(LED2, LOW);
  }
}

 

 



   
Lee G reacted
Quote
byron
(@byron)
No Title
Joined: 7 years ago
Posts: 1276
 

Posted by: @robotbuilder

I was going to post a video clip but online providers that didn't require signing up to an account and providing an email address only kept

I guess you already have a youtube account for watching the DroneBot videos et al. so maybe just load your clip there?  

I had not actually done this so I thought I would give it a quick go to see how easy it is.  I took a 3 second video of a small screen on my desk, sent it to my computer desktop, logged on to youtube, found the place to load the videos, dragged the video to load it, ticked a couple of boxes, and made it public, it was uploaded and it gave me a link.  

Real easy, so maybe we can get some instructional @robotbuilder videos 😀 



   
Inq reacted
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 7 years ago
Posts: 2571
Topic starter  

@byron 

I don't have a utube account or even a google account you don't need them to search for and watch utube videos. As for instructional videos I will leave that to people who know what they are talking about like Bill's dronebot videos. I just enjoy messing about with electronics and programming when I get the time at an amateur level. There are so many other practical things I have to spend most of my time and money on.

I did sign up for this forum and a programming forum but that is it. I don't for example use Facebook or any of those other multimedia things. My wife likes Facebook so one is enough! I watch free to air TV while it still exists.



   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 7 years ago
Posts: 2571
Topic starter  

Using a google search on dronebot workshop and PID I came across this on PID that I remember watching but had forgotten about. It uses an Arduino PID library.

After all these years of ad hoc methods for keeping the robot base going straight and now trying to lock onto visual targets I would really like to get PID actually working on some hardware!!

https://dronebotworkshop.com/custom-servo-motor/

https://forum.dronebotworkshop.com/technology/pid-controller-for-robotics/

 



   
Lee G reacted
ReplyQuote
Inq
 Inq
(@inq)
Rocket Scientist or Space Cadet
Joined: 4 years ago
Posts: 2051
 

Posted by: @byron

I took a 3 second video of a small screen on my desk, sent it to my computer desktop, logged on to youtube, found the place to load the videos

Yes, and you can make it even easier... you can just upload them directly from your phone two seconds after making it.  At least from an Android.  Don't know about that Fruit thing.  Obviously, you want to be on WiFi when you do it.

 



   
ReplyQuote
Inq
 Inq
(@inq)
Rocket Scientist or Space Cadet
Joined: 4 years ago
Posts: 2051
 

Posted by: @robotbuilder

I don't have a utube account or even a google account you don't need them to search for and watch utube videos.

Do you have a smart phone?  It's been a decade, but I recall to have an Android, you have to have a Google account.  If so, you already have a YT account.  They're the same.  If you talk on a fruit, I'm clueless. 😆 

I'd really love to see your bots in action.  The Google accounts are free and you don't  have to give them any personal information that I recall... certainly not a credit card.



   
ReplyQuote
Inq
 Inq
(@inq)
Rocket Scientist or Space Cadet
Joined: 4 years ago
Posts: 2051
 

Posted by: @robotbuilder

I would really like to get PID actually working on some hardware!!

If you're wanting to work it out on your own, I'd completely understand, but if you want some YT help, the topic you sent me earlier has a PID which I've done before the hard way, but it also has some method of "Auto Tuning" of the PID parameters, that I'm not familiar with.

https://projecthub.arduino.cc/RolfK/two-wheeled-self-balancing-robot-with-stepper-motor-9ecd74



   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 7 years ago
Posts: 2571
Topic starter  

@inq 

I'd really love to see your bots in action.

I only have one bot project at any time as each of the past bots were learning experiments with different ideas and sensors and I dismantled each one to reuse their parts and code ideas in future experiments. In fact I haven't changed the basic setup since I joined these forums years ago!!

https://forum.dronebotworkshop.com/user-robot-projects/k8055-robot/#post-4101

All I have done over the years has been experimenting with sensors (including the webcams and visual analysis) and algorithms that make use of those sensors.

As regards video of a robot in action keep in mind that without the details of how the robots actually do what they do autonomously a video might just be showing a remote controlled robot base.

Hopefully I will have time to work on the PID experiment this weekend. I have a few fix it jobs to do around the house as well.

 



   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 7 years ago
Posts: 2571
Topic starter  

@inq 

Ok I have the example from https://curiores.com/positioncontrol working.

Did a quick bread board of components and modified some pin numbers to suit my connections.

Here is a short video so you know it actually happened.

Notice it turns one way stops and then turns back the other way and stops where it started.

https://streamable.com/7qnjta

Overview:

overView

 

 



   
Lee G reacted
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 7 years ago
Posts: 2571
Topic starter  

The video in my previous post has expired!!

So I will have to give thought to where else to post robots in action and it seems like I have to sign up.

Today I worked on using two motorized wheels with hall effect coders that only have one encoder output instead of two. They also come from a robot vacuum cleaner so they must use the direction of rotation chosen when the motors are activated. I wrote some code that seems to work ok by incrementing or decrementing according the direction the wheels are commanded to rotate.

I was mulling over how to attach two of the motor I used in the above working example to a robot base and think I can do it ok. They are not designed to simply be clamped on but are molded to fit snuggly in the robot vacuum shell which in this case were held in place with a pivot hook and spring. The weight of the motor stretches the spring to turn of the motors when the shell is picked up.

A follow up curiores example using more than one motor,

https://www.hackster.io/curiores/how-to-control-multiple-dc-motors-with-encoders-f8ed6c



   
Lee G reacted
ReplyQuote