|
Page 1 of 1
|
[ 4 posts ] |
|
Trouble with the nSyncedMotors command
| Author |
Message |
|
lostitagain
Rookie
Joined: Thu Nov 17, 2011 1:30 am Posts: 6
|
 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 |
|
 |
|
mightor
Moderator
Joined: Wed Mar 05, 2008 8:14 am Posts: 2863 Location: Rotterdam, The Netherlands
|
 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
_________________| Some people, when confronted with a problem, think, "I know, I'll use threads," | and then two they hav erpoblesms. (@nedbat)| My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
| Mon Nov 21, 2011 4:27 pm |
|
 |
|
lostitagain
Rookie
Joined: Thu Nov 17, 2011 1:30 am Posts: 6
|
 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 |
|
 |
|
lostitagain
Rookie
Joined: Thu Nov 17, 2011 1:30 am Posts: 6
|
 Re: Trouble with the nSyncedMotors command
Thanks for the help. It works now.
|
| Mon Nov 21, 2011 5:05 pm |
|
|
|
Page 1 of 1
|
[ 4 posts ] |
|
Who is online |
Users browsing this forum: mightor 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
|
|