View unanswered posts | View active topics It is currently Mon Aug 03, 2020 11:12 pm

Reply to topic  [ 3 posts ] 
Motor control 
Author Message
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Motor control
Hey peeps,

I've recently come into possession of a VEX Cortex set (the super bundle) and am having a lot of fun with it. However, I am fairly new to this hardware platform so I am keen to know a few things.

  • I noticed in the header files this platform allows you to associate a motor with an encoder. How is this done?
  • Is it possible to regulate the motor speeds based on the encoder counts so that I can synchronise two motors so the robot can run straight?

I'd really rather not have to write my own motor control code, to be honest. If anyone already has some (or knows how to achieve the above without this) then I'd love to hear from them :)

- Xander

| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]

Fri Dec 31, 2010 8:14 am
Profile WWW
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: Motor control
An encoder is mapped to a motor by using th mapEncoderToMotor(nMotorIndex, nSensorIndex); function.

sudo rm -rf /

Mon Jan 10, 2011 10:14 pm

Joined: Mon Jan 10, 2011 11:39 pm
Posts: 16
Post Re: Motor control
Yes I have done this. I use it sometimes, its an integrated drive in my framework for RobotC.
Heres an example (hasnt been fully tested but should work fine):
void ShaftTankDrive()
  // This flips the motors around so they go in the right direction
  bMotorFlippedMode[port2] = 0;
  bMotorFlippedMode[port3] = 1;
  bMotorFlippedMode[port4] = 0;
  bMotorFlippedMode[port5] = 1;

  // Now lets define the temporary variables
  int LeftSide;
  int RightSide;

  int ChangeVar;
  //int SensorAverage;

  // Amount to speed up/slow down by
  ChangeVar = (Sensors.in1 - Sensors.in2);

  // Are we there yet? >:(
  //SensorAverage = (Sensors.in1 + Sensors.in2) / 2;

  LeftSide = Controller.Ch3 - ChangeVar;
  LeftSide = Math_Clamp(LeftSide,-127,127);

  RightSide = Controller.Ch2 + ChangeVar;
  RightSide = Math_Clamp(RightSide,-127,127);

  // This sets motor ports 1 and 2 to Controller.Ch2 value, 3 and 4 to Controller.Ch3 value.
  Motors.mtr2 = Math_Clamp(RightSide, -127, 127);
  Motors.mtr3 = Math_Clamp(RightSide, -127, 127);
  Motors.mtr4 = Math_Clamp(LeftSide, -127, 127);
  Motors.mtr5 = Math_Clamp(LeftSide, -127, 127);

Its dependent on my Framework so it wont work straight up.


Stefan Andres Charsley

Mon Jan 10, 2011 11:45 pm
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest

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.