View unanswered posts | View active topics It is currently Mon Oct 20, 2014 6:07 am






Reply to topic  [ 4 posts ] 
Trouble with the nSyncedMotors command 
Author Message
Rookie

Joined: Thu Nov 17, 2011 1:30 am
Posts: 6
Post Trouble with the nSyncedMotors command
I am trying to set up a function for turning. It takes an int input for which direction to turn, sets up the synched motors for the correct direction, and then runs the motor to turn.

When I step through the program it fails with the switch line highlighted and gives the following:

Byte Code Interpreter Exception:
Program Slot: 0. Task ID: main[0]
Error at PC: Sub: turn+0x0008
Task PC: Sub: turn+0x0008.
TaskState: 'Exception'
Exception Type: 'Cannot Update Slave Sync(60)'

The code for the turn function is:

// Turns the robot, Case 0 is for left turn, Case 1 is for right turn
void turn(int dir)
{

// Set motorencoders to zero to measure out a 90 degree turn
nMotorEncoder[motorB] = 0;
nMotorEncoder[motorC] = 0;

switch (dir)
{
// Left Turn
case 0:
if (nSyncedMotors != synchBC)
nSyncedMotors = synchBC;
if (nSyncedTurnRatio != -100)
nSyncedTurnRatio = -100;
motor[motorB] = TURNSPEED;

// Right turn.
case 1:
if (nSyncedMotors != synchCB)
nSyncedMotors = synchCB;
if (nSyncedTurnRatio != -100)
nSyncedTurnRatio = -100;
motor[motorC] = TURNSPEED;
}
}

I set up the if statements because the robot would crash if it was given the same nSyncedMotors command twice in a row. TURNSPEED is a #define constant.


Mon Nov 21, 2011 4:05 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3224
Location: Rotterdam, The Netherlands
Post Re: Trouble with the nSyncedMotors command
I'm afraid you can't reset the encoders of the slave motor :) Remove the nMotorEncoder[motorC] = 0; and it'll work fine. Is there a reason you need to reset the encoders all the time?

- 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]


Mon Nov 21, 2011 4:27 pm
Profile WWW
Rookie

Joined: Thu Nov 17, 2011 1:30 am
Posts: 6
Post Re: Trouble with the nSyncedMotors command
that was a remnant of my original version where I was telling it to make 90 degree turns


Mon Nov 21, 2011 5:01 pm
Profile
Rookie

Joined: Thu Nov 17, 2011 1:30 am
Posts: 6
Post Re: Trouble with the nSyncedMotors command
Thanks for the help. It works now.


Mon Nov 21, 2011 5:05 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 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.