Pages: [1] 2   Go Down
Author Topic: Arduino Joystick Coding  (Read 1463 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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=
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If that doesn't help, post what code you have. Hopefully you are reading the joystick X, Y and Z values.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
God Member
*****
Karma: 27
Posts: 829
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?)
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 84
Posts: 3414
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Queens, New York
Offline Offline
Faraday Member
**
Karma: 84
Posts: 3414
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No cross posting!
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

UK
Offline Offline
Shannon Member
****
Karma: 222
Posts: 12541
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
« Last Edit: February 04, 2013, 10:43:36 pm by PeterH » Logged

I only provide help via the forum - please do not contact me for private consultancy.

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
God Member
*****
Karma: 27
Posts: 829
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Pages: [1] 2   Go Up
Jump to: