View unanswered posts | View active topics It is currently Tue Oct 21, 2014 10:09 am






Reply to topic  [ 4 posts ] 
Arm & Claw joystick control 
Author Message
Rookie

Joined: Thu Nov 21, 2013 10:05 pm
Posts: 2
Post Arm & Claw joystick control
We currently have an arm and claw controlled by two motors (clawMotor and armMotor). Motors are controlled by channel 6 & 7 (default buttons on the front). This works ok but when we move the arm down it goes all the way down, making it hard to pick stuff up, also the same thing with the claw, it closes all the way. What we would like is the left joy-stick to control both the arm and claw, move the are up/down and open and close the claw, we have the rightMotor and leftMotor working on the right joy-stick great and think we can get much better control with the joy-stick. We would be grateful for any help you can provide.


Fri Nov 22, 2013 1:05 pm
Profile
Site Admin
Site Admin
User avatar

Joined: Tue Oct 09, 2012 10:34 am
Posts: 192
Post Re: Arm & Claw joystick control
Hi RKLinke,
Please post your code between [code][/code] tags. It's hard to help you only based on your description.

Thanks,
--Ryan

_________________
Ryan Cahoon
CMU Robotics Academy
RVW Software Developer

Robot Potato Head; Virtual NXT


Wed Dec 11, 2013 3:58 pm
Profile
Rookie

Joined: Thu Nov 21, 2013 10:05 pm
Posts: 2
Post Re: Arm & Claw joystick control
Attached is the code that we are using now, I found some information and coded this up and it works better but still has some lag time on the down arm movement (still wants to keep going down for a bit) and on the claw too. I have bought two 393 Integrated Encoder Module thinking we could stop it at a given point but have not found any code to do that.
Also right now one controller is running the clwbot with the right joystick doing the driving and the other joystick moving the claw & arm we would like to move the claw & arm to the second joystick but again don’t know how to do that….. Any help with codding and moving the claw/arm would be great….


Code:
#pragma config(Motor,  port1,           leftMotor,     tmotorVex393, openLoop, reversed)
#pragma config(Motor,  port6,           clawMotor,     tmotorVex393, openLoop, reversed)
#pragma config(Motor,  port7,           armMotor,      tmotorVex393, openLoop, reversed)
#pragma config(Motor,  port10,          rightMotor,    tmotorVex393, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

/*----------------------------------------------------------------------------------------------------*\
|*                                - Clawbot Single Joystick Control -                                 *|
|*                                      ROBOTC on VEX 2.0 Cortex                                      *|
|*                                                                                                    *|
|*  This program uses a single joystick, either right or left to drive the robot. Use notes below     *|
|*  to reconfigure which joystick is used. The joystick buttons are used to raise and lower the arm.   *|
|*  The joystick buttons are used to open and close the claw.                                                               *|
|*                                                                                                                                                      *|
|*                                        ROBOT CONFIGURATION                                         *|
|*    NOTES:                                                                                          *|
|*    1)   Ch1 is the X axis and Ch2 is the Y axis for the RIGHT joystick.                             *|
|*    2)   Ch3 is the Y axis and Ch4 is the X axis for the LEFT joystick.                              *|
|*      3)   Button 5U and 5L are on the front left side of the joystick.                                                *|
|*      3)   Button 6U and 6L are on the front right side of the joystick.                                                *|
|*                                                                                                    *|
|*    MOTORS & SENSORS:                                                                               *|
|*    [I/O Port]        [Name]          [Type]                               [Description]            *|
|*    Motor - Port 2   rightMotor    VEX 393 Motor                         Right drive motor          *|
|*    Motor - Port 6   clawMotor     VEX 393 Motor w/ Motor Controler 29   Claw motor                 *|
|*    Motor - Port 7   armMotor      VEX 393 Motor w/ Motor Controler 29   Arm motor                  *|
|*    Motor - Port 10  leftMotor     VEX 393 Motor                         Left drive motor           *|
\*----------------------------------------------------------------------------------------------------*/

//+++++++++++++++++++++++++++++++++++++++++++++| MAIN |+++++++++++++++++++++++++++++++++++++++++++++++
task main ()
{
  int threshold = 10;   // helps to eliminate 'noise' from a joystick that isn't perfectly at (0,0)
                        // feel free to change this to match your needs.
   while(1 == 1)
   {

 if(abs(vexRT[Ch3]) > threshold)         // If the left joystick is greater than or less than the threshold:
    {
      motor[armMotor]  = (vexRT[Ch3])/2;   // Left Joystick Y value / 2.
    }
    else                                    // If the left joystick is within the threshold:
    {
      motor[armMotor]  = 0;                // Stop the left motor (cancel noise)
    }

    if(abs(vexRT[Ch4]) > threshold)         // If the right joystick is greater than or less than the threshold:
    {
      motor[clawMotor] = (vexRT[Ch4])/2;   // Right Joystick Y value / 2.
    }
    else                                    // If the right joystick is within the threshold:
    {
      motor[clawMotor] = 0;                // Stop the claw motor (cancel noise)
    }
    motor[leftMotor]  = (vexRT[Ch2] + vexRT[Ch1])/2;  // (y + x)/2
      motor[rightMotor] = (vexRT[Ch2] - vexRT[Ch1])/2;  // (y - x)/2
// Raise, lower or do not move arm
//  * old line of code   motor[armMotor]  = (vexRT[Ch3] + vexRT[Ch3])/2;  // (y + x)/2

// Open, close or do not more claw
//  * old line of code   motor[clawMotor]  = (vexRT[Ch4] + vexRT[Ch4])/2;  // (y + x)/2
      }
   }
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


Sun Dec 22, 2013 10:34 am
Profile
Site Admin
Site Admin
User avatar

Joined: Tue Oct 09, 2012 10:34 am
Posts: 192
Post Re: Arm & Claw joystick control
Hi RKLinke,

To use controls on the second controller, just add Xmtr2 to the end of any of the axis or button names, e.g. Ch1Xmtr2.

Your code looks fine to me. Any lag you're seeing is probably beyond your control. Using the encoders to add stops would be one option. Another would be to mechanically limit the range of motion of your various joints. To limit the motion of using encoders, you would use code something like this:
Code:
if(vexRT[Ch3] > threshold && nMotorEncoder[armMotor] < upperLimit)         // If the left joystick is above the deadzone and arm is below the upper limit:
{
  motor[armMotor]  = (vexRT[Ch3])/2;   // Left Joystick Y value / 2.
}
else if(vexRT[Ch3] < -threshold && nMotorEncoder[armMotor] > lowerLimit)   // If the left joystick is below the deadzone and arm is above the lower limit:
{
  motor[armMotor]  = (vexRT[Ch3])/2;   // Left Joystick Y value / 2.
}
else                                                                       // If the left joystick is within the deadzone or we're trying to move outside the limits:
{
  motor[armMotor]  = 0;                // Stop the left motor (cancel noise)
}

Note that you may need to reverse the limit checks, depending on the direction of movement that the encoders consider positive.

Something else to try would be a similar bit of code, but without the encoders, which allows you to slow down the down movement of the arm to compensate for gravity:
Code:
if(vexRT[Ch3] > threshold)         // If the left joystick is above the deadzone
{
  motor[armMotor]  = (vexRT[Ch3])/2;   // Left Joystick Y value / 2.
}
else if(vexRT[Ch3] < -threshold)   // If the left joystick is below the deadzone
{
  motor[armMotor]  = (vexRT[Ch3])/3;   // Left Joystick Y value / 2.
}
else                                                                       // If the left joystick is within the deadzone
{
  motor[armMotor]  = 0;                // Stop the left motor (cancel noise)
}

_________________
Ryan Cahoon
CMU Robotics Academy
RVW Software Developer

Robot Potato Head; Virtual NXT


Wed Dec 25, 2013 2:29 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


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

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.