View unanswered posts | View active topics It is currently Sun Aug 28, 2016 11:43 pm

 Page 1 of 1 [ 3 posts ]
 Print view Previous topic | Next topic
Controlling 1 Motor with 2 Joysticks
Author Message
Rookie

Joined: Mon Dec 19, 2011 5:06 pm
Posts: 2
Controlling 1 Motor with 2 Joysticks
We are trying to control a motor with two joysticks. One joystick turns the motor on at low power when a load is not applied. The second joystick turns the motor on at a high power when a load is applied. We tried programming this, but only one of the joysticks would work, while the other one caused the motor to attempt to move but failed. Here's the code we used:

if (joystick.joy2_y1 > 0) {
motor[arm] = joystick.joy2_y1/2;
}
if (joystick.joy2_y1 < 0)
{
motor[arm] = joystick.joy2_y1/100;
}
if (joystick.joy2_y2 > 0)
{
motor[arm] = joystick.joy2_y2;
}
if (joystick.joy2_y2 < 0)
{
motor[arm] = joystick.joy2_y2/90;
}

Is it possible to control a single motor with 2 joysticks? If so, what's wrong with our code?

Mon Dec 19, 2011 5:22 pm
Expert

Joined: Thu Sep 29, 2011 11:09 pm
Posts: 184
Location: Michigan USA
Re: Controlling 1 Motor with 2 Joysticks
Well, one thing I see, is that you are assuming that if you aren't using the joystick, the value will be 0. Due to tolerance issues, this is not true.

A couple more things:
You should give preference to one of the joysticks to prevent further issues. Try rearranging the logic.
Why is it that in one direction you give the motor a lot more power than you do in the other direction? I am guessing this has to do with gravity in the real world.

Try something like this:
 Code:#define THRESHOLD 5if (joystick.joy2_y1 > THRESHOLD) {   motor[arm] = joystick.joy2_y1/2;}else if (joystick.joy2_y1 < -THRESHOLD){   motor[arm] = joystick.joy2_y1/100;}else if (joystick.joy2_y2 > THRESHOLD){   motor[arm] = joystick.joy2_y2;}else if (joystick.joy2_y2 < -THRESHOLD){   motor[arm] = joystick.joy2_y2/90;}

Also note, that dividing the joystick value by 100 will only allow the motor value to be 0 or 1 (same with /90).

_________________
Matt

Mon Dec 19, 2011 6:00 pm
Guru

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
Re: Controlling 1 Motor with 2 Joysticks
First, you did not post the whole code. I assume your code is inside a forever while-loop. Secondly, your code is fighting to move the motor. If both joysticks are active, one will try to program the arm motor one way and the other will try to program it the other way. Since you did not use deadband, both of your joysticks are likely active at the same time (non-zero). I am not sure if I understand what you want to do exactly, but it sounds like you want to control the arm with the joystick but may want to slow it down if there is no load. If that's the case, you don't really need 2 joysticks. How about using just one joystick to control the arm at lower speed but when a button is pressed and held, then it will apply more power.

Since I don't know what power you want under which circumstances, the above code is just an example. Feel free to change the scale factor. Basically, if button 1 is pressed, the above code will run the arm "forward" full speed and half speed reverse. If button 1 is released, it will run the arm "forward" half speed and quarter speed in reverse.

Mon Dec 19, 2011 6:35 pm
Display posts from previous:  Sort by
 Page 1 of 1 [ 3 posts ]

Who is online

Users browsing this forum: No registered users and 1 guest

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning