Joystick Control of 2 Motors

mdtest

New Member
Goal: To us a simple/cheap joystick to contol forward/reverse of 2 small motors.

Paramaters:
These motors will be used to move a small table (4"x4") on lead screws.
The j/s movement will be porpotional to the movement of the table.
This is NOT a stepper motor application, percision is relative and visual confirmed.
Limit switches will be used to limit the amount of travel in any direction.
The J/S will be tethered to the motors, no wireless requirement here.
The springs on the J/S will be removed so it won't auto center.
The movement of the J/S will change the potentiometers.
The motors will be low speed low voltage, under 5 volts.
A three way switch to toggle UV LEDs, White LEDs and all LEDs off.

Optional:
A single switch to overide the j/s to move the table to center.

Questions:
Which PicAxe is appropriate?

How do I make the j/s movement porpotional?

What have I not thought of?

Mike Duffy
 

MPep

Senior Member
Hi Mike,

Just a thought, but why not use Radio-Control servos?
There are equations in the manual to use Readadc, then use the result in Servo pos commands. Read the manual.

Picaxe type: how many other IO do you need? Maybe an 08M could do the job, 18X??
 

Rickharris

Senior Member
Goal: To us a simple/cheap joystick to contol forward/reverse of 2 small motors.

Paramaters:
These motors will be used to move a small table (4"x4") on lead screws.
The j/s movement will be porpotional to the movement of the table.
This is NOT a stepper motor application, percision is relative and visual confirmed.
Limit switches will be used to limit the amount of travel in any direction.
The J/S will be tethered to the motors, no wireless requirement here.
The springs on the J/S will be removed so it won't auto center.
If you remove the springs the joy stick will fall over if you let go. As you will have to keep hold all the time you may as well leave the springs in.

Unless you provide some kind of friction application to hold the position of the stick.
The movement of the J/S will change the potentiometers.
The motors will be low speed low voltage, under 5 volts.
A three way switch to toggle UV LEDs, White LEDs and all LEDs off.

You need to look at your joy stick - Many cheaper ones use the pots as a varable resistor and so only have 2 connections. To readadc (the pot position) the picaxe will expect a common ground with the joy stick and some voltage value between ground and the picaxe supply voltage. I have a joystick here that uses 3 volts!
Optional:
A single switch to overide the j/s to move the table to center.
To get the table to the centre you will need to have a micro switch on each axis or it will not be accurate over several operations. Why not use the automatic centering of the joystick?
Questions:
Which PicAxe is appropriate?

How do I make the j/s movement porpotional?

What have I not thought of?

Mike Duffy
Personally Depending on the application I think I would use some plain pots or linear pots - you can glue one linear pot on the top of another at right angles to get X Y movement like a joy stick.

The only benifit from using a joy stick is the mechanics and the USB interface to talk to the PC. Perhaps a better joy stick option woud be a radio control joystick. You can get the mechanisim bare.

Any picaxe that has 2 or more ADC channels and 4 outputs for the drive motors will do you job as far as you specify it )14M and up. You will need an H bridge to drive the motor to drive a lead screw you will need a fairly meaty motor unless the table is made of polystyrene foam!. I generally favour cordless drill motors for this type of activity as they have good torque properties and can be fairly cheap in the right shop.

Readadc breaks the input into 255 steps [8 bit] (readadc10 into 1024 steps [10 bit]) To give trully proportional movement you need to have an encoder on the lead screw to know how far it has turned. HOWEVER if you are eye balling te movement it matters not you will compensate yur movment of the joystick for the tables movement.




 
Last edited:

hippy

Ex-Staff (retired)
Design Cycles

Which PicAxe is appropriate?

Impossible to say without knowing what needs to be done to achieve the desired results for this ( and most other ) project. It really comes down to program code capacity and that will depend on how complicated your code needs to be, plus having enough I/O to handle necessary inputs and outputs.

Ideally you would determine your design then choose a PICAXE to suit, or multiple PICAXE's if that suits better. Alternatively you can choose a PICAXE and hope the design fits or limit the design to within that chip's capabilities, or simply pick the most capable PICAXE-40X1 and go with that.

In terms of design, in order to simplify things, consider the system as modular; a module which reads pots and creates X-Y co-ordinates, a module which takes X-Y co-ordinates and positions the motors as desired. It would make sense to start with a single motor module, duplicated twice. You can do the same with the three way switch if software is involved there; a module to read the switch and determine mode, a module to set LED's according to mode.

Some modules may be very simple, some incredibly complex ( if there is any accurate motor position feedback ), but each module will be as simple as it can be which aids design and also debugging when it comes to creating proof of concept, and test code. It also allows interaction and data flow between modules to be identified and will help prevent over-complicated designs and speeds the coding of modules; pot to X-Y, then X-Y to motor will ultimately ( trust me * ) be simpler and easier than pot direct to motor.

A typically good development process is requirements, specification, design, hardware choice then implementation and optimisation. Within that 'life-cycle process' there will be prototyping, testing and debugging with redesigns and other changes as become necessary. It's a process of 'continual refinement', overcoming issues which crop-up or had not been anticipated. Follow that model for all projects and there should be a satisfactory outcome.

In the real world, we all want to dive-in, get the project running and see something working as quickly as possible. In which case, do some basic design work, make an informed guess for which PICAXE to use, see how it goes but be prepared to have chosen a more capable or expensive chip than may be necessary, or an under-capable chip and have to change tack to finish the project.

(*) The big advantage to a modular design is you can change one software module usually without having to change anything else. If you want to change from a joystick to push-button, left, right, up, down control or even setting positional data from a PC over serial only that one module has to change. Likewise if you decided to later use stepper motors or include advanced positional feedback of the table you only need to change the X-Y to motor module.
 
Last edited:

Andrew Cowan

Senior Member
Step 1 - find a joystick.

The rest is then pretty simple.

Use readADC to find where the joystick is.
Work out if it is forward/backwards for each motor: scale it and add a reverse bit.
Check limit switches.
Send out PWM signals and reverse signals to an L239D (H bridge motor driver, 600mA max per motor)
Read the LED switch
Set the LEDs.
You need two PWM channels for this, as you have two motors. The smallest chip with this is the 28X1. You could use a smaller chip and two other chips (08Ms?) to do the PWM, but if you don't mind spending a few pounds more, the 28X1 is perfect.

If you want to go with hippy's way (lots of modules), maybe three 08Ms? (Motor X, Motor Y, Lights)...

A
 
Last edited:

BeanieBots

Moderator
I think Andrew might have OVER simplified things a bit there.
It's NOT that simple. For a start, you need to know where your motors are if they are to 'follow' the joystick. That requires feedback. That requires more pots (one for each motor) and it also means the PICAXE needs to read those pots as well AND it needs to read them FAST or the motors will shoot past where they are meant to be.

It can be done, but how well depends on fast your motors move and how good your postion control software is.

The simplest solution by far would be to go with MPep's suggestion of 'hobby' servos. This sort of thing is done all the time by RC'ers using 'hobby' servos. All the hard work of position control is taken care of within the servo.
 

Andrew Cowan

Senior Member
The j/s movement will be porpotional to the movement of the table.
This is NOT a stepper motor application, percision is relative and visual confirmed.
Limit switches will be used to limit the amount of travel in any direction.
Maybe I've misunderstood it, but to me it sounds like the joystick determines where the table moves - not where it is. Centre joystick = no momement, far left = move left full speed etc.

It would be more complex if you want centre joystick = centre table, far left = table far left (as BB mentions).

A
 

Dippy

Moderator
I think it needs clarifying.

My initial reading is as BB has said. But, I can understand the ambiguity too.

I read it as, for example, move the joystick halfway left and the table moves halfway left, nout to do with speed though I'm sure we'll get around to PID sooner or later. Servo like.

I interpreted "movement" as in "deflection from default/zero position".
 

hippy

Ex-Staff (retired)
If you want to go with hippy's way (lots of modules), maybe three 08Ms? (Motor X, Motor Y, Lights)...
Modules don't have to be in separate PICAXE's and at design stage it's usually best not to worry if they are or are not. Once the design is arrived at you can then determine which modules can be conveniently combined or are best as separate PICAXE's.

The advantage of everything all in one PICAXE is that there is no blocking involved in passing data from one module to another, it's there and ready in a variable. Once you get into multiple PICAXE's it's necessary to work out how to get the data over and what effect that has.

On the other hand, the modular design should also show up where problems may be; a single module waiting for INFRAIN and SERIN at the same time is not going to work so has to be devolved into smaller modules which will work.

Developing code for modules separately also means you will know its footprint. Two modules may each fit in a separate 08M but need an 18X if combined.

It also gives a specification for what each module has to do without worrying about other modules; that's why people designing engines don't particularly care about what vehicle(s) it will go in, the vehicle designer will have specified the engine requirements, and in turn the vehicle designers don't need to worry about what the engine is providing it meets those specification. Each team can deal with their task in hand without being side-tracked by the other team's issues. Things invariably go better when you only have one thing to deal with at a time, hence why we break tasks into steps, the principle of modularisation.

It may sound complicated or long-winded but it isn't really, and especially not with practice and it becoming second nature. Like installing a kitchen or putting anything together, if you just go out and buy the bits you think you need with no planning, something is very likely to go wrong, be missing, unnecessary, not fit, be too short, too long, not do the job and cause a lot of frustration along the way.
 

hippy

Ex-Staff (retired)
Here's a simple example of how modularisation can make what code is doing much clearer as well as easier to write ...

Do
Gosub ReadPotPercentage
Gosub SetPwmFrequency
Loop

ReadPotPercentage:
ReadAdc10 0,w0
percent = w0 * 50 / 511 ' 0..1023 -> 0..100
Return

SetPwmFrequency:
period = PWM_MAX - PWM_MIN * percent / 100 + PWM_MIN
duty = period * 2
PwmOut 3, period, duty
Return
 

Wrenow

Senior Member
Welcome back to the forum, Mike,

Hmmmm... A thought - IF you are moving the plate/stage within a frame. A couple of the Spectrasymbol linear pressure pots (long strips of plastic thet give a wiper read where it is pressed on) or their new magnetic version (non-contact - http://www.spectrasymbol.com/typo3/site/en/magnetopots/how-it-works.html) as the position feedback sensor for standard servo elsectonics (stripped out of a regular old hobby servo - or contiened in one so you get the gearbox as well). If you are going to use a standard servo to attach to your leadscrews, you might want to know what Servo City has tons of gears, sprockets, hubs and other adaters to set you up. http://servocity.com/html/mechanicals___accessories.html

If set up in this fashion, it becomes a simple matter of A read the joystick XY positions, send a servo comand for that position, very similar to the Robotic arm project in the manual. And, you could use the littlle 08 3 servo controller board, I believe, to save a bit of filtering, etc. development.

Cheers,

Wreno
 

mdtest

New Member
Thanks all for the input. For clarity, I was refering to porportional as to position of the table. Move the j/s left half way, the table moves half way to the left.

I have discussed this with the end users and they feel the porportional is not very important. I've decided to make the j/s simply turn the motor on and off. If j/s moved left, the x axis motor will move the table that way until a limit switch tripped or the j/s recentered. I will be leaving the springs on the j/s.

As I see it I have 2 options. readadc for each the x & y axis then
1) set an output high to energize a relay to move the motor in the correct direction.
or
2) set PWM for a L239D to drive the motor.

I realize that option 1 would be a constant speed of the motor. Would option 2 have the ability to be varialble speed? As I move the j/s further left, the motor spins faster?

Option 1 seems very simple and very straight forward. Are their other reasons to consider option 2?

By the way, I have found a great supplier for j/s's. http://www.feteriscomponents.nl//usa/usa-joysticks-detail-industrial.htm . Several of these have switches on the j/s - I will be able to use these switches to activate the lights and apply re-agents to the sample under the hood.

Again thanks for all the advise and suggestions.

Mike
 

Wrenow

Senior Member
OK. Seems to me, offhand, then that using ReadADC for the joystick, then doing the maths to get it in the right range, and outputting a servo signal to something like the http://robotpower.com/products/scorpion_mini_info.html would be a great solution. Interestingly, this little ESC has added a provision for limit switches.

This would give you adjustable speed on the movement, so you can get finer control over your X and Y axis.

you would, of course, need two of those ESCs, one each for X and Y.

That is an interesting little bugger, with a programmable microchip onboard, so it can be modified to I2C etc. No idea what language, etc. you need to use to program it, though.

Hope that helps.

Cheers,

Wreno
 
Top