View unanswered posts | View active topics It is currently Sat Aug 30, 2014 8:25 am






Reply to topic  [ 3 posts ] 
NXT Motors crossing with DC motors, please help 
Author Message
Rookie

Joined: Tue Feb 22, 2011 5:58 pm
Posts: 1
Post NXT Motors crossing with DC motors, please help
Hello my team and I are having a problem with coding an autonomous program. During the program out Nxt motor must dispense batons, while running the program when the NXT motor is supposed to run the right drive motors turn the robot instead. We have looked over this code and can not find what the problem is, any suggestions help, thanks.

This is the bugged program.
#pragma config(Hubs, S1, HTMotor, HTMotor, HTServo, none)
#pragma config(Motor, motorA, eject, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, mtr_S1_C1_1, right, tmotorNormal, openLoop)
#pragma config(Motor, mtr_S1_C1_2, left, tmotorNormal, openLoop, reversed)
#pragma config(Motor, mtr_S1_C2_1, dab, tmotorNormal, openLoop)
#pragma config(Motor, mtr_S1_C2_2, dispense, tmotorNormal, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
// D -> right
void forward(int clicks, int speed = 30) {
nMotorEncoder[right]=0;
nMotorEncoder[left]=0;
while(nMotorEncoder[right] < clicks)
{
motor[right] = speed;
motor[left] = speed;
}
if(nMotorEncoder[right] >= clicks)
{
nMotorEncoder[right]=0;
nMotorEncoder[left]=0;
motor[right] = 0;
motor[left] = 0;
}

return;
}

void backward(int clicks, int speed = -30) {

nMotorEncoder[right]=0;
nMotorEncoder[left]=0;
while(nMotorEncoder[right] > clicks)
{
motor[right] = speed;
motor[left] = speed;
}
if(nMotorEncoder[right] <= clicks)
{
nMotorEncoder[right]=0;
nMotorEncoder[left]=0;
motor[right] = 0;
motor[left] = 0;
}

return;
}

void turn(int clicks, string dir) {
int speed = 30;
//string dir = "right";
nMotorEncoder[right]=0;
nMotorEncoder[left]=0;
if(dir == "left") {
while(nMotorEncoder[right] < clicks)
{
motor[right] = speed;
motor[left] = -speed;
}
if(nMotorEncoder[right] >= clicks)
{
nMotorEncoder[right]=0;
nMotorEncoder[left]=0;
motor[right] = 0;
motor[left] = 0;
}
}else if(dir == "right") {
while(nMotorEncoder[left] < clicks)
{
motor[right] = -speed;
motor[left] = speed;
}
if(nMotorEncoder[left] >= clicks)
{
nMotorEncoder[right]=0;
nMotorEncoder[left]=0;
motor[right] = 0;
motor[left] = 0;
}
}else{
return;
}

return;
}


task main() {

//toward goal
forward(3000);

//turn along goal
turn(2300, "left");

//dispense
//tilt arm back
motor[dab] = -50;
wait1Msec(500);
motor[dab] = 0;
//kick battons out
{
motor[dispense] = -100;
motor[eject] = 50;
}
wait1Msec(3000);

//forward to next pipe
forward(200);

//dispense again
{
motor[eject] = 50;
}
wait1Msec(3000);

//towards mountain
forward(2700);

//go over mountain
forward(8000);



}


Tue Feb 22, 2011 6:08 pm
Profile
Rookie

Joined: Sun Dec 05, 2010 11:58 am
Posts: 28
Post Re: NXT Motors crossing with DC motors, please help
I didn't know -variable worked. I thought it had to be -1*variable. I could easily be wrong, but you might want to check it.
Where does the program go wrong? How far into the program does the robot get before errors occur?
Could you give a specific function or line number?


Fri Feb 25, 2011 1:56 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: NXT Motors crossing with DC motors, please help
Yes, -variable does work. '-' is a unary operator. It can operate on both constants and variables.


Fri Feb 25, 2011 2:28 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.