Newbie with a small robotics project

Hello all. Very new to the forum, and very new to robotics. Currently, I’m working as a volunteer project to help some high schoolers in building an automated car that needs to travel a programmed distance. I was asked to help because I have a fair amount of programming knowledge (I’m pretty good with C, C++, Python, SAS, and R), but I have EXTREMELY limited experience in circuitry and robotics building (I’m a Biochemistry PhD candidate, haha). After probing an electrical engineering friend, he did some quick searching and thought that the Bot Board II would make a great board to work with.

Well, I have been trying to fumble my way through the internet to learn what I can in buying parts, and already make a couple of small mistakes along the way (Eg: I currently have 6 Microchip PICs sampled becuase I thought I could use them with the Bot Board II). I’d like to explain what I am currently thinking of trying, and hopefully get some advice from some of the forum gurus.

Again, the objective is to make the car go a programmed distance and stop. So, I’d like to use the Bot Board II (currently have two of them for hopefully two cars), connect a Lego NXT Motor (which has a builtin encoder) to the Bot Board, and program the distance by pressing the buttons on the bot board. The distance might preliminarily be displayed using the LEDs in binary with some combination of beeps (I’ll worry about adding some form of display later). So, the NXT motor has 6 wires (two for pos/neg voltage, one ground, one +4.3V, and two for the quadrature encoder): I might be simplifying this, but I was thinking i could connect the pos and neg to the bot board, and one of the encoder wires to the corresponding input (since one will provide a sensitivity of 2deg per pulse, which is MORE than accurate enough for our needs). From the programming front, I was hoping to basically have the motor run with a DO WHILE loop until the counter measuring the pulses from the encoder reaches the deisgnated distance, and then cutting the power to stop it. It only needs to go in a straight line, so I was hoping I might not need a motor/servo controller.

OK, so to actually include some specific questions.

  1. Would I need a motor controller for this, or is the job I’m needing simple enough that I could somehow program the power to be cut and stop the motor (or, if need be, somehow reverse the current to change the direction of the motor for maybe like 100ms as a break?)
  2. Since my master plan (due to limited funds) of sampling Microchip PICs to use on the Bot Board II apparently isn’t possible, I’m going to have to purchase a new microprocessor. After reading through a few simple PBASIC guides, its a simple enough syntax that I’m not concerned about learning it and then teaching it to the students. Based on my needs, is there reason to get an Atom/Atom Pro, or would a BS2 be good enough (I’m currently seeing them on Ebay for ~$35, so saving the few dollars would be nice)?

Any other comments or suggestions people have would be GREATLY appreciated.

Damien

short answers are yes you need a motor controller and either the BA or BAP would do the job but I would encourage buying the BAP for its speed if you are going to be using it to read the quadrature inputs in real time and don’t want to miss pulses.

longer analysis follows. from what I can tell the nxt motor has no power amplifier in it and the pos/neg voltage connections are directly wired to the motor terminals. to drive this in either direction then you typically need an h-bridge and something to control the bridge circuit. this is where the motor controller comes into play. this motor has pretty low current though so you could probably get away with using something like the SHB-01 HS-5745 Servo Amp sold by lynxmotion. you would need to convert it into a continuous rotation servo controller using a pair of resistors to fool its feedback pot into thinking the output shaft was always at 0 degrees. now you can use an r/c servo output signal from a BA or BAP to control direction and to a lesser extent rpm.

the quadrature input, powered from the pins you describe as +4.3V and GND, could be connected directly to the BA or BAP i/o pins and either polled by software or better yet have one of them trigger an interrupt routine on pin change so you never miss any pulses.

Thanks for the info and quick reply! I think I understood most of that. So BAP >>> BS2 if I’m using the encoder. I’m not actually planning on using the quadrature input, since it can read up to 720 pulses/rotation, and the 180 is MORE than accurate for this. Was just hoping to cut some costs. The SHB-01 seems simple enough (and relatively cheap), and I can see the point now (basically one more piece of circuitry to regulate the voltage and thus the speed/direction.

Would I need to convert it to a continuous rotation servo? I’ve only done a bit of reading on modifying servos, but looking at a schematic (I can’t post URLs yet, but google nxt_motor_rotation_sensor_circuit.jpg and its the first result) I don’t see a potentiometer (and reading Lego’s description, this is their generic motor for all projects, and what’s the point of having an encoder for a restricted rotation?). So my ignorance is going to start showing through, but I see two contacts on the SHB-01 for the motor, and then three cables coming off with three contacts on the other side of them. Do those three cables connect to the Bot Board II (voltage, ground, and I/O) or something else?

Your comments on the encoder connection make sense - glad to know what the 4.3V and GRD are for, wasn’t sure on that. Could you explain the “interrupt routine on pin change.” The programmer in me says to do it by software, but losing pulses seems like it would cause too many problems.

Um the bit about continuous rotation servo is just a concept to explain how to apply the SHB-01 to the NXT motor. The NXT motor is already continuous rotation so you don’t need to modify it. The SHB-01 however is a servo controller which expects a motor coupled to a potentiometer as a position feedback. by replacing the potentiometer with a fixed resistor divider you can convert the SHB-01 servo controller into the equivalent of a continuous rotation servo controller.

Interrupts are a software solution. The input from the encoder goes to an i/o pin which is configured to trigger a software interrupt when it changes state. The alternative to interrupts is polled operation which requires your software loop be fast enough to guarantee it will examine the state of the encoder input before it changes twice. If that occurs, that is to say you examined the interrupt at too slow of a rate, then you have no idea the pulse came and went. coding interrupts on a basic micro controller requires a little bit of research into the examples, sample programs, and projects done by a few of the other forum regulars. whatever you write needs to be efficient code… get in, increment a counter, set a flag maybe, get out. in this way it presents the smallest interruption time to your foreground routines as well as increasing the maximum rate at which you can reliably count pulses.

As for the encoder, I have done some of this and maybe soon I will work on it again as I convert my Rover from using the HITEC rc receiver to the DIY receiver probably with XBEE communications…

I have one of the Rover kit where two of the wheels have encoders on them. I connected one pin of the first encoder to BAP IO pin P18 and the other to P16 and for the other encoder BAP IO line P19 and P17. In particular I used P18 and P19 as they coorespond to IO pins that also can serve as IRQ2 and IRQ3 on the underlying H8 microprocessor. I coded it up to interrupt on both leading and trailing edge of the signal and during the interrupt processing I detect the state of the other encoder line. Knowing how the phases of the two signals are allows you to detect if you are going forward or backward. Most of the time this is not important, but it does help you when you switch from one to other to know when the wheel actually mode the transistion.

My first version of this code did not do all of this, it simply counted how many interrupts happened. You can see this code in the thread:
lynxmotion.net/viewtopic.php?t=3496

If you would like to see the later code, let me know and I can post it as well:

Good Luck
Kurt