View unanswered posts | View active topics It is currently Fri Sep 19, 2014 6:00 am






Reply to topic  [ 4 posts ] 
Joystick Programming help 
Author Message
Rookie

Joined: Sat Dec 07, 2013 1:08 pm
Posts: 8
Post Joystick Programming help
Hey,

I'm having some trouble. I'm writing code for our robot this year and since we don't have a complete robot yet because it's missing the drive chain, I've been using a simple robot made of Lego pieces to test my code.
I was looking through our programs from last year and basically mirrored it for the basic drive train. The program I mirrored it from was the one our team used last year for Teleop period. I obviously tweaked it a bit, changing the settings to fit my simple robot.

(This is last year's code)

Code:
#pragma config(Hubs,  S4, HTMotor,  HTMotor,  HTServo,  none)
#pragma config(Sensor, S4,     ,               sensorI2CMuxController)
#pragma config(Motor,  mtr_S4_C1_1,     motorD,        tmotorTetrix, openLoop, reversed)
#pragma config(Motor,  mtr_S4_C1_2,     motorE,        tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S4_C2_1,     motorF,        tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S4_C2_2,     motorG,        tmotorTetrix, openLoop)
#pragma config(Servo,  srvo_S4_C3_1,    servo1,               tServoNone)
#pragma config(Servo,  srvo_S4_C3_2,    servo2,               tServoNone)
#pragma config(Servo,  srvo_S4_C3_3,    servo3,               tServoNone)
#pragma config(Servo,  srvo_S4_C3_4,    servo4,               tServoNone)
#pragma config(Servo,  srvo_S4_C3_5,    servo5,               tServoNone)
#pragma config(Servo,  srvo_S4_C3_6,    servo6,               tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "JoystickDriver.c" //Joystick is included in this program
task main()
{
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//
//derek was here


  int threshold = 15;

  while(true) //infinite loop
  {

    //Below is the code for driving the robot with the joysticks (tank drive) on remote 1.

    getJoystickSettings(joystick);



    if(abs(joystick.joy1_y1) > threshold)
    {
      motor[motorE] = joystick.joy1_y1;
    }
    else
    {
      motor[motorE] = 0;
    }

    if(abs(joystick.joy1_y2) > threshold)
    {
      motor[motorD] = joystick.joy1_y2;
    }
    else
    {
      motor[motorD] = 0;
      //derek was here
    }

//Below is the code for controlling the lift with the 2nd controller.

    if(abs(joystick.joy2_y1) > threshold)//joystick on second controller controles the 2nd part of lift.
    {
      motor[motorG] = joystick.joy2_y1/1.5;
    }

    else
    {
      motor[motorG] = 0;
    }

    if(abs(joystick.joy2_y2) > threshold)//joystick on second controller controles the 3rd part of lift.
    {
      motor[motorF] = joystick.joy2_y2/1.5;
    }

    else
    {
        motor[motorF]=0;
    }

    if(joy2Btn(3) ==1)//button 3 when pressed holds servo in ring grab mode.
    {
        servo[servo2]=255;
    }

    else //If button 3 isn't pressed, it returns to ring dispense mode.
    {
        servo[servo2]=221;
    }

    if(joy2Btn(5) == 1) //button X is pressed on 2nd controller brings 1st part of the lift up.
         {
            servo[servo1]=200;
      }

      else
      {
          servo[servo1]=128;
      }

      if(joy2Btn(7) == 1)
      {
          servo[servo1]=0;
      }
    }
}


(This is my code)

Code:
#pragma config(Hubs,  S1, HTMotor,  HTServo,  HTMotor,  none)
#pragma config(Motor,  mtr_S1_C1_1,     motorD,        tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C3_1,     motorF,        tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C3_2,     motorG,        tmotorTetrix, openLoop)
#pragma config(Servo,  srvo_S1_C2_1,    servo1,               tServoNone)
#pragma config(Servo,  srvo_S1_C2_2,    servo2,               tServoNone)
#pragma config(Servo,  srvo_S1_C2_3,    servo3,               tServoNone)
#pragma config(Servo,  srvo_S1_C2_4,    servo4,               tServoNone)
#pragma config(Servo,  srvo_S1_C2_5,    servo5,               tServoNone)
#pragma config(Servo,  srvo_S1_C2_6,    servo6,               tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "JoystickDriver.c"
task main()
{

   /*int threshhold = 15;*/

   while(true)
   {

   if(abs(joystick.joy1_y1) > 15/*threshhold*/)
   {
     motor[motorC] = joystick.joy1_y1;
   }
   else
   {
     motor[motorC] = 0;
   }

   if(abs(joystick.joy1_y2) > 15/*threshhold*/)
   {
     motor[motorB] = joystick.joy1_y2;
   }
   else
   {
     motor[motorB] = 0;
   }

 }
}


So my problem is that my simple robot will respond when I use the joystick, but it jerks pretty bad. Help is always depreciated

Thanks!


Wed Dec 11, 2013 10:04 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Joystick Programming help
You forgot to call getJoystickSettings(joystick).


Wed Dec 11, 2013 10:54 pm
Profile
Rookie

Joined: Sat Dec 07, 2013 1:08 pm
Posts: 8
Post Re: Joystick Programming help
Thanks! I feel very silly for not remembering to put that into my code! I did try that and it didn't fix my problem with the jerking. It's still doing the same thing.

Also I'm sorry, You are very appreciated (not depreciated)!


Wed Dec 11, 2013 11:28 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Joystick Programming help
I don't know why your robot is jerky but since your pragmas don't show motorB and motorC, may be you should do the "Motor and Sensor setup" to set up the motors probably to see if that solves the problem. I doubt it but it will at least show you the configuration of the motors.


Thu Dec 12, 2013 1:46 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users 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.