View unanswered posts | View active topics It is currently Wed Jul 30, 2014 4:50 pm






Reply to topic  [ 2 posts ] 
Shaft encoder not tracking reverse rotation 
Author Message
Rookie

Joined: Sat Jan 14, 2012 12:13 pm
Posts: 3
Post Shaft encoder not tracking reverse rotation
I'm setting up an arm that is designed to stop at certain levels using an encoder. The encoder rotates in reverse when the arm is going up. When using the 'Poll NXT Brick' it counts and controls the motor in the reverse direction, but when running the program it will not count 'Tach Move' will not track in reverse, so the arm will not stop.

I'm assuming it's a simple mistake, but 2 hours into everything else working properly, this has me ready to get the hammer out.

Rundown (What I want):

    Initialize: arm drops to lowest level (front horizontal), taps the touch sensor, stops moving, sets encoder to 0.
    Click button 1, claw opens/closes.
    Click button 2, set encoder to -1000, move slowly until target reached. (vertical)
    Click button 2 again, set encoder to -2000, move slowly until target reached. (horizontal back)
    Click button 2 -again-, ignore encoder, move slowly back to horizontal front, stop when touch sensor activates, reset encoder to 0 again.

Rundown (What I get):

    Initialize: arm drops to lowest level (front horizontal), taps the touch sensor, stops moving, sets encoder to 0.
    Click button 1, claw opens/closes.
    Click button 2, set encoder to -1000, moves slowly forever.
    Click button 2 again, set encoder to -2000, continues to move slowly forever
    Click button 2 -again-, ignore encoder, move slowly back to horizontal front, stop when touch sensor activates, reset encoder to 0 again. (works)

The 'Tach Move' does count the forward rotation during program execution, just not reverse, it remains and whatever setting it was at when it left the front horizontal position.

I used tasks because I want the robot to be able to continue driving while other items are in motion.


Code:
#pragma config(Hubs,  S1, HTServo,  HTMotor,  HTMotor,  HTMotor)
#pragma config(Sensor, S1,     ,               sensorI2CMuxController)
#pragma config(Sensor, S2,     HTGYRO,         sensorI2CHiTechnicGyro)
#pragma config(Sensor, S3,     HTACCEL,        sensorI2CHiTechnicAccel)
#pragma config(Sensor, S4,     Touch,          sensorTouch)
#pragma config(Motor,  mtr_S1_C2_1,     LeftFront,     tmotorNormal, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C2_2,     LeftRear,      tmotorNormal, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C3_1,     Arm,           tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  mtr_S1_C3_2,     notused,       tmotorNone, openLoop)
#pragma config(Motor,  mtr_S1_C4_1,     RightRear,     tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C4_2,     RightFront,    tmotorNormal, openLoop)
#pragma config(Servo,  srvo_S1_C1_1,    servo1,               tServoNone)
#pragma config(Servo,  srvo_S1_C1_2,    servo2,               tServoNone)
#pragma config(Servo,  srvo_S1_C1_3,    servo3,               tServoNone)
#pragma config(Servo,  srvo_S1_C1_4,    servo4,               tServoNone)
#pragma config(Servo,  srvo_S1_C1_5,    claw_servo,           tServoStandard)
#pragma config(Servo,  srvo_S1_C1_6,    servo6,               tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "joystickdriver.c"

int threshold = 10;
int armStage = 1;
int clawStage = 1;

task clawControl
{
  while (true)
  {
    if (clawStage == 1) { servo[claw_servo] = 120; }
    if (clawStage == 2) { servo[claw_servo] = 180; }
  }
}

task armControl
{
  while (true)
  {
    if (armStage == 1 && SensorValue(Touch) == 1) { motor[Arm] = 0; nMotorEncoder[Arm] = 0; }
    if (armStage == 1 && SensorValue(Touch) == 0) { motor[Arm] = -15; }
    if (armStage == 2) { nMotorEncoderTarget[Arm] = 1000; motor[Arm] = 15; }
    if (armStage == 3) { nMotorEncoderTarget[Arm] = 2000; motor[Arm] = 15; }
  }
}

void initialize()
{
  bFloatDuringInactiveMotorPWM = false;
  nMotorPIDSpeedCtrl[motorA] = mtrNoReg;
  StartTask(clawControl);
  StartTask(armControl);
}

task main
{
  initialize();
  bool btn1 = true;
  bool btn2 = true;
  while (true)
  {
    getJoystickSettings(joystick);

    if (btn1 && joy1Btn(1) == 0) { btn1 = false; }
    if (btn2 && joy1Btn(2) == 0) { btn2 = false; }
    if (joy1Btn(1) == 1 && !btn1 && clawStage == 1) { clawStage = 2; btn1 = true; }
    if (joy1Btn(1) == 1 && !btn1 && clawStage == 2) { clawStage = 1; btn1 = true; }
    if (joy1Btn(2) == 1 && !btn2 && armStage == 1) { armStage = 2; btn2 = true; }
    if (joy1Btn(2) == 1 && !btn2 && armStage == 2) { armStage = 3; btn2 = true; }
    if (joy1Btn(2) == 1 && !btn2 && armStage == 3) { armStage = 1; btn2 = true; }
    if(abs(joystick.joy1_y1)>threshold || abs(joystick.joy1_x2)>threshold)
    {
      motor[LeftFront]  = (joystick.joy1_y1 + joystick.joy1_x2)/2;
      motor[LeftRear] = (joystick.joy1_y1 + joystick.joy1_x2)/2;
      motor[RightFront]  = (joystick.joy1_y1 - joystick.joy1_x2)/2;
      motor[RightRear] = (joystick.joy1_y1 - joystick.joy1_x2)/2;
    }
    else
    {
      motor[LeftFront] = 0;
      motor[LeftRear] = 0;
      motor[RightFront] = 0;
      motor[RightRear] = 0;
    }
  }
}



Thanks for any help you have to offer.

- Greg C.


Mon Apr 09, 2012 1:38 am
Profile
Rookie

Joined: Sat Jan 14, 2012 12:13 pm
Posts: 3
Post Re: Shaft encoder not tracking reverse rotation
I found out that setting negative values to the encoder target causes the motor to float, not brake. I have decided to re-gear the arm, using another reduction, thus reversing the mounting position of the motor, so it spins in a 'forward' rotation while raising. That way I can use positive values, maintain braking, and double up on the rotation strength.

I will follow up with working code when complete.

Thanks,
-Greg C.


Tue Apr 10, 2012 12:13 pm
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.