Go Down

Topic: Arduino Joystick Coding (Read 2006 times) previous topic - next topic

stevekap25

For my senior design project, I need to modify a go-kart for our client.  Our client has cerebral palsy and cannot drive a normal go-kart; therefore we need to make this go-kart joystick accessible.  We are in the process of connecting an 8-way joystick  to the Arduino Due  in hopes of the following:
- Movement in positive y will accelerate
- Movement in negative y will brake
- Movement in positive x/y will turn the wheels right/left

3 pins of the Arduino are then outputted to Motor Driver which is connected to 3 actuators to power the acceleration, braking, and steering.  Our goal is when he moves the joystick in any direction, the Arduino will read the input and supply a voltage to the driver which will then power the corresponding actuator.  My group for some reason cannot get past the coding though.  We are novices with the Arduino coding as this is our first time working with this microprocessor.  We normally would not ask a question this advanced, but since this is going to a good cause we are hopeful that you might be able to help. If not, is there anyone you would recommend talking with.

stevekap25

For my senior design project, I need to modify a go-kart for our client.  Our client has cerebral palsy and cannot drive a normal go-kart; therefore we need to make this go-kart joystick accessible.  We are in the process of connecting an 8-way joystick  to the Arduino Due  in hopes of the following:
- Movement in positive y will accelerate
- Movement in negative y will brake
- Movement in positive x/y will turn the wheels right/left

3 pins of the Arduino are then outputted to Motor Driver which is connected to 3 actuators to power the acceleration, braking, and steering.  Our goal is when he moves the joystick in any direction, the Arduino will read the input and supply a voltage to the driver which will then power the corresponding actuator.  My group for some reason cannot get past the coding though.  We are novices with the Arduino coding as this is our first time working with this microprocessor.  We normally would not ask a question this advanced, but since this is going to a good cause we are hopeful that you might be able to help. If not, is there anyone you would recommend talking with.

zoomkat

Reading material

https://www.google.com/search?hl=en&as_q=joystick&as_epq=&as_oq=&as_eq=&as_nlo=&as_nhi=&lr=&cr=&as_qdr=all&as_sitesearch=http%3A%2F%2Farduino.cc%2Fforum%2F&as_occt=any&safe=images&tbs=&as_filetype=&as_rights=
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

Nick Gammon

If that doesn't help, post what code you have. Hopefully you are reading the joystick X, Y and Z values.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Nick Gammon

It would also help to post a link to the joystick in question, and the motors. We can't read minds you know.

Read this before posting a programming question
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

stevekap25

Thank you for your help, sorry for not posting the objects being used

Arduino Due as the microprocessor
8-way universal joystick http://na.suzohapp.com/joysticks/universal_joy.htm
Using a motor driver - VNH5019 Motor Driver Carrier

As of now, our code is not working at all.  We would like to start over at best due to the fact that we are very inexperienced

Retroplayer

Connect the joystick pots to the arduino A0 and A1 lines, then just do analogRead to get their values. If the joystick is self-centering, then the initial reading is your center. Moving one way will increase the reading and moving the other will decrease the reading. Compare these against the initial reading to determine the direction.

However, I am not sure how you are going to control three actuators with just three pins when you need forward and reverse for each motor for drive and steering. For steering, you will need two pins (and possibly an enable signal) to do forward/reverse of the motor. For the acceleration and braking, you will need 2 pins (and possibly an enable) for forward/reverse. You could probably get away with just one line for braking, though. If you use the electronic brake on most H-Bridge circuits, you just reuse the forward/reverse lines (setting them both HIGH at the same time) to brake.

How will you be controlling speed? Through PWM or using a commercial ESC (electronic speed controller?)

HazardsMind

The code is very simple.

If X is greater than 0, go forward.
Else if X is less than 0, go backward.
Else stop

Same with Y.

Usual joysticks are analog which means they have a measured value between 0 and 1023.
So half of 1023,=> 512, would be your "0", so anything greater than 512 would go forward.
Less than, reverse, and is 512, stop.
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

liudr

A bit dangerous to have a stick control both turning and acceleration/brake. If someone pushes the stick to a corner, it's gonna be a bad day (accelerating and turning with almost full strength at the same time).

Post your code.

HazardsMind

My GitHub:
https://github.com/AndrewMascolo?tab=repositories

PeterH

#10
Feb 05, 2013, 04:23 am Last Edit: Feb 05, 2013, 04:43 am by PeterH Reason: 1
I recommend that you make the steering control speed sensitive, with steering authority reducing as the speed rises. Also consider designing the speed control so that 'full throttle' ramps the power up progressively rather than slamming you into full power. (I guess there will be plenty of cross-talk between steering and throttle inputs when it's being used by somebody with poor limb control.)

If you're planning to use a conventional IC gokart then the controls are likely to be quite heavy so you'll need a substantial power supply. Make sure you consider what happens if the supply fails or the battery goes flat while the kart is in motion. Also I'd think that safety might be a major concern - have you addressed that aspect thoroughly?
I only provide help via the forum - please do not contact me for private consultancy.

liudr

Cross posting is bad! Ask everyone to forgive you and admin to combine posts!

Nick Gammon

Please do not cross-post. This wastes time and resources as people attempt to answer your question on multiple threads.

Quote
... we are very inexperienced ...


Are you inexperienced in general forum etiquette, too?

Threads merged.

- Moderator
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Retroplayer

Ahh, now I see that you are using a digital joystick. So, forget the analog pins. You will need to manually increase and decrease acceleration based on how long the joystick is pushed forward/backward. Basically a timer that checks the switch for its state and if it is still low, it will increase/decrease the speed. How that is done depends on how you are controlling speed (ESC, H-bridge with PWM?)

And I agree with the poster above that using the same joystick for both steering and speed could be dangerous. A wheelchair does this, yes, but it is using two wheels and going rather slow. I do assume that your disabled client knows how to use these controls, though since that IS how a wheelchair is operated. Just understand that at high speeds, there is going to be jerking of the rider going on, which may cause unwanted pushes of the joystick.

You can counteract that in the control scheme mentioned above. Check the state of the switches on timer. Then if a sudden bump happens, it will not accelerate/decelerate. Only when the stick is continually held in a direction will it respond.

zoomkat

If you are looking for analog joysticks, the below might be of interest.

http://www.ebay.com/itm/3-X-New-Handle-Joystick-3D-for-Sony-Playstation2-PS2-PS-2-10V-/230803703512?pt=LH_DefaultDomain_0&hash=item35bcf906d8
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

Go Up