Author Topic: Wiper motor, pot, and motor controller communication  (Read 4934 times)

0 Members and 1 Guest are viewing this topic.

Offline Robotics12Topic starter

  • Jr. Member
  • **
  • Posts: 33
  • Helpful? 0
Wiper motor, pot, and motor controller communication
« on: March 21, 2012, 01:52:17 AM »
Ok, so I have posted about my project before...the wireless cart. Here is a more updated picture after most of the things are mounted(this is as a week ago, more things are mounted now...I can get a better picture tomorrow).


What I have now is a pot in each of the circles in the picture. The pot for feedback down at the wheels and a pot in the steering wheel for the target(I actually have a mount already in place for both just not in this picture). I have the wiper motor set up at the bottom with its own rod to rotate the wheels left and right, which in return will turn the pot.

So, I have a roboclaw 2x5a which I will be using one of the outputs for the wiper motor.
http://www.pololu.com/catalog/product/1495

It seems like the analog input is what I am trying to accomplish. Thing is, instead of having two pots into the roboclaw, I will have 1 pot into a arduino(the steering wheel pot) that communicates wirelessly to another arduino. This second arduino, I would assume, needs to go into the roboclaw instead of the pot? It acts as the input for the steering wheel pot.

Also, I have a second pot(pot at the wheel) for feedback to tell where the current position is, which will be the second pot that goes directly into the roboclaw. Do I have this correct?
The wiper motor will be the DC1 Motor in the diagram.
« Last Edit: March 24, 2012, 03:50:22 PM by Robotics12 »

Offline Daanii

  • Robot Overlord
  • ****
  • Posts: 138
  • Helpful? 3
Re: Wiper motor, pot, and motor controller communication
« Reply #1 on: March 22, 2012, 12:06:23 PM »
Nice picture! Good to see your wireless go-kart is moving along.

The wiring diagram you showed is different from what you need. That diagram shows how to wire the Roboclaw motor controllers to control a skid-steer remote-control toy car. The two motors in that diagram drive the wheels, with one motor driving a wheel or wheels on the left and the other motor driving a wheel or wheels on the right.

If the two pots are set at the same position, the car goes forward. If one pot is set at a different position than the other, the car turns. That's what the YouTube video is showing at the Pololu website you linked to.

What you want to do is different. You are not using a pot to control speed. You want to control position. So you cannot just wire things up to your motor controller. You need to use a very different system.

Here's one way to do that. Attach a pot to your steering wheel. Use analogRead on your first Arduino to get the position of the steering wheel. That tells you what steering the driver wants to do. That is your target.

Since you want to do this wirelessly, you will want to send the "target" signal from your first Arduino to the second Arduino. The second Arduino will take that target, compare it to "feedback" (the current position of the steering linkage), and generate a speed and direction signal for the Roboclaw motor controller.

To get the feedback signal, you need a pot on the end of the steering linkage stub sticking up in your picture. You need to use analogRead on your second Arduino to get the position of the steering linkage.

When you have the target and the feedback, you can use a PID algorithm, or even just a P algorithm, to get a number for your motor control. You will need to convert that number into a motor direction and speed signal to send to your Roboclaw motor controller.

That all may sound hard. It is, and it is not. It is hard in that it is a lot of work. When you are just starting out, it will take you some time and experimentation. On the other hand, it's all pretty straightforward. You do not need to hit the textbooks to learn new theories or formulas. It's all plain vanilla, nothing fancy.

The Pololu jrk controller does all that for you. You just send it the target and the feedback and it controls the motor. You can tune the PID algorithm using a motor control software interface that Pololu provides. All very neat and tidy, but it does cost $100.

For me, it was worth the cost. I spent a few weeks trying to do it myself, and burned out a motor controller, before I went the easy route. I'm glad I did.

One further note. Since you are using an Arduino, you may want to look at the Arduino website and forums (www.arduino.cc/forum) for some guidance. Especially about the PID algorithm. You may or may not find some help there. But since this site (as good as it is) is not Arduino-specific, people there may be more likely to have done what you want to do.

Offline Robotics12Topic starter

  • Jr. Member
  • **
  • Posts: 33
  • Helpful? 0
Re: Wiper motor, pot, and motor controller communication
« Reply #2 on: March 22, 2012, 12:50:50 PM »
Perfect explanation. I have some code dealing with getting the position of each pot, this will get the position of the steering pot and will have one for the feedback pot:
The target pot will be sent wirelessly to arduino2, while the feedback pot will be sent as an input to arduino2 and then both of these values are sent to the roboclaw...do I have that correct?

Code: [Select]
//This will be the input pin for the pot, I will set it here but possibly change
int potPin = 0;
int val = 0;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  val = analogRead(potPin); //read value from the pot
  val = map(val, 0 1023, 0, 20);
  Serial.println(val);
  //delay(15);
}

Then, some code for the second arduino to receive wirelessly from the first..doubt it is correct but just something to get me started:
Code: [Select]
//read in value from first arduino of slide pot
//#include "RoboClaw.h"
//#include "BMSerial.h"

int potIn = 30;

void setup()
{
  Serial.begin(9600);
}


void loop()
{
   //stays until receive value front arduino1
  while(Serial.available() == 0);
 
  //range from 0 to 30
  //converting char value into integer
  int data = Serial.read() - '0';
 
  //pot range of 180 deg, change since we want be using the full 180?
  int pos = map(data,0,30,0,180);
  pos = constrain(pos,0,180);
  //val = analogRead(potPin);
 
  Serial.flush();
}

And I have posted something similar to this with some code at the arduino forum with not much luck yet.
I am also trying to get some help with the roboclaw/arduino communication from roboclaw forum. This is all pretty much first time thing for me which is probably why I am asking a lot of questions.
« Last Edit: March 22, 2012, 01:08:16 PM by Robotics12 »

Offline Robotics12Topic starter

  • Jr. Member
  • **
  • Posts: 33
  • Helpful? 0
Re: Wiper motor, pot, and motor controller communication
« Reply #3 on: March 22, 2012, 04:52:13 PM »
The more I look at it, seems I will need to use the simple serial method described here in slides 25-28. But still using the same process Daanii has described. I am currently studying more about this motor controller and the process, or mode, using simple serial with it.
http://www.pololu.com/file/0J518/roboclaw2x5A_B0099.pdf

Offline Daanii

  • Robot Overlord
  • ****
  • Posts: 138
  • Helpful? 3
Re: Wiper motor, pot, and motor controller communication
« Reply #4 on: March 22, 2012, 08:28:09 PM »
On another thread, TheBadger recommended this article on PID controllers:

http://www.inpharmix.com/jps/PID_Controller_For_Lego_Mindstorms_Robots.html

this made me understand how PID works, this guy is great.

I second his recommendation. Read that webpage and see if you can figure out more what you need to do to write your PID software.

As to the other things, your code had one typo that I saw:

Code: [Select]
val = map(val, 0 1023, 0, 20);

should be:

Code: [Select]
val = map(val, 0, 1023, 0, 20);
Otherwise with your code, I'm not sure how your wireless works to send the steering target from one Arduino to the other, so I cannot help you there.

In general, the principle in your code is right, but you will need to work on your ranges. Once you mount the pot on the steering wheel, you can calibrate it. Then you will have a steering "target" to send wirelessly to the other Arduino.

But I can help with the rest. The second Arduino needs to get the steering target from the first Arduino, and then get the steering feedback itself from the second pot using an analogRead. With those two numbers, you can then generate the signal and send it to your motor controller. If you can mount the two pots, that will help.

Also, do you have the linkage to make your windshield wiper motor actually move the wheels? That will be important too.

Offline Robotics12Topic starter

  • Jr. Member
  • **
  • Posts: 33
  • Helpful? 0
Re: Wiper motor, pot, and motor controller communication
« Reply #5 on: March 22, 2012, 09:10:28 PM »
I will defiantly look over that article.

For the xbee's to communicate we have 'programmed' the xbee's using a terminal program, putty. That is about it. We have actually demoed it using a pot and a servo and it works wirelessly.

Yes, we are 'centering' the pot before mounting it into the wheel and steering linkage so the center correlates with the wheels/steering wheel being straight. The first set of code I posted will be for the 'target' pot into arduino1 and also for the steering linkage pot, at the bottom, into arduino2. That set of code will read in the values at each pot. For the 'target' it will send wirelessly to arduino2 and the 'feedback' pot will send directly to arduino2 so now arduino2 has both values of each pot and can generate the signal, and will be connected to the roboclaw. Which is where I am now, getting the arduino2 to calculate signal and then getting the arduino2 to send to the roboclaw.

That second set of code, is the actual code that will be with the arduino2 to be able to receive the input from arduino1. As I mentioned earlier, it is similar to the code for the arduino2 when demoing the pot/servo example except this code does not contain #include Servo.h or creating a servo object.

Here is the linkage for the wiper motor picture. As you have see, we have it linked to the steering linkage for all components of the wheels being moved. You can also see the pot we have mounted, eventually, into the rod so it rotates as the wheels move left and right as that rod can twist left and right with the wheels. This is the 'feedback' pot.
« Last Edit: March 24, 2012, 03:49:49 PM by Robotics12 »

Offline Daanii

  • Robot Overlord
  • ****
  • Posts: 138
  • Helpful? 3
Re: Wiper motor, pot, and motor controller communication
« Reply #6 on: March 22, 2012, 09:41:10 PM »
From that picture I can tell you are all set with the pots and the steering linkage. Looks great!

Hope that article helps you see how PID works. It may be a little confusing, since he talks about a light sensor and controlling two motors. But he does go into a lot of detail and makes a good effort to explain how PID works. If you can figure out your code from that pseudo code, that's great. If not, maybe I or someone else can help.

 


Get Your Ad Here