View unanswered posts | View active topics It is currently Wed Apr 16, 2014 7:45 am






Reply to topic  [ 2 posts ] 
RobotC program problems... 
Author Message
Rookie

Joined: Wed Feb 03, 2010 3:47 pm
Posts: 1
Post RobotC program problems...
Hi, I've been having some trouble getting my program for RobotC working. I have no clue what I'm doing wrong or what's going on. The program is "working" as in it runs on the NXT brick but my motors won't turn! Please get back to me ASAP please. Thanks

#pragma config(Motor, motorA, , tmotorNormal, PIDControl, )
#pragma config(Motor, motorB, , tmotorNormal, PIDControl, )

#include "Joystickdriver.c"

void initialize()
{
return;
}

void movementControl()
{
int powerControl;
int directionControl;

powerControl = joystick.joy1_y1;
directionControl = joystick.joy1_x1;
if (directionControl < 0)
{
// Turn left

motor[motorA] = powerControl;
motor[motorB] = powerControl * (65 + directionControl) / 65;
}

else
{
// Turn right

motor[motorA] = powerControl;
motor[motorB] = powerControl * (65 - directionControl) / 65;
}
}

void gunFire()
{

if(joy1Btn(8) != 0)
{
motor[motorB] = 255;
motor[motorC] = 255;
motor[motorD] = 50;
}

else
{
motor[motorB] = 0;
motor[motorC] = 0;
motor[motorD] = 0;
}
}

void gunControl()

{
servoRight = 0 at bottom, servoLeft = 255 at bottom

if(joy1Btn)
return 0;
}

task main();
{
while (true)
{
initialize();
getJoystickSettings(joystick);
movementControl();
gunControl();
gunFire();
}
}


Wed Feb 03, 2010 3:54 pm
Profile
Expert

Joined: Mon Oct 27, 2008 9:59 pm
Posts: 137
Post Re: RobotC program problems...
Reading your code you have a number of issues. However, I would still expect to see your motorA moving in response to joy1_y1... so you likely also have a wiring/hardware issue as well. It is best to troubleshoot those types of issues using the debug windows in ROBOTC rather than with unproven code which may or may not work.

As for just a few of the issues which stuck out to me:
1. You're calling an initialize function (which does nothing) every time in you main loop. I would place it outside of the loop at the beginning for your main task so it is just called once.
2. You reference motors motorC and motorD in your gunFire function, but I do not see them defined in the pragmas
3. You reference servos in the gunControl function, but these are also not defined in any pragmas, and there are what appear to be comments with no comment syntax in there.
4. You reference motorB in both the movementControl and gunFire functions. I expect this is by accident and would cause the motor to behave schizophrenically.
5. In your movementControl function:
Code:
   if (directionControl < 0)
   {
      // Turn left

      motor[motorA] = powerControl;
      motor[motorB] = powerControl * (65 + directionControl) / 65;
   }

   else
   {
      // Turn right

      motor[motorA] = powerControl;
      motor[motorB] = powerControl * (65 - directionControl) / 65;
   }

I do not believe this will do what you think it will. Where did the 'magic number' 65 come from? As I recall, the analog sticks return values between -127 and 128. This code is also subject to precision errors since all the variables are defined as integers, but when you divide by 65 the result will not likely be what you're looking for.

Hope this helps.


Thu Feb 04, 2010 11:07 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 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.