View unanswered posts | View active topics It is currently Mon Oct 15, 2018 11:39 pm






Reply to topic  [ 2 posts ] 
Creating a driver control program for VEX IQ Controller 
Author Message
Rookie

Joined: Tue Nov 24, 2015 2:45 am
Posts: 1
Post Creating a driver control program for VEX IQ Controller
We are currently on a 10 Day Trial on RobotC. We really like the virtual world with RobotC and are trying to create a driver control for our competition robot. If we can make it work, we want to continue using RobotC.

We have used MODKit for a year now, but have experienced a few "glitches" during our autonomous programs. In some cases, we had to add 3 second waits to keep the program from overlapping commands. In other cases, sometimes one drive motor did not work during turns and other times it worked (perhaps due to the weight of our robot?).

We often use multiple buttons along with the joystick simultaneously. We use buttons to turn on and keep on a motor and another to turn it off. We also use a button to set a hold function on a motor. We have tried to set up a program but are not sure how to insure multiple buttons run at the same time and not have to wait for its turn in the queue.

Attached is our current controller setup, well it is missing an additional program for L Down that reverses the Lift motor. Also E up controls the drive motor and sets another motor into reverse.

All of our searches resulted in Basic Programming. We discover the repeat forever and the while with controller button, but we are still confused.

Here's what we started:

#pragma config(Sensor, port2, touchLED, sensorVexIQ_LED)
#pragma config(Sensor, port3, colorDetector, sensorVexIQ_ColorHue)
#pragma config(Sensor, port4, gyroSensor, sensorVexIQ_Gyro)
#pragma config(Sensor, port7, distanceMM, sensorVexIQ_Distance)
#pragma config(Motor, motor1, BallShooter, tmotorVexIQ, openLoop, reversed, encoder)
#pragma config(Motor, motor5, BallMover, tmotorVexIQ, PIDControl, reversed, encoder)
#pragma config(Motor, motor6, RightDrive, tmotorVexIQ, openLoop, reversed, driveRight, encoder)
#pragma config(Motor, motor8, BallLift, tmotorVexIQ, PIDControl, reversed, encoder)
#pragma config(Motor, motor11, LeftDrive, tmotorVexIQ, openLoop, driveLeft, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//


task main()
{
repeat (forever) {
arcadeControl(ChA, ChC, 127);
while (getJoystickValue(BtnRUp) == 1) {
moveMotor(BallLift, 270, degrees, 50);
stopMotor(BallLift);
}
while (getJoystickValue(BtnRDown) == 1) {
moveMotor(BallLift, 720, rotations, 50);
}
if (getJoystickValue(BtnLDown) == 1) {
moveMotor(BallLift, -720, rotations, 50);
}

We stopped after questioning how we will make multiple buttons work at the same time. We are also unsure if we are coding it correctly.

Any help you can offer would be great.


Attachments:
Controller.png
Controller.png [ 259.46 KiB | Viewed 13079 times ]
Tue Nov 24, 2015 3:16 am
Profile
Moderator
Moderator

Joined: Tue May 19, 2015 3:07 pm
Posts: 91
Post Re: Creating a driver control program for VEX IQ Controller
It looks like your program is a mesh of functions from when you used RVW to practice autonomous and getJoystick functions. My biggest suggestion is to look at the ROBOTC sample programs (File -> Open Sample Programs -> Remote Control)

Here is one of them just so you know what I am talking about.

Code:
#pragma config(Motor,  motor1,          leftMotor,     tmotorVexIQ, openLoop, encoder)
#pragma config(Motor,  motor6,          rightMotor,    tmotorVexIQ, openLoop, reversed, encoder)
#pragma config(Motor,  motor10,         armMotor,      tmotorVexIQ, openLoop, encoder)
#pragma config(Motor,  motor11,         clawMotor,     tmotorVexIQ, openLoop, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

/*------------------------------------------------------------------------------------------------
  This program will use the VEX IQ Wirless Controller to drive your Clawbot. This program uses
  If/Else statements to provide a "threshold" for the transmitter - this allows your robot to
  come to a stop even if the joysticks on the Wireless Controller haven't perfectly returned to
  their zero position.

  Note: You will have to set ROBOTC to enable "Wireless Control" to use the VEX IQ joystick.

                            ROBOT CONFIGURATION: VEX IQ Clawbot
    MOTORS & SENSORS:
    [I/O Port]          [Name]              [Type]                         [Location]
    Port 1                 leftMotor           VEX IQ Motor                     Left side motor
    Port 6                   rightMotor          VEX IQ Motor                     Right side motor (reversed)
      Port 10                     armMotor                  VEX IQ Motor                        Arm Up/Down motor
      Port 11                     clawMotor                  VEX IQ Motor                        Claw Open/Close motor
------------------------------------------------------------------------------------------------*/

task main()
{
   int threshold = 10;
   static int leftSpeed = 0;
   static int rightSpeed = 0;

   while(true)
   {
      leftSpeed = (getJoystickValue(ChA) - getJoystickValue(ChB)/2);   // (y - x)/2
      rightSpeed = (getJoystickValue(ChA) + getJoystickValue(ChB)/2);   // (y + x)/2

      if(leftSpeed > threshold || leftSpeed < -threshold)
      {
         setMotorSpeed(leftMotor, leftSpeed);
      }
      else
      {
         setMotorSpeed(leftMotor, 0);
      }

      if(rightSpeed > threshold || rightSpeed < -threshold)
      {
         setMotorSpeed(rightMotor, rightSpeed);
      }
      else
      {
         setMotorSpeed(rightMotor, 0);
      }

      //If Button "L-Up" is pressed in, we'll set the arm motor to run in reverse.
      if(getJoystickValue(BtnLUp) == 1)
      {
         setMotorSpeed(armMotor, -127);
      }
      //If the "L-Up" isn't pressed, but "L-Down" is, we'll set the motor to run forward.
      else if(getJoystickValue(BtnLDown) == 1)
      {
         setMotorSpeed(armMotor, 127);
      }
      else  //If neither button is pressed, we'll set the motor off.
      {
         setMotorSpeed(armMotor, 0);
      }

      //If Button "L-Up" is pressed in, we'll set the arm motor to run in reverse.
      if(getJoystickValue(BtnRUp) == 1)
      {
         setMotorSpeed(clawMotor, -127);
      }
      //If the "L-Up" isn't pressed, but "L-Down" is, we'll set the motor to run forward.
      else if(getJoystickValue(BtnRDown) == 1)
      {
         setMotorSpeed(clawMotor, 127);
      }
      else   //If neither button is pressed, we'll set the motor off.
      {
         setMotorSpeed(clawMotor, 0);
      }
   }
}


The main code that looks pertinent to you would be
Code:
if(getJoystickValue(BtnRUp) == 1)
      {
         setMotorSpeed(clawMotor, -127);
      }

Remember because of the while loop (or repeat forever loop because they are the same) your code is run over and over again. So just if the button is pressed turn on the motor is all you need rather than while button. The other part is setting motor speeds rather than moving motor. This is how you would code something where you want a button to turn on the motor and then another similar command to turn the motor back off.


Sat Nov 28, 2015 7:40 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 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:  
cron



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