View unanswered posts | View active topics It is currently Mon Sep 01, 2014 9:02 pm






Reply to topic  [ 25 posts ]  Go to page Previous  1, 2
robotc error 
Author Message
Rookie
User avatar

Joined: Wed Feb 22, 2012 9:04 am
Posts: 20
Location: behind you
Post Re: robotc error
can anyone tell me how to make the joysticks control the movement of the robot, currently the tophat controls it.

Code:
#pragma config(Hubs,  S1, HTMotor,  HTMotor,  HTMotor,  HTMotor)
#pragma config(Hubs,  S2, HTServo,  HTServo,  none,     none)
#pragma config(Sensor, S1,     ,               sensorI2CMuxController)
#pragma config(Sensor, S2,     ,               sensorI2CMuxController)
#pragma config(Motor,  mtr_S1_C1_1,     leftdrive,     tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C1_2,     rightdrive,    tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C2_1,     armupdown,     tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C2_2,     armleftright,  tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C3_1,     motorH,        tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C3_2,     motorI,        tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C4_1,     motorJ,        tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C4_2,     motorK,        tmotorNormal, openLoop)
#pragma config(Servo,  srvo_S2_C1_1,    claw,                 tServoStandard)
#pragma config(Servo,  srvo_S2_C1_2,    unkwown,              tServoStandard)
#pragma config(Servo,  srvo_S2_C1_3,    servo3,               tServoNone)
#pragma config(Servo,  srvo_S2_C1_4,    servo4,               tServoNone)
#pragma config(Servo,  srvo_S2_C1_5,    servo5,               tServoNone)
#pragma config(Servo,  srvo_S2_C1_6,    servo6,               tServoNone)
#pragma config(Servo,  srvo_S2_C2_1,    servo7,               tServoNone)
#pragma config(Servo,  srvo_S2_C2_2,    servo8,               tServoNone)
#pragma config(Servo,  srvo_S2_C2_3,    servo9,               tServoNone)
#pragma config(Servo,  srvo_S2_C2_4,    servo10,              tServoNone)
#pragma config(Servo,  srvo_S2_C2_5,    servo11,              tServoNone)
#pragma config(Servo,  srvo_S2_C2_6,    servo12,              tServoNone)


/**
 * Project Name: TEST robot rotational arm
 * Description:  program for a robot with a rotational arm on top with a claw
 * Version: 1
 *
 * This teleop file was generated using Teleop Catalyst for RobotC Version 1.4 beta on 2/23/2012.
 * Learn more about Teleop Catalyst at: http://ftc.kcastromechs.org/catalyst
 *
 * Feel free to modify this code as much as you'd like, as long as you keep this comment
 * block, in its unaltered form, somewhere in your code. Thanks!
**/

//// Include Files:
#include "JoystickDriver.c";

//// Function Prototypes:
// Initialize function (auto-executed when teleop period begins):
void initialize();

// "Event Handlers" for gamepad 1:
void g1_btn6_t_handler();
void g1_btn5_t_handler();
void g1_btn8_t_handler();
void g1_btn7_t_handler();
void g1_tHat_btn6_t_handler();
void g1_tHat_btn2_t_handler();
void g1_tHat_btn0_t_handler();
void g1_tHat_btn4_t_handler();
void g1_btn1_t_handler();
void g1_btn3_t_handler();
void g1_btn4_t_handler();
void g1_btn2_t_handler();
void g1_btn11_t_handler();
void g1_btn12_t_handler();

// Execute function(s) for gamepad 1:
void g1_btn6_t_execute();
void g1_btn5_t_execute();
void g1_btn8_t_execute();
void g1_btn7_t_execute();
void g1_tHat_btn6_t_execute();
void g1_tHat_btn2_t_execute();
void g1_tHat_btn0_t_execute();
void g1_tHat_btn4_t_execute();
void g1_btn1_t_execute();
void g1_btn3_t_execute();
void g1_btn4_t_execute();
void g1_btn2_t_execute();
void g1_btn11_t_execute();
void g1_btn12_t_execute();

float deadband(float power);

// Your custom functions:

//// Global Booleans:
// Booleans for Gamepad 1:
bool g1_btn6_toggledOn = false;
bool g1_btn6_flag = false;
bool g1_btn5_toggledOn = false;
bool g1_btn5_flag = false;
bool g1_btn8_toggledOn = false;
bool g1_btn8_flag = false;
bool g1_btn7_toggledOn = false;
bool g1_btn7_flag = false;
bool g1_tHat_btn6_toggledOn = false;
bool g1_tHat_btn6_flag = false;
bool g1_tHat_btn2_toggledOn = false;
bool g1_tHat_btn2_flag = false;
bool g1_tHat_btn0_toggledOn = false;
bool g1_tHat_btn0_flag = false;
bool g1_tHat_btn4_toggledOn = false;
bool g1_tHat_btn4_flag = false;
bool g1_btn1_toggledOn = false;
bool g1_btn1_flag = false;
bool g1_btn3_toggledOn = false;
bool g1_btn3_flag = false;
bool g1_btn4_toggledOn = false;
bool g1_btn4_flag = false;
bool g1_btn2_toggledOn = false;
bool g1_btn2_flag = false;
bool g1_btn11_toggledOn = false;
bool g1_btn11_flag = false;
bool g1_btn12_toggledOn = false;
bool g1_btn12_flag = false;

/// Joystick values:
float g1_joy1_y1;
float g1_joy1_y2;

/// Variables for driveSwap, slowDown, and deadban features:
float deadbandValue  = 10;   // Deadband is a "neutral zone" where nothing happens.
float slowDownFactor = 1;    // May be used to reduce the speed of the robot/increase sensitivity.
float joySwap = 1;           // May be used to swap the driving direction of the robot. 1 means forward = forward, -1 means forward = backwards

task main()
{
   initialize();   // Run the initialization code.

   while (true)
   {
      getJoystickSettings(joystick);

      if (!joystick.StopPgm && joystick.UserMode)
      {
         g1_btn6_t_handler();
         g1_btn5_t_handler();
         g1_btn8_t_handler();
         g1_btn7_t_handler();
         g1_tHat_btn6_t_handler();
         g1_tHat_btn2_t_handler();
         g1_tHat_btn0_t_handler();
         g1_tHat_btn4_t_handler();
         g1_btn1_t_handler();
         g1_btn3_t_handler();
         g1_btn4_t_handler();
         g1_btn2_t_handler();
         g1_btn11_t_handler();
         g1_btn12_t_handler();

         // Update variables with joystick values:
         g1_joy1_y1 = joystick.joy1_y1;
         g1_joy1_y2 = joystick.joy1_y2;

         // Update the power of the drive motors with that of the joystick values:
      }
   }
}

void initialize()
{
   /*
      Everything in here is executed at the beginning of the teleop period.
      When the music plays, this stuff happens!
   */

   //initialization code goes here
}

float deadband(float power) {
   if (abs(power) < deadbandValue) {
      return 0;
   } else {
      return power;
   }
}

//custom functions & tasks (0)

void g1_btn6_t_handler()
{
   if (joy1Btn(6)) {
      g1_btn6_flag = true;
   } else if (g1_btn6_flag) {
      g1_btn6_flag = false;
      if (g1_btn6_toggledOn) {
         g1_btn6_toggledOn = false;
      } else {
         g1_btn6_toggledOn = true;
      }
      g1_btn6_t_execute();
   }
}

void g1_btn5_t_handler()
{
   if (joy1Btn(5)) {
      g1_btn5_flag = true;
   } else if (g1_btn5_flag) {
      g1_btn5_flag = false;
      if (g1_btn5_toggledOn) {
         g1_btn5_toggledOn = false;
      } else {
         g1_btn5_toggledOn = true;
      }
      g1_btn5_t_execute();
   }
}

void g1_btn8_t_handler()
{
   if (joy1Btn(8)) {
      g1_btn8_flag = true;
   } else if (g1_btn8_flag) {
      g1_btn8_flag = false;
      if (g1_btn8_toggledOn) {
         g1_btn8_toggledOn = false;
      } else {
         g1_btn8_toggledOn = true;
      }
      g1_btn8_t_execute();
   }
}

void g1_btn7_t_handler()
{
   if (joy1Btn(7)) {
      g1_btn7_flag = true;
   } else if (g1_btn7_flag) {
      g1_btn7_flag = false;
      if (g1_btn7_toggledOn) {
         g1_btn7_toggledOn = false;
      } else {
         g1_btn7_toggledOn = true;
      }
      g1_btn7_t_execute();
   }
}

void g1_tHat_btn6_t_handler()
{
   if (joystick.joy1_TopHat == 6) {
      g1_tHat_btn6_flag = true;
   } else if (g1_tHat_btn6_flag) {
      g1_tHat_btn6_flag = false;
      if (g1_tHat_btn6_toggledOn) {
         g1_tHat_btn6_toggledOn = false;
      } else {
         g1_tHat_btn6_toggledOn = true;
      }
      g1_tHat_btn6_t_execute();
   }
}

void g1_tHat_btn2_t_handler()
{
   if (joystick.joy1_TopHat == 2) {
      g1_tHat_btn2_flag = true;
   } else if (g1_tHat_btn2_flag) {
      g1_tHat_btn2_flag = false;
      if (g1_tHat_btn2_toggledOn) {
         g1_tHat_btn2_toggledOn = false;
      } else {
         g1_tHat_btn2_toggledOn = true;
      }
      g1_tHat_btn2_t_execute();
   }
}

void g1_tHat_btn0_t_handler()
{
   if (joystick.joy1_TopHat == 0) {
      g1_tHat_btn0_flag = true;
   } else if (g1_tHat_btn0_flag) {
      g1_tHat_btn0_flag = false;
      if (g1_tHat_btn0_toggledOn) {
         g1_tHat_btn0_toggledOn = false;
      } else {
         g1_tHat_btn0_toggledOn = true;
      }
      g1_tHat_btn0_t_execute();
   }
}

void g1_tHat_btn4_t_handler()
{
   if (joystick.joy1_TopHat == 4) {
      g1_tHat_btn4_flag = true;
   } else if (g1_tHat_btn4_flag) {
      g1_tHat_btn4_flag = false;
      if (g1_tHat_btn4_toggledOn) {
         g1_tHat_btn4_toggledOn = false;
      } else {
         g1_tHat_btn4_toggledOn = true;
      }
      g1_tHat_btn4_t_execute();
   }
}

void g1_btn1_t_handler()
{
   if (joy1Btn(1)) {
      g1_btn1_flag = true;
   } else if (g1_btn1_flag) {
      g1_btn1_flag = false;
      if (g1_btn1_toggledOn) {
         g1_btn1_toggledOn = false;
      } else {
         g1_btn1_toggledOn = true;
      }
      g1_btn1_t_execute();
   }
}

void g1_btn3_t_handler()
{
   if (joy1Btn(3)) {
      g1_btn3_flag = true;
   } else if (g1_btn3_flag) {
      g1_btn3_flag = false;
      if (g1_btn3_toggledOn) {
         g1_btn3_toggledOn = false;
      } else {
         g1_btn3_toggledOn = true;
      }
      g1_btn3_t_execute();
   }
}

void g1_btn4_t_handler()
{
   if (joy1Btn(4)) {
      g1_btn4_flag = true;
   } else if (g1_btn4_flag) {
      g1_btn4_flag = false;
      if (g1_btn4_toggledOn) {
         g1_btn4_toggledOn = false;
      } else {
         g1_btn4_toggledOn = true;
      }
      g1_btn4_t_execute();
   }
}

void g1_btn2_t_handler()
{
   if (joy1Btn(2)) {
      g1_btn2_flag = true;
   } else if (g1_btn2_flag) {
      g1_btn2_flag = false;
      if (g1_btn2_toggledOn) {
         g1_btn2_toggledOn = false;
      } else {
         g1_btn2_toggledOn = true;
      }
      g1_btn2_t_execute();
   }
}

void g1_btn11_t_handler()
{
   if (joy1Btn(11)) {
      g1_btn11_flag = true;
   } else if (g1_btn11_flag) {
      g1_btn11_flag = false;
      if (g1_btn11_toggledOn) {
         g1_btn11_toggledOn = false;
      } else {
         g1_btn11_toggledOn = true;
      }
      g1_btn11_t_execute();
   }
}

void g1_btn12_t_handler()
{
   if (joy1Btn(12)) {
      g1_btn12_flag = true;
   } else if (g1_btn12_flag) {
      g1_btn12_flag = false;
      if (g1_btn12_toggledOn) {
         g1_btn12_toggledOn = false;
      } else {
         g1_btn12_toggledOn = true;
      }
      g1_btn12_t_execute();
   }
}

void g1_btn6_t_execute()
{
   if (g1_btn6_toggledOn)
   {
      //put servo control for claw to close
   }
   else
   {
      //have servo stay closed
   }
}

void g1_btn5_t_execute()
{
   if (g1_btn5_toggledOn)
   {
      //put servo control for claw to close
   }
   else
   {
      //have servo stay closed
   }
}

void g1_btn8_t_execute()
{
   if (g1_btn8_toggledOn)
   {
      //put servo control for claw to open
   }
   else
   {
      //have servo stay open
   }
}

void g1_btn7_t_execute()
{
   if (g1_btn7_toggledOn)
   {
      //put servo control for claw to open
   }
   else
   {
      //have servo stay open
   }
}

void g1_tHat_btn6_t_execute()
{
   if (g1_tHat_btn6_toggledOn)
   {
      motor[rightdrive] = 25;
      motor[leftdrive] = -25;
   }
   else
   {
      motor[rightdrive] = 0;
      motor[leftdrive] = 0;
   }
}

void g1_tHat_btn2_t_execute()
{
   if (g1_tHat_btn2_toggledOn)
   {
      motor[leftdrive] = 25;
      motor[rightdrive] = -25;
   }
   else
   {
      motor[leftdrive] = 0;
motor[rightdrive] = 0;
   }
}

void g1_tHat_btn0_t_execute()
{
   if (g1_tHat_btn0_toggledOn)
   {
      motor[rightdrive] = 25;
      motor[leftdrive] = 25;
   }
   else
   {
      motor[rightdrive] = 0;
      motor[leftdrive] = 0;
   }
}

void g1_tHat_btn4_t_execute()
{
   if (g1_tHat_btn4_toggledOn)
   {
      motor[rightdrive] = -25;
      motor[leftdrive] = -25;
   }
   else
   {
      motor[rightdrive] = 0;
motor[leftdrive] = 0;
   }
}

void g1_btn1_t_execute()
{
   if (g1_btn1_toggledOn)
   {
      motor[armleftright] = 10;
   }
   else
   {
      motor[armleftright] = 0;
   }
}

void g1_btn3_t_execute()
{
   if (g1_btn3_toggledOn)
   {
      motor[armleftright] = -10;
   }
   else
   {
      motor[armleftright] = 0;
   }
}

void g1_btn4_t_execute()
{
   if (g1_btn4_toggledOn)
   {
      motor[armupdown] = 25;
   }
   else
   {
      motor[armupdown] = 0;
   }
}

void g1_btn2_t_execute()
{
   if (g1_btn2_toggledOn)
   {
      motor[armupdown] = -25;
   }
   else
   {
      motor[armupdown] = 0;
   }
}

void g1_btn11_t_execute()
{
   if (g1_btn11_toggledOn)
   {
      //how do you make this drive the left motor
   }
   else
   {
      //how do you make this stop the left motor
   }
}

void g1_btn12_t_execute()
{
   if (g1_btn12_toggledOn)
   {
      //how do you make this drive the right motor
   }
   else
   {
      //how do you make this stop the right motor
   }
}

_________________
-------------------
"She laughs at everything you say. Why? Because she has fine teeth."
"Three can keep a secret, if two of them are dead."
"Either write something worth reading or do something worth writing."


Fri Feb 24, 2012 3:48 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: robotc error
You seem to have some questions about basic functionality. Why don't you take a read through this: http://www.robotc.net/education/curricu ... essons.pdf

_________________
sudo rm -rf /


Fri Feb 24, 2012 4:36 pm
Profile
Rookie
User avatar

Joined: Wed Feb 22, 2012 9:04 am
Posts: 20
Location: behind you
Post Re: robotc error
i have this code:

Code:
#pragma config(Sensor, S1,     touchleft,      sensorTouch)
#pragma config(Sensor, S2,     touchlift,      sensorTouch)
#pragma config(Sensor, S3,     touchright,     sensorTouch)
#pragma config(Motor,  motorA,          lift,          tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  motorB,          left,          tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  motorC,          right,         tmotorNormal, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main
{
  //main code goes here
while (1 == 1)
{
  while(SensorValue(touchleft) == 0 && SensorValue(touchlift) == 0 && SensorValue(touchright) == 0)
{
  motor[lift] = 0;
  motor[left] = 10;
  motor[right] = 10;
}
while(SensorValue(touchleft) == 1)
{
    motor[left] = -25;
    motor[right] = 25;
}
while(SensorValue(touchright) == 1)
{
  motor[left] = 25;
  motor[right] = -25;
}
while(SensorValue(touchlift) == 1)
{
  motor[lift] = 10;
}
            while(SensorValue(touchleft) == 1 && SensorValue(touchright) == 1)
            {
            motor[left] = -10;
            motor[right] = -10;
            }
           while(SensorValue(touchlift) == 1 && SensorValue(touchleft) == 1 && SensorValue(touchright) == 1)
           {
           motor[lift] = -10;
           }
}
}


and it can do everything except the lines with a indent which wont work!!!

does anyone know why because i am confused?

_________________
-------------------
"She laughs at everything you say. Why? Because she has fine teeth."
"Three can keep a secret, if two of them are dead."
"Either write something worth reading or do something worth writing."


Sun Feb 26, 2012 6:42 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: robotc error
What do you mean "don't work"? What happens? What do you expect to happen instead? What order the buttons being pushed in?

_________________
sudo rm -rf /


Sun Feb 26, 2012 6:59 pm
Profile
Rookie

Joined: Wed Jul 21, 2010 11:23 pm
Posts: 39
Post Re: robotc error
If any of your three touch sensors are pressed the program will remain stuck (so to speak) in one of the three individual while loop that looks at each sensor separately. Therefore it will never get to the indented code that is supposed to run when combinations of the sensors are pressed.

It seems to me you want to be using 'if' statements instead of 'while' loops.


Mon Feb 27, 2012 4:15 pm
Profile
Rookie
User avatar

Joined: Wed Feb 22, 2012 9:04 am
Posts: 20
Location: behind you
Post Re: robotc error
I was wondering how to connect my logitech game pad f310 to my nxt so i could control it from the game pad using the buttons and joysticks, and also what things I need on the robot to allow the communication from my pc to my robot

please respond Image

_________________
-------------------
"She laughs at everything you say. Why? Because she has fine teeth."
"Three can keep a secret, if two of them are dead."
"Either write something worth reading or do something worth writing."


Tue Feb 28, 2012 9:04 pm
Profile
Rookie
User avatar

Joined: Wed Feb 22, 2012 9:04 am
Posts: 20
Location: behind you
Post Re: robotc error
magicode wrote:
What do you mean "don't work"? What happens? What do you expect to happen instead? What order the buttons being pushed in?

oh I realized my error later and fixed it, so never mind about that error

_________________
-------------------
"She laughs at everything you say. Why? Because she has fine teeth."
"Three can keep a secret, if two of them are dead."
"Either write something worth reading or do something worth writing."


Tue Feb 28, 2012 9:06 pm
Profile
Rookie
User avatar

Joined: Wed Feb 22, 2012 9:04 am
Posts: 20
Location: behind you
Post Re: robotc error
ronmcrae wrote:
If any of your three touch sensors are pressed the program will remain stuck (so to speak) in one of the three individual while loop that looks at each sensor separately. Therefore it will never get to the indented code that is supposed to run when combinations of the sensors are pressed.

It seems to me you want to be using 'if' statements instead of 'while' loops.

I already changed that when I fixed my other errors because I realized that wouldnt work, my new code is:

Code:
#pragma config(Sensor, S1,     touchleft,      sensorTouch)
#pragma config(Sensor, S2,     touchlift,      sensorTouch)
#pragma config(Sensor, S3,     touchright,     sensorTouch)
#pragma config(Motor,  motorA,          lift,          tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  motorB,          left,          tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  motorC,          right,         tmotorNormal, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main
{
  //main code goes here
while (1 == 1)
{
if (SensorValue(touchleft) == 0 && SensorValue(touchlift) == 0 && SensorValue(touchright) == 0)
{
  motor[lift] = 0;
  motor[left] = 10;
  motor[right] = 10;
}
if (SensorValue(touchleft) == 1 && SensorValue(touchright) == 0)
{
    motor[left] = -25;
    motor[right] = 25;
}
if (SensorValue(touchright) == 1 && SensorValue(touchleft) == 0)
{
  motor[left] = 25;
  motor[right] = -25;
}
if (SensorValue(touchlift) == 1 && SensorValue(touchleft) == 0 && SensorValue(touchright) == 0)
{
  motor[lift] = 10;
  motor[left] = 0;
  motor[right] = 0;
}
if (SensorValue(touchleft) == 1 && SensorValue(touchright) == 1 && SensorValue(touchlift) == 0)
{
  motor[left] = -10;
  motor[right] = -10;
}
if (SensorValue(touchlift) == 1 && SensorValue(touchleft) == 1 && SensorValue(touchright) == 1)
{
  motor[lift] = -10;
  motor[left] = 0;
  motor[right] = 0;
}
}
}


And it works great!!!

_________________
-------------------
"She laughs at everything you say. Why? Because she has fine teeth."
"Three can keep a secret, if two of them are dead."
"Either write something worth reading or do something worth writing."


Thu Mar 01, 2012 10:18 am
Profile
Rookie
User avatar

Joined: Wed Feb 22, 2012 9:04 am
Posts: 20
Location: behind you
Post Re: robotc error
SCOPE wrote:
I was wondering how to connect my logitech game pad f310 to my nxt so i could control it from the game pad using the buttons and joysticks, and also what things I need on the robot to allow the communication from my pc to my robot

please respond Image


I finished figuring out all my current questions with the help of you people and my friend during my last meet except one, how do i program the triggers to do anything???

my code is this:

Code:
#pragma config(Hubs,  S1, HTMotor,  HTMotor,  HTMotor,  HTMotor)
#pragma config(Hubs,  S2, HTServo,  HTServo,  none,     none)
#pragma config(Sensor, S1,     ,               sensorI2CMuxController)
#pragma config(Sensor, S2,     ,               sensorI2CMuxController)
#pragma config(Motor,  mtr_S1_C1_1,     leftdrive,     tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C1_2,     rightdrive,    tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C2_1,     armupdown,     tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C2_2,     armleftright,  tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C3_1,     motorH,        tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C3_2,     motorI,        tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C4_1,     motorJ,        tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C4_2,     motorK,        tmotorNormal, openLoop)
#pragma config(Servo,  srvo_S2_C1_1,    claw,                 tServoStandard)
#pragma config(Servo,  srvo_S2_C1_2,    unkwown,              tServoStandard)
#pragma config(Servo,  srvo_S2_C1_3,    servo3,               tServoNone)
#pragma config(Servo,  srvo_S2_C1_4,    servo4,               tServoNone)
#pragma config(Servo,  srvo_S2_C1_5,    servo5,               tServoNone)
#pragma config(Servo,  srvo_S2_C1_6,    servo6,               tServoNone)
#pragma config(Servo,  srvo_S2_C2_1,    servo7,               tServoNone)
#pragma config(Servo,  srvo_S2_C2_2,    servo8,               tServoNone)
#pragma config(Servo,  srvo_S2_C2_3,    servo9,               tServoNone)
#pragma config(Servo,  srvo_S2_C2_4,    servo10,              tServoNone)
#pragma config(Servo,  srvo_S2_C2_5,    servo11,              tServoNone)
#pragma config(Servo,  srvo_S2_C2_6,    servo12,              tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

/////////////////////////////////////////ROBOT///////////////////////////////////////////
/*///////////////////////////////////////////////////////////////////////////////////////
/Controls                        Description                              othernames    /
/////////////////////////////////////////////////////////////////////////////////////////
/topHat------------used to control the claw being open or closed------------topHat      /
/Button1-----------used to make the arm turn Left---------------------------armleft     /
/Button2-----------used to make the arm go up-------------------------------armup       /
/Button3-----------used to make the arm go down-----------------------------armdown     /
/Button4-----------used to make the arm turn right--------------------------armright    /
/Joystick1---------uesd to make the robot move------------------------------???????     /
/Joystick2---------used to make the robot move------------------------------???????     /
/triggerL1---------???????????????????????????------------------------------???????     /
/triggerL2---------???????????????????????????------------------------------???????     /
/triggerR1---------???????????????????????????------------------------------???????     /
/triggerR2---------???????????????????????????------------------------------???????     /
*////////////////////////////////////////////////////////////////////////////////////////
const int armup = 2;
const int armdown = 3;
const int armleft = 1;
const int armright = 4;
const int threshold = 5;
#include "JoystickDriver.c"

void triggers()
{
  //trigger controls for claw (the claw is a VEX Robotics claw)
}
void handleArm()
{
  //up/down
  if (joy1_Btn(armup))
  {
    motor[armupdown] = 25; //motor that lifts the arm goes up
  }
  else if (joy1_Btn(armdown))
  {
    motor[armupdown] = -25; //motor that lifts the arm goes down
  }
  else
  {
    motor[armupdown] = 0; //motor that lifts the arm is stationary
  }
  //left/right
  if (joy1_Btn(armleft))
  {
    motor[armleftright] = 10; //motor that turns the arm moves to the left
  }
  else if (joy1_Btn(armright))
  {
    motor[armleftright] = -10; //motor that turns the arm moves to the right
  }
  else
  {
    motor[armleftright] = 0; //motor that turns the arm is stationary
  }
}
void tankDrive()
{
  //put tank drive code here
  //forward/backward
  //turn left/right
    if(abs(joystick.joy1_y2) > threshold)   // If the right analog stick's Y-axis readings are either above or below the threshold:
    {
      motor[rightdrive] = joystick.joy1_y2;         // Motor rightdrive is assigned a power level equal to the right analog stick's Y-axis reading.
    }
    else                                    // Else if the readings are within the threshold:
    {
      motor[rightdrive] = 0;                        // Motor rightdrive is stopped with a power level of 0.
    }


    if(abs(joystick.joy1_y1) > threshold)   // If the left analog stick's Y-axis readings are either above or below the threshold:
    {
      motor[leftdrive] = joystick.joy1_y1;         // Motor leftdrive is assigned a power level equal to the left analog stick's Y-axis reading.
    }
    else                                    // Else if the readings are within the threshold:
    {
      motor[leftdrive] = 0;                        // Motor leftdrive is stopped with a power level of 0.
    }
}

task main()
{
while (true)
{
 getJoystickSettings(joystick);
 handleArm();
 tankDrive();
 triggers();
}
}

_________________
-------------------
"She laughs at everything you say. Why? Because she has fine teeth."
"Three can keep a secret, if two of them are dead."
"Either write something worth reading or do something worth writing."


Thu Mar 01, 2012 10:24 am
Profile
Rookie

Joined: Fri Aug 31, 2012 1:56 am
Posts: 8
Post Re: robotc error
This is a little late but...
The triggers are the same as the buttons. They each have a number that is printed on them if you have the Logitech Dual Action controller. If you have the F310 controller, you have to navigate in RobotC to, Robot -> NXT Brick -> Joystick Control Basic. You have to have an NXT and a controller connected to the computer for the dialogue box to open. Once it is open start messing around with the buttons on your controller and you will see that the dialogue box reacts to your input. Push the buttons you need and the box will tell you what buttons are being pressed. Hope that helps!

Oh, and a side note. If the F310 Gamepad triggers are giving output as the right joystick, that's because it's in an accelerated mode. Unplug your joystick, flip the switch on the back of the controller to "D" and plug it back in. All buttons should act normally.

Hope that helps!


Fri Aug 31, 2012 2:07 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 25 posts ]  Go to page Previous  1, 2

Who is online

Users browsing this forum: tmalecek and 2 guests


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.