Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   FIRST Tech Challenge (http://www.chiefdelphi.com/forums/forumdisplay.php?f=146)
-   -   [FTC]: Need Help Programming Joystick via Samantha (http://www.chiefdelphi.com/forums/showthread.php?t=130715)

FRC Team CC 03-10-2014 21:38

[FTC]: Need Help Programming Joystick via Samantha
 
Hello Chief Delphi,

We are FTC Team 8660, the Charging Champions. We are a rookie team who needs help programming the Logitech controller provided by FIRST. We are using RobotC. We were able to configure the Samantha module to the router and have made many, many attempts programming it but we're unable to to get it to work. After searching on online blogs, tutorials, and videos for a long time, we were unable to find the answers, so we came here seeking advice. We also cannot get the joystick to work, even by wired connections.
  • What are the complete procedures for successfully setting up a tele-op program?
  • If possible, can you provide us a sample program? (e.g. button A to move backwards, button Y to move forwards)

All help is appreciated. Go FTC Teams!!!

Sincerely,
Charging Champions
FTC Team 8660

MattRain 04-10-2014 00:18

Re: [FTC]: Need Help Programming Joystick via Samantha
 
Here is our Teleop code from last year... see if this helps. Shorter version below.

Code:

#pragma config(Hubs,  S1, HTMotor,  HTMotor,  HTMotor,  HTServo)
#pragma config(Sensor, S1,    ,              sensorI2CMuxController)
#pragma config(Motor,  mtr_S1_C1_1,    right,        tmotorTetrix, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C1_2,    left,          tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C2_1,    tower,        tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C2_2,    none,          tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C3_1,    claw,          tmotorTetrix, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C3_2,    flag,          tmotorTetrix, openLoop)
#pragma config(Servo,  srvo_S1_C4_1,    Brake,                tServoStandard)
#pragma config(Servo,  srvo_S1_C4_2,    LeftFlap,            tServoStandard)
#pragma config(Servo,  srvo_S1_C4_3,    RightFlap,            tServoStandard)
#pragma config(Servo,  srvo_S1_C4_4,    Block,                tServoStandard)
#pragma config(Servo,  srvo_S1_C4_5,    servo5,              tServoNone)
#pragma config(Servo,  srvo_S1_C4_6,    servo6,              tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard              !!*//

#include "JoystickDriver.c"  //Include file to "handle" the Bluetooth messages.


void initializeRobot()
{
        servoTarget[Brake] = 65;
        servoTarget[RightFlap] = 241;
  servoTarget[LeftFlap] = 18;
  servoTarget[Block] = 237;

  return;
}

task main()
{
  initializeRobot();

  waitForStart();  // wait for start of tele-op phase

  while (true)
  {
                getJoystickSettings(joystick);
                if(joy1Btn(7))// claw Up
  {
    motor[right] = joystick.joy1_y2/4;
    motor[left] = joystick.joy1_y1/4;
  }
  else
  {
    motor[right] = joystick.joy1_y2;
    motor[left] = joystick.joy1_y1;
  }
    motor[tower] = joystick.joy2_y1;

  //****************** DRIVER 2 (James) ***************************

  if(joy2Btn(6))// claw Up
  {
    motor[claw] = 128;
  }
  else if(joy2Btn(8))// claw Down
  {
    motor[claw] = -128;
  }
  else
  {
    motor[claw] = 0;
  }

  if(joy2Btn(2))//flinger
                {
                servoTarget[Block]= 170;
                }
                else
                {
                servoTarget[Block]= 237;
          }

        //****************** DRIVER 1 (Jacob) ***************************

  if(joy1Btn(4))// flag up
  {
    motor[flag] = 100;
  }
  else if(joy1Btn(3))// flag down
  {
    motor[flag] = 50;
  }
  else if(joy1Btn(2))// flag down
  {
    motor[flag] = -100;
  }
  else
  {
    motor[flag] = 0;
  }

  if(joy1Btn(5)) //Right FLAP
  {
    servoTarget[LeftFlap] = 80;
  }
  else
  {
    servoTarget[LeftFlap] = 180;
  }

  if(joy1Btn(6))// Left FLAP
  {
    servoTarget[RightFlap] = 146;
  }
  else
  {
    servoTarget[RightFlap] = 47;
  }

  //*********************** BOTH DRIVERS **************************

  if(joy1Btn(1)&joy2Btn(1))// baton mover
  {
    servoTarget[Brake] = 97;
  }
  else
  {
    servoTarget[Brake] = 65;
  }
                }
        }

Code:

#pragma config(Hubs,  S1, HTMotor,  HTMotor,  HTMotor,  HTServo)
#pragma config(Sensor, S1,    ,              sensorI2CMuxController)
#pragma config(Motor,  mtr_S1_C1_1,    right,        tmotorTetrix, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C1_2,    left,          tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C2_1,    tower,        tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C2_2,    none,          tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C3_1,    claw,          tmotorTetrix, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C3_2,    flag,          tmotorTetrix, openLoop)
#pragma config(Servo,  srvo_S1_C4_1,    Brake,                tServoStandard)
#pragma config(Servo,  srvo_S1_C4_2,    LeftFlap,            tServoStandard)
#pragma config(Servo,  srvo_S1_C4_3,    RightFlap,            tServoStandard)
#pragma config(Servo,  srvo_S1_C4_4,    Block,                tServoStandard)
#pragma config(Servo,  srvo_S1_C4_5,    servo5,              tServoNone)
#pragma config(Servo,  srvo_S1_C4_6,    servo6,              tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard              !!*//

#include "JoystickDriver.c"  //Include file to "handle" the Bluetooth messages.


void initializeRobot()
{
        servoTarget[Brake] = 65;
        servoTarget[RightFlap] = 241;
  servoTarget[LeftFlap] = 18;
  servoTarget[Block] = 237;

  return;
}

task main()
{
  initializeRobot();

  waitForStart();  // wait for start of tele-op phase

  while (true)

    motor[right] = joystick.joy1_y2;
    motor[left] = joystick.joy1_y1;
    motor[tower] = joystick.joy2_y1;


FTC4211 04-10-2014 19:48

Re: [FTC]: Need Help Programming Joystick via Samantha
 
All of our archived code from the last 2 seasons can be found at: http://www.4211thebombers.org/UsefullLinks.html

The "Team 4211's Block Party Code" and "Team 4211's Ring it Up Code" links contain all the autonomous and telop code that we ran at competitions. They have examples of various techniques and strategies for controlling the robot in telop and autonomous, including how to separate the joystick inputs into different threads to allow faster response times.


To more directly answer your question, here is a program with all the basic telop components you need along with various control schemes for driving a robot and for moving a servo. Just uncomment a section you want to try and it will work on a robot.

Code:

#pragma config(Hubs,  S1, HTMotor,  HTServo,  none,    none)
#pragma config(Sensor, S1,    ,              sensorI2CMuxController)
#pragma config(Motor,  mtr_S1_C1_1,    Right_Drive_Motor, tmotorTetrix, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C1_2,    Left_Drive_Motor, tmotorTetrix, openLoop)
#pragma config(Servo,  srvo_S1_C2_1,    exampleServo,        tServoStandard)
#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";

void initializeRobot()
{
        // put the code to initialize servo positions in here

        // don't put code to move motors in here as that can lead to a DQ
}

task main()
{
        initializeRobot(); // initialize robot 
       
        waitForStart(); // waits for FCS to start the match
       
        while (1)
        {
                getJoystickSettings(joystick); // get new message from joystick
               
               
                // 3 common drive control schemes for differental drive robots are below
               
               
                /* delete this line and line 29 to run this drive mode
               
                // drive the robot in tank drive style with the joysticks
                motor[Left_Drive_Motor]=joystick.joy1_y1;
                motor[Right_Drive_Motor]=joystick.joy1_y2;
               
                */
               
               
                /* delete this line and line 61 to run this drive mode
               
                // drive the robot with 4 buttons
                if (joy1Btn(4)) // drive forward when button 4 is pressed
                {
                        motor[Left_Drive_Motor]=75;
                        motor[Right_Drive_Motor]=75;
                }
                else if (joy1Btn(2)) // drive backwards when button 4 is pressed
                {
                        motor[Left_Drive_Motor]=-75;
                        motor[Right_Drive_Motor]=-75;
                }
                else if (joy1Btn(1)) // turn left when button 1 is pressed
                {
                        motor[Left_Drive_Motor]=-75;
                        motor[Right_Drive_Motor]=75;
                }
                else if (joy1Btn(3)) // turn right when button 2 is pressed
                {
                        motor[Left_Drive_Motor]=75;
                        motor[Right_Drive_Motor]=-75;
                }
                else // stop when no button is pressed
                {
                        motor[Left_Drive_Motor]=0;
                        motor[Right_Drive_Motor]=0;
                }
               
                */
               
               
                /* delete this line and line 107 to run this drive mode
               
                // drive the robot with the tophat on the left side of the controller
                switch(joystick.joy1_TopHat)
                {
                        case 0: // drive forwards when top hat is pushed forwards
                                motor[Left_Drive_Motor]=75;
                                motor[Right_Drive_Motor]=75;
                                break;
                        case 1: // drive right forwards when top hat is pushed front right
                                motor[Left_Drive_Motor]=75;
                                motor[Right_Drive_Motor]=0;
                                break;
                        case 2: // turn right when top hat is pushed right
                                motor[Left_Drive_Motor]=75;
                                motor[Right_Drive_Motor]=-75;
                                break;
                        case 3: // drive back right when top hat is pushed back right
                                motor[Left_Drive_Motor]=-75;
                                motor[Right_Drive_Motor]=0;
                                break;
                        case 4: // drive backward when top hat is pushed back
                                motor[Left_Drive_Motor]=-75;
                                motor[Right_Drive_Motor]=-75;
                                break;
                        case 5: // drive back left when top hat is pushed back left
                                motor[Left_Drive_Motor]=0;
                                motor[Right_Drive_Motor]=-75;
                                break;
                        case 6: // turn left when top hat is pushed left
                                motor[Left_Drive_Motor]=-75;
                                motor[Right_Drive_Motor]=75;
                                break;
                        case 7: // drive front left when top hat is pushed front left
                                motor[Left_Drive_Motor]=0;
                                motor[Right_Drive_Motor]=75;
                                break;
                        default:  // stop the robot when no top hat direction is pressed
                                motor[Left_Drive_Motor]=0;
                                motor[Right_Drive_Motor]=0;
                                break;
                }
               
                */
               
               
               
                // 3 common servo movement controls
               
               
                /* delete this line and line 132 to run this servo control mode
               
                // move a servo with the joystick
                servo[exampleServo]=joystick.joy1_y1;
               
                */
               
               
                /* delete this line and line 146 to run this servo control mode
               
                // move a servo to a postition when a button is pressed
                if (joy1Btn(5))
                {
                        servo[exampleServo]=0; // change the '0' to whatever position you need when the button is pressed
                }
                else
                {
                        servo[exampleServo]=255; // change the '0' to whatever position you need when the button is released
                }
               
                */
               
               
                /* delete this line and line 162 to run this servo control mode
               
                // move a servo to a forward/backward like a motor when a button pair is pressed
                if (joy1Btn(5))
                {
                        servo[exampleServo]=ServoValue[exampleServo]+1; // increase the '1' to make the servo change its position faster
                }
                if (joy1Btn(7))
                {
                        servo[exampleServo]=ServoValue[exampleServo]-1; // increase the '1' to make the servo change its position faster
                }
               
                */
        }
}


robotsrule 05-10-2014 20:35

Re: [FTC]: Need Help Programming Joystick via Samantha
 
You should check out the youtube videos posted by the Robogamers. The channel is RobogamersTV
https://www.youtube.com/user/robogamersonline

Watching their videos helped us a lot. They have one specifically on joystick control programming.

https://www.youtube.com/watch?v=3HF31q2mnfA

The Anderson wiring will probably help as well.
https://www.youtube.com/watch?v=M1FsxbLcM0w

Hope this helps.


All times are GMT -5. The time now is 18:23.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi