View unanswered posts | View active topics It is currently Mon Sep 01, 2014 4:22 am






Reply to topic  [ 4 posts ] 
Doing multiple commands at once 
Author Message
Rookie

Joined: Sat Jun 27, 2009 4:52 pm
Posts: 7
Post Doing multiple commands at once
I am the sole programmer at my school, so when I encounter a problem, it is up to me to figure it out.
I cannot figure out how to program my teleop program to run the joysticks and the if(joy1Btn(5) == 1) commands at once.
In other words, I cannot figure out how to move the robot, use a button, then move it again or use another button.
This is my program:


Attachments:
tank version v.c [2.92 KiB]
Downloaded 194 times
Tue Feb 16, 2010 12:42 pm
Profile
Expert

Joined: Mon Oct 27, 2008 9:59 pm
Posts: 137
Post Re: Doing multiple commands at once
Looking at your code, I assume you want to avoid waiting for the encoder to reach its target in the toby() function as well as the 2 second wait for your ball shooter.

There are several ways to tackle this and most of them involve tasks.
In ROBOTC, a task is analogous to a thread so that each task of the same priority time share the CPU. So if your main task contained the code for the drive train, you could have a separate task for the other functions which contain separate while loops or wait statements.

Note that you probably only want to get the joystick settings (the latest packet) from a single task (usually your main task) even if other tasks read the current joystick values. I did notice a bug in your code where you appear to be getting the joystick settings only once at the beginning of your main task before the endless loop. You want to move that into the top of the loop so that you can get the latest joystick values on every iteration of the loop.

That is, change this:
Code:
task main()
{
   //initialization stuff
   getJoystickSettings(joystick);
   
   while(true)
   {
      //control stuff
   }
}
to something like this:
Code:
task main()
{
   //initialization stuff

   while(true)
   {
      getJoystickSettings(joystick);   
      //control stuff
   }
}


Tue Feb 16, 2010 5:38 pm
Profile
Rookie

Joined: Sat Jun 27, 2009 4:52 pm
Posts: 7
Post Re: Doing multiple commands at once
Thanks. I have a new problem, but not as major. I want my buttons to control the movement of the motors directly. For example, if I press button four, I want motor B to run only while I press button four. Once I release button four, then I want motor B to stop.


Thu Feb 18, 2010 10:36 am
Profile
Expert

Joined: Mon Oct 27, 2008 9:59 pm
Posts: 137
Post Re: Doing multiple commands at once
That should be fairly straightforward.

For example:
Code:
if(joy1Btn(x)) //if button pressed
{
   motor[motorB]=100; //motor on
}
else //button not pressed
{
   motor[motorB]=0; //motor off
}


Thu Feb 18, 2010 1:36 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.