View unanswered posts | View active topics It is currently Sat Sep 20, 2014 4:18 pm






Reply to topic  [ 2 posts ] 
Encoders Help 
Author Message
Rookie

Joined: Sat Nov 17, 2012 10:27 pm
Posts: 5
Post Encoders Help
Hi, it's me again, with another programming problem. I am trying to use encoder programming instead of using time, but my program isn't working. Instead of reaching the set number of encoder counts, when I start the program, it just continuously goes forward. Can someone please help on what I am doing wrong? Help will be greatly appreciated.

Thanks,
Lincoln

Code:
#pragma config(Hubs,  S1, HTMotor,  HTServo,  none,     none)
#pragma config(Hubs,  S2, HTMotor,  none,     none,     none)
#pragma config(Sensor, S1,     ,               sensorI2CMuxController)
#pragma config(Sensor, S2,     ,               sensorI2CMuxController)
#pragma config(Sensor, S3,     ,               sensorHiTechnicIRSeeker1200)
#pragma config(Motor,  mtr_S1_C1_1,     motorD,        tmotorTetrix, openLoop, encoder)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorTetrix, openLoop, reversed)
#pragma config(Motor,  mtr_S2_C1_1,     motorF,        tmotorTetrix, PIDControl)
#pragma config(Motor,  mtr_S2_C1_2,     motorG,        tmotorTetrix, PIDControl, reversed)
#pragma config(Servo,  srvo_S1_C2_1,    servo1,               tServoStandard)
#pragma config(Servo,  srvo_S1_C2_2,    servo2,               tServoStandard)
#pragma config(Servo,  srvo_S1_C2_3,    servo3,               tServoContinuousRotation)
#pragma config(Servo,  srvo_S1_C2_4,    servo4,               tServoContinuousRotation)
#pragma config(Servo,  srvo_S1_C2_5,    servo5,               tServoStandard)
#pragma config(Servo,  srvo_S1_C2_6,    servo6,               tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "JoystickDriver.c"




void initializeRobot()
{
   servo[servo1]=255;
   servo[servo2]=0;
   servo[servo3]=128;
   servo[servo4]=128;
   servo[servo5]=255;
    nMotorEncoder[motorD] = 0;
  nMotorEncoder[motorE] = 0;
   return;
}




task main()
{
   initializeRobot();

     servo[servo1]=255;
   servo[servo2]=0;
   servo[servo3]=128;
   servo[servo4]=128;
   servo[servo5]=110;
   motor[motorF]=0;
   motor[motorG]=0;
nMotorEncoder[motorE] = 0;
  nMotorEncoder[motorD] = 0;

  nMotorEncoderTarget[motorE] = 0;
  nMotorEncoderTarget[motorD] = 462;

  motor[motorE] = 0;
  motor[motorD] = 50;

  while (nMotorRunState[motorE] != runStateIdle || nMotorRunState[motorD] != runStateIdle)
  {

  }

  motor[motorE] = 0;
  motor[motorD] = 0;

  wait1Msec(3000);

        servo[servo1]=255;
   servo[servo2]=0;
   servo[servo3]=128;
   servo[servo4]=128;
   servo[servo5]=110;
   motor[motorF]=0;
   motor[motorG]=0;
nMotorEncoder[motorE] = 0;
  nMotorEncoder[motorD] = 0;

  nMotorEncoderTarget[motorE] = 7312;
  nMotorEncoderTarget[motorD] = 7312;

  motor[motorE] = 50;
  motor[motorD] = 50;

  while (nMotorRunState[motorE] != runStateIdle || nMotorRunState[motorD] != runStateIdle)
  {

  }

  motor[motorE] = 0;
  motor[motorD] = 0;

  wait1Msec(3000);

        servo[servo1]=255;
   servo[servo2]=0;
   servo[servo3]=128;
   servo[servo4]=128;
   servo[servo5]=110;
   motor[motorF]=0;
   motor[motorG]=0;

nMotorEncoder[motorE] = 0;
  nMotorEncoder[motorD] = 0;

  nMotorEncoderTarget[motorE] = 462;
  nMotorEncoderTarget[motorD] = 0;

  motor[motorE] = 50;
  motor[motorD] = 1;

  while (nMotorRunState[motorE] != runStateIdle || nMotorRunState[motorD] != runStateIdle)
  {

  }

  motor[motorE] = 0;
  motor[motorD] = 0;

  wait1Msec(3000);


Sat Feb 09, 2013 3:41 pm
Profile
Rookie

Joined: Wed Feb 06, 2013 7:40 pm
Posts: 3
Post Re: Encoders Help
I'm not sure about the NXT hook up but on cortex the encoders can be backwards and this will cause the problem you are describing.


Sat Feb 09, 2013 9:27 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.