View unanswered posts | View active topics It is currently Thu Jul 31, 2014 7:42 pm






Reply to topic  [ 2 posts ] 
Encoder issue in telop. 
Author Message
Rookie

Joined: Mon Feb 27, 2012 5:26 pm
Posts: 20
Post Encoder issue in telop.
Code:
#pragma config(Hubs,  S1, HTMotor,  HTMotor,  HTMotor,  HTMotor)
#pragma config(Hubs,  S2, HTServo,  none,     none,     none)
#pragma config(Sensor, S1,     ,               sensorI2CMuxController)
#pragma config(Sensor, S2,     ,               sensorI2CMuxController)
#pragma config(Motor,  mtr_S1_C1_1,     right,         tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C1_2,     right2,        tmotorTetrix, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C2_1,     left,          tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C2_2,     left2,         tmotorTetrix, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C3_1,     lift,          tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C3_2,     lift2,         tmotorTetrix, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C4_1,     Arm,           tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C4_2,     motorK,        tmotorTetrix, openLoop)
#pragma config(Servo,  srvo_S2_C1_1,    flipperleft,          tServoStandard)
#pragma config(Servo,  srvo_S2_C1_2,    tilt2,                tServoStandard)
#pragma config(Servo,  srvo_S2_C1_3,    dumpster,             tServoContinuousRotation)
#pragma config(Servo,  srvo_S2_C1_4,    servo4,               tServoNone)
#pragma config(Servo,  srvo_S2_C1_5,    tilt,                 tServoStandard)
#pragma config(Servo,  srvo_S2_C1_6,    flipperright,         tServoStandard)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "JoystickDriver.c"

void initializeRobot()
{
nMotorEncoder[Arm] = 0;
}




task main()
{

while (1 == 1)
  {
    getJoystickSettings(joystick);


    if (joystick.joy2_y2 < 15 && joystick.joy2_y2 > -15)  /* Makes left side wheels move in tandem and same speed */
    {                                                                                 // Makes motors = joystick move
                                                                                     //   but if at 10 or negative 10 stop
      motor[right] = 0;
      motor[right2] = 0;  // just states if joystick = 10 or -10 motor = 0

    }
    else
    {
      motor[right] = joystick.joy2_y2;
         motor[right2] = joystick.joy2_y2; // if it is above 10 or -10 then the motor power = the joystick.
    }


    if (joystick.joy2_y1 < 15 && joystick.joy2_y1 > -15)  /* Makes left side wheels move in tandem and same speed */
    {                                                                                 // Makes motors = joystick move
                                                                                     //   but if at 10 or negative 10 stop
      motor[left] = 0;
      motor[left2] = 0; // joystick if 10 or -10 = motor power = 0

    }
    else
    {
      motor[left] = joystick.joy2_y1;  // if it is above 10 or -10 then the motor power = the joystick.
      motor[left2] = joystick.joy2_y1;

    }
    while (joy2Btn(6) == 1 )
    {
       motor[right] = joystick.joy2_y2/3;
         motor[right2] = joystick.joy2_y2/3;
       motor[left] = joystick.joy2_y1/3;
         motor[left2] = joystick.joy2_y1/3;
      }
   
   
        if (joystick.joy1_y1 < 10 && joystick.joy1_y1 > -10) //motor = 0 if at 5 or -5
    {
      motor[Arm] = 0;


    }
    else
    {
      motor[Arm] =  joystick.joy1_y1/-2;

    }
      
      
         
if(joystick.joy1_TopHat == -1)                  //Top d-pad btn (joystick 2) sets the grabber arm height to the default position
    {
      nMotorEncoderTarget[Arm] = 0;
      motor[Arm] = 0;
      while(nMotorRunState[Arm] != runStateIdle) {}    // Wait until encoder value is reached.
    }


    if(joystick.joy1_TopHat == 0)                       //Right d-pad btn (joystick 2) sets the grabber arm height to score position
    {
      nMotorEncoderTarget[Arm] = -300;    //CHECK AND ADD THE CORRECT ENCODER VALUE!!!!!
      motor[Arm] = -50;
      while(nMotorRunState[Arm] != runStateIdle) {}    // Wait until encoder value is reached.
    }


    if(joystick.joy1_TopHat == 4)                  //Right d-pad btn (joystick 2) sets the grabber arm height to pick-up position
     {
      nMotorEncoderTarget[Arm] = -300;   //CHECK AND ADD THE CORRECT ENCODER VALUE!!!!!
      motor[Arm] = 15;
      while(nMotorRunState[Arm] != runStateIdle) {}   // Wait until encoder value is reached
     }

    wait1Msec(50);

     
    // Infinite loop:
{
      if(joy1Btn(1) == 1)                  // If Joy1-Button2 is pressed:
        {
          servo[tilt] =  242;
          servo[tilt2] =  10;// block is Grabbed
                      // Can use the debugger to help find these positions
        }
    {
      if(joy1Btn(4) == 1)                  // If Joy1-Button2 is pressed:
        {
          servo[tilt] =  40;
          servo[tilt2] =  214;    // block is Grabbed
                                // Can use the debugger to help find these positions
        }

      {
    if(joy1Btn(3) == 1)                  // If Joy1-Button2 is pressed:
        {
          servo[tilt] =  4;             // block is Grabbed
          servo[tilt2] =  248;
                                        // Can use the debugger to help find these positions
        }
        {
          if(joy1Btn(2) == 1)                  // Open position us Joy1btn 3
                                                // if button 3 is pressed
          {
            servo[tilt] = 140;
            servo[tilt2] =  112;

          }


    {  if (joystick.joy1_y2 < 10 && joystick.joy1_y2 > -10)  /* Makes left side wheels move in tandem and same speed */
    {                                                                                 // Makes motors = joystick move
                                                                                     //   but if at 10 or negative 10 stop
      motor[lift] = 0;
      motor[lift2] = 0;  // just states if joystick = 10 or -10 motor = 0

    }
    else
    {
      motor[lift] = joystick.joy1_y2;
         motor[lift2] = joystick.joy1_y2; // if it is above 10 or -10 then the motor power = the joystick.
    }


   /* }


      motor[lift] = 100;
      motor[lift2] = 100;     // lift is run at a power level of -100. arm down
      wait1Msec(100);
  }

    */




   if(joy1Btn(5))
    {
    servo[dumpster]=0;
    wait1Msec(100);
    }

    if(joy1Btn(5) == 1)                  // If Joy1-Button7is pressed:
    {
      servo[dumpster]=0;
      wait1Msec(100);  // Turn Motor lift at full power
    }
     else                            // If Joy1-Button7 is NOT pressed:
    {
    servo[dumpster]=128;
                         // Turn lift Off
    }
     if(joy1Btn(5))
    {
    servo[dumpster]=0;
    wait1Msec(100);
    }
    }
     if(joy1Btn(7))
    {
    servo[dumpster]=255;
    wait1Msec(100);
    }

    if(joy1Btn(7) == 1)                  // If Joy1-Button7is pressed:
    {
      servo[dumpster]=255;
      wait1Msec(100);   // Turn Motor lift at full power
    }
     else                            // If Joy1-Button7 is NOT pressed:
    {
    servo[dumpster]=128;
                     // Turn lift Off
    }
     if(joy1Btn(7))
    {
    servo[dumpster]=255;
    wait1Msec(100);
    }








}}}}}}




Is there a way to overide the encoder if it doesn't reach a position? for example its stuck on the floor or robot and to stop the motor with a button and zero out the encoder I thought the top hat =-1 would do that but it doesn't seem to be working.... please help asap.


Fri Dec 06, 2013 7:12 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Encoder issue in telop.
You are using RobotC built-in PID which means you cannot tune the PID constants. If you can't do that, you are going to have a "steady state error" which means when the arm is close to the target, the power applied to the arm is going to decrease which means it will never reach the target. The difference between the target and the actual position it is holding at is called the "steady state error". It is even more complicated for the arm because the arm is working against gravity which means it is easier to go down than going up. In addition, if it is a "swing arm on a shoulder" design, the load is heaviest when the arm is at the horizontal position. Therefore, it is very tricky to control using PID. You really need full PID control with tunable Kp, Ki and Kd constants. There is no easy fix. I can suggest a few thing you can try. First, you may want to increase the arm motor power in order to decrease the steady state error but you may risk oscillation. Secondly, if your steady state error is "acceptable", you may want do this instead of using nMotorRunState.
Code:
    if(joystick.joy1_TopHat == 0)                       //Right d-pad btn (joystick 2) sets the grabber arm height to score position
    {
        nMotorEncoderTarget[Arm] = -300;
        motor[Arm] = -50;    //may need to increase this power to decrease steady state error
        while (abs(-300 - nMotorEncoder[Arm]) > ARM_STEADY_STATE_ERR) {}
    }


Sat Dec 07, 2013 4:15 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 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.