View unanswered posts | View active topics It is currently Sat Oct 25, 2014 5:11 pm






Reply to topic  [ 3 posts ] 
Can't Synch Motors 
Author Message
Rookie

Joined: Thu Oct 16, 2008 8:22 pm
Posts: 3
Post Can't Synch Motors
Can anyone tell me why motors A and B won't synch? I can't seem to figure it out. I don't get any errors while running the program, but immediately when I turn it off it gives me an error that says it failed to update the slave...



#pragma config(Motor, motorA, , tmotorNormal, PIDControl)
#pragma config(Motor, motorB, , tmotorNormal, PIDControl)
#pragma config(Motor, mtr_S1_C1_1, motorD, tmotorNormal, openLoop)
#pragma config(Motor, mtr_S1_C1_2, motorE, tmotorNormal, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

#include "JoystickDriver.c"

task main()
{
while (true)
{
getJoystickSettings(joystick);
if (joystick.joy1_y1 > 5 || joystick.joy1_y1 < -5)
motor[motorD] = -joystick.joy1_y1;
else
motor[motorD] = 0;
if (joystick.joy1_y2 > 5 || joystick.joy1_y2 < -5)
motor[motorE] = joystick.joy1_y2;
else
motor[motorE] = 0;

nPidUpdateIntervalNxt = 10;
nMotorPIDSpeedCtrl[motorA] = mtrEncoderReg;
nMotorPIDSpeedCtrl[motorB] = mtrEncoderReg;
nSyncedMotors = synchAB;
nSyncedTurnRatio = 100;
if (joy1Btn(2))
{
motor[motorA] = 80;
}
else
if (joy1Btn(3))
{
motor[motorA] = -80;
}
else
{
motor[motorA] = 0;
}
}
}[/color]


Thu Oct 30, 2008 9:13 pm
Profile
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:42 am
Posts: 613
Post Re: Can't Synch Motors
Few Issues here...

1. You're missing the top line of your code. You need to define where your FTC hardware is connected on the NXT. You can generate this line by going into Motors and Sensor Setup. This is what's generating the error message when you run your code.
Code:
#pragma config(Hubs,  S1, HTMotor,  HTServo,  none,     none)


2. I tried the syncing out... it seems to be working by turning on both motors... but the "sync" part of it doesn't seem to be there. I'll have to investigate this a little more

Edited Code:
Code:
#pragma config(Hubs,  S1, HTMotor,  HTServo,  none,     none)
#pragma config(Motor,  motorA,          ,              tmotorNormal, PIDControl)
#pragma config(Motor,  motorB,          ,              tmotorNormal, PIDControl)
#pragma config(Motor,  mtr_S1_C1_1,     motorD,        tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorNormal, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "JoystickDriver.c"

task main()
{
  while (true)
  {
    getJoystickSettings(joystick);
    if (joystick.joy1_y1 > 5 || joystick.joy1_y1 < -5)
      motor[motorD] = -joystick.joy1_y1;
    else
      motor[motorD] = 0;
    if (joystick.joy1_y2 > 5 || joystick.joy1_y2 < -5)
      motor[motorE] = joystick.joy1_y2;
    else
      motor[motorE] = 0;

    nMotorPIDSpeedCtrl[motorA] = mtrEncoderReg;
    nMotorPIDSpeedCtrl[motorB] = mtrEncoderReg;
    nSyncedMotors = synchAB;
    nSyncedTurnRatio = 100;

    if (joy1Btn(2))
    {
      motor[motorA] = 80;
    }
    else
      if (joy1Btn(3))
    {
      motor[motorA] = -80;
    }
    else
    {
      motor[motorA] = 0;
    }
  }
}

_________________
Timothy Friez
ROBOTC Developer - SW Engineer
tfriez@robotc.net


Fri Oct 31, 2008 4:16 pm
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 615
Post Re: Can't Synch Motors
I cannot find anything wrong with the firmware. There is a bug in your program though.

The code to setup motor synchronization should be moved outside of the loop. Whenever synchronization is setup it "resets" the synchronization state and starts over. You're running through the loop 100s (1000s?) of times a second and each time through the synchronization it looses the "history" needed to keep the motors in sync. Once I moved this outside the loop, everything works fine.

For example, manually hold motor C and you'll notice motor A will slow down to keep speed with A.

Here's the revised program.

Code:
#pragma config(Hubs,  S1, HTMotor,  HTServo,  none,     none)
#pragma config(Motor,  motorA,          ,              tmotorNormal, PIDControl)
#pragma config(Motor,  motorB,          ,              tmotorNormal, PIDControl)
#pragma config(Motor,  mtr_S1_C1_1,     motorD,        tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorNormal, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "JoystickDriver.c"

task main()
{
  nMotorPIDSpeedCtrl[motorA] = mtrEncoderReg;
  nMotorPIDSpeedCtrl[motorB] = mtrEncoderReg;
  nSyncedMotors = synchAB;
  nSyncedTurnRatio = 100;

  while (true)
  {
    getJoystickSettings(joystick);
    if (joystick.joy1_y1 > 5 || joystick.joy1_y1 < -5)
      motor[motorD] = -joystick.joy1_y1;
    else
      motor[motorD] = 0;
    if (joystick.joy1_y2 > 5 || joystick.joy1_y2 < -5)
      motor[motorE] = joystick.joy1_y2;
    else
      motor[motorE] = 0;

    nPidUpdateInterval = 10;
    if (joy1Btn(2))
    {
      motor[motorA] = 80;
    }
    else
      if (joy1Btn(3))
    {
      motor[motorA] = -80;
    }
    else
    {
      motor[motorA] = 0;
    }
  }
}


Mon Nov 03, 2008 4:17 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 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.