View unanswered posts | View active topics It is currently Mon Oct 20, 2014 7:02 am






Reply to topic  [ 10 posts ] 
COMPLEX PROGRAMMING ISSUES (motors, sensors) 
Author Message
Rookie
User avatar

Joined: Thu Dec 30, 2010 10:41 am
Posts: 6
Post COMPLEX PROGRAMMING ISSUES (motors, sensors)
Hi. I'm having some trouble programming robotc to do what i want it to. there are 3 issues that i have right now.

Issue 1

I have an nxt motor mounted on top of my robot, which wounds out a string that raises and lowers a piece of plastic (much like a drawbridge).

There are 4 main positions i want the robot to reach

Vertical: which is nMotorEncoder: 1
High Goal: nMotorEncoder: 360
Medium Goal: nMotorEncoder: 540
Low Goal: nMotorEncoder: 720

I want to assign 4 buttons on the logitech controller to make the plastic piece move to the four positions.

Here is what I have:

if (joy2Btn(1))

{
nMotorEncoderTarget[Lifter]=1 //Robot moves nxt motor from starting position to positon one
motor[Lifter]=70;
while(nMotorRunState[Lifter] != runStateIdle)
}

if (joy2Btn(2))

{
nMotorEncoderTarget[Lifter]=360 //Robot moves nxt motor from starting position to positon two
motor[Lifter]=70;
while(nMotorRunState[Lifter] != runStateIdle)

now that i have that, my question is how do i make the robot wind the wire backwards to go from position two to position one. :breakcomputer:

what i am trying to do is:

button 1= nmotorencoder 1
button 2= nmotorencoder 360
button 3= nmotorencoder 540
button 4=nmotorencoder 720

so if i press a button it will automatically go to that position.



Issue #2

My autonomous program consists of a list of commands which converts to a while loop. I am not so sure how to do so, but here is what i have:
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
............(the program is long, so here is what i have half way).........

motor[Leftd]=0;
motor[Rightd]=0;
nMotorEncoder[Leftd]=0;
nMotorEncoder[Rightd]=0;
nMotorEncoderTarget[Leftd]=2880;
nMotorEncoderTarget[Rightd]=2880; //Robot moves to opponents side.
motor[Leftd]=70;
motor[Rightd]=70;
while(nMotorRunState[Leftd] != runStateIdle || nMotorRunState[Rightd] != runStateIdle)

while(true)
{
if(SensorValue(Infrared) >5)
{motor[Leftd]= -50;
motor[Rightd]=50;}

if(SensorValue(Infrared) <5) *IMPORTANT********IMPORTANT*
{ motor[Leftd]=50; //So once the robot moves to the opponents side, it will automatically look
motor[Rightd]= -50;} for the infrared beacon(middle goal). once the robot is aligned with the
beacon, and the robot is 2 cm away from the goal, then it will run a
if(SensorValue(Infrared) ==5) command list.
{ motor[Leftd]=50;
motor[Rightd]=50;}

if(SensorValue(Infrared)== 5 & SensorValue(Sonar)==2)
{motor[Leftd]=0;
motor[Rightd]=0;
motor[Spinner]=80; //Robot gets batons.
wait10Msec(250);
motor[Spinner]=0;

nMotorEncoder[Leftd]=0;
nMotorEncoder[Rightd]=0;
nMotorEncoderTarget[Leftd]=-500;
nMotorEncoderTarget[Rightd]=-500; //robot backs up.
motor[Leftd]=70;
motor[Rightd]=70;
while(nMotorRunState[Leftd] != runStateIdle || nMotorRunState[Rightd] != runStateIdle)


motor[Leftd]=0;
motor[Rightd]=50;
wait10Msec(40); //Robot pivots towards low goal.
motor[Leftd]=0;
motor[Rightd]=0;

]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]

Also, I am not sure if the command I have:

if(SensorValue(Infrared)== 5 & SensorValue(Sonar)==2)

is correct. What i am trying to say in this line is, "if the robot is aligned, and is 2cm away from the goal"
I am not positive, but shouldn't i use a "else if" or "else" command.



Issue # 3

In my main program for the ftc challenge, I want to assign certain buttons to do command lists.
I have no clue how to do it.
Here is what i have:
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
if (joy2Btn(7)) //If Joy2Btn-7 is pressed

while(true)
{
taskT1 //<----- how do i set up tasks so that i can end this command list using another button
{
if(SensorValue(Infrared) >5)
{motor[Leftd]= -50;
motor[Rightd]=50;}

if(SensorValue(Infrared) <5)
{ motor[Leftd]=50;
motor[Rightd]= -50;}

if(SensorValue(Infrared) ==5)
{ motor[Leftd]=50;
motor[Rightd]=50;}

if(SensorValue(Infrared)== 5 & SensorValue(Sonar)==2)
{motor[Leftd]=0;
motor[Rightd]=0;
motor[Spinner]=80; //Robot gets batons.
wait10Msec(250);
motor[Spinner]=0;
}
}

else if (joy2Btn(8)) //If Joy2Btn-8 is pressed
{
end TaskT1
}

]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]


The task part does not work :cry: , but If you can help me find something to the same effect that would be AWESOME!!!




THANK YOU A MILLION :bigthumb:


Attachments:
File comment: This is the draw bridge design
draw bridge nxt.docx [13.65 KiB]
Downloaded 313 times

_________________
,.-~*´¨¯¨`*·~-.¸-(_Hµ§åM_)-,.-~*´¨¯¨`*·~-.¸
Thu Dec 30, 2010 1:29 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: COMPLEX PROGRAMMING ISSUES (motors, sensors)
It may be easier to break down the problem into smaller problems. For example, in issue 1, let's say if you have a function that will set the arm to different positions and a function to detect a button pressed. Something like this:
Code:
void SetArmPosition(int pos, int power)
{
    nMotorEncoderTarget[Lifter] = pos;
    //
    // Check which direction the motor should go.
    //
    motor[Lifter] = nMotorEncoder[Lifter] < pos? power: -power;
    while(nMotorRunState[Lifter] != runStateIdle)
    {
        // Just wait.
    }
    motor[Lifter] = 0;
}

bool ButtonPressed(int button)
{
    //
    // In general, this function is more useful than just checking joy2Btn(button)
    // because it detects the edge event of a button being pressed instead of
    // keep repeating an action just because the button was being pressed and
    // held down.
    //
    static int prevButtons = 0;
    int currButtons = joystick.joy2_Buttons;
    int buttonMask = 1 << button;
    bool fPressed = ((prevButton & buttonMask) == 0) && (currButtons & buttonMask) != 0);
    prevButtons = currButtons;
    return fPressed;
}

task main()
{
    if (ButtonPressed(1))
    {
        SetArmPosition(1, 70);
    }
    else if (ButtonPressed(2))
    {
        SetArmPosition(360, 70);
    }
    ...


Thu Dec 30, 2010 2:29 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: COMPLEX PROGRAMMING ISSUES (motors, sensors)
Issue 2 is slightly harder. The way your code is structured currently may not quite work because after travelling 2880 encoder clicks without considering your heading, you may be way off. Although you do turn to the IR beacon afterwards, you may be approaching it at an angle. In addition, zone 5 of the IR seeker is very wide (see my other posting on this issue). I would turn the IR seeker sideway and use zone 2, or zone 8 instead. A better way to do it is to keep a pair of motor variables, consider one condition at a time and modify these variables. When all conditions are considered, then you program the motors with the values in the variables. This way you will be driving the 2880 encoder clicks while keeping your heading towards the IR beacon.
Code:
void GotoDispenser()
{
    int leftPower;
    int rightPower;

    nMotorEncoder[Leftd] = 0;
    nMotorEncoder[Rightd] = 0;

    while (((nMotorEncoder[Leftd] + nMotorEncoder[Rightd])/2 < 2880) ||
             (SensorValue(Sonar) > 2))
    {
        if (SensorValue(Infrared) < 2)
        {
            //
            // Turn slightly left. Ideally, the power difference between the wheels
            // should be proportional to the zone difference using PID but a small
            // increment should suffice.
            //
            leftPower = 70;
            rightPower = 75;
        }
        else if (SensorValue(Infrared) > 2)
        {
            leftPower = 75;
            rightPower = 70;
        }
        else
        {
            leftPower = 70;
            rightPower = 70;
        }
        motor[Leftd] = leftPower;
        motor[Rightd] = rightPower;
    }

    motor[Leftd] = 0;
    motor[Rightd] = 0;


Thu Dec 30, 2010 3:21 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: COMPLEX PROGRAMMING ISSUES (motors, sensors)
For issue 3, just use the ButtonPressed function in issue one. But of course, the SetArmPosition function or similar functions you write are probably blocking functions meaning they won't return until the operation is completed. So while the operation is in progress, nothing else can be processed, essentially doing one thing at a time sequentially. A more efficient way to write this is to use a state machine. But that's more complex. If you are interested in how that can be done, you can look at our code at http://proj.titanrobotics.net/hg/Ftc/20 ... t/Right1.h. This is one of the autonomous routines we have.


Thu Dec 30, 2010 3:50 pm
Profile
Rookie
User avatar

Joined: Thu Dec 30, 2010 10:41 am
Posts: 6
Post Re: COMPLEX PROGRAMMING ISSUES (motors, sensors)
sorry that i did not answer back so fast, i was very ill for the last couple of days :cry:

something about acute bronchitis, but anyway.....

First off, thanks for the speedy reply, I was so thrilled by the speed in which that you replied to my questions :P :D :D :D !!!

now for my questions:

for the first issue, your reply was
Quote:

Code:
void SetArmPosition(int pos, int power)
{
nMotorEncoderTarget[Lifter] = pos;
//
// Check which direction the motor should go.
//
motor[Lifter] = nMotorEncoder[Lifter] < pos? power: -power;
while(nMotorRunState[Lifter] != runStateIdle)
{
// Just wait.
}
motor[Lifter] = 0;
}

bool ButtonPressed(int button)
{
static int prevButtons = 0;
int currButtons = joystick.joy2_Buttons;
int buttonMask = 1 << button;
bool fPressed = ((prevButton & buttonMask) == 0) && (currButtons & buttonMask) != 0);
prevButtons = currButtons;
return fPressed;
}

task main()
{
if (ButtonPressed(1))
{
SetArmPosition(1, 70);
}
else if (ButtonPressed(2))
{
SetArmPosition(360, 70);
}


Nevertheless, I am confused on several aspects.

first problem:

when i first copied your program into my program, just as a test, i ran into a butt load of errors :breakcomputer: .



SetArmPosition sometimes shows up as an invalid command.

the first 3 times i tried your program, SetArmPosition wouldn't respond as a command

but that is probably because of the way i had the program setup. I have some pictures to try to explain what i am talking about.



the next problem is that "prevButtons" does not show up as a valid command, but "prevButton" does(sometimes, i found some new errors).

does it make any difference if i went ahead, (btw i am using robotc 2.26 mindstorms) and used "prevButton"?


My next problem is the "void" commands before the "task main"

currently I have:

void SetArmPosition(int pos, int power)
void initializeRobot()

before the task main,
(I did have issues with setting them up correctly, but for now they are fixed.)

For future reference could you please explain how to line up more than one void commands so that there is no conflict.


Last question on issue 1, am I supposed to just copy the program, or do I have to customize certain parts (before the task main)?



:downloading:


Attachments:
nxt3.png
nxt3.png [ 46.72 KiB | Viewed 3466 times ]
nxt2.png
nxt2.png [ 51.76 KiB | Viewed 3467 times ]

_________________
,.-~*´¨¯¨`*·~-.¸-(_Hµ§åM_)-,.-~*´¨¯¨`*·~-.¸
Sun Jan 02, 2011 10:45 pm
Profile
Rookie
User avatar

Joined: Thu Dec 30, 2010 10:41 am
Posts: 6
Post Re: COMPLEX PROGRAMMING ISSUES (motors, sensors)
Issue number 2

How am I to insert your program into mine for it to work properly?

so say, i have this program

Quote:
#pragma config(Hubs, S1, HTMotor, HTServo, HTMotor, none)
#pragma config(Sensor, S2, Magnet, sensorHiTechnicMagnetic)
#pragma config(Sensor, S3, Sonar, sensorSONAR)
#pragma config(Sensor, S4, Infrared, sensorHiTechnicIRSeeker1200)
#pragma config(Motor, motorA, Lifter, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, mtr_S1_C1_1, Leftd, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, mtr_S1_C1_2, Rightd, tmotorNormal, PIDControl, reversed, encoder)
#pragma config(Motor, mtr_S1_C3_1, Spinner, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, mtr_S1_C3_2, motorG, tmotorNormal, openLoop)
#pragma config(Servo, srvo_S1_C2_1, Aservo1, tServoStandard)
#pragma config(Servo, srvo_S1_C2_2, Aservo2, tServoStandard)
#pragma config(Servo, srvo_S1_C2_3, Aservo3, tServoStandard)
#pragma config(Servo, srvo_S1_C2_4, Bservo1, tServoStandard)
#pragma config(Servo, srvo_S1_C2_5, Bservo2, tServoStandard)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

#include "JoystickDriver.c"

void initializeRobot()
{
// Place code here to sinitialize servos to starting positions.
// Sensors are automatically configured and setup by ROBOTC. They may need a brief time to stabilize.

return;
}

task main()
{
initializeRobot();

waitForStart(); // Wait for the beginning of autonomous phase.


nMotorEncoder[Leftd]=0;
nMotorEncoder[Rightd]=0;
nMotorEncoderTarget[Leftd]=2880;
nMotorEncoderTarget[Rightd]=2880; //Robot moves and jumps ramp.
motor[Leftd]=60;
motor[Rightd]=60;
while(nMotorRunState[Leftd] != runStateIdle || nMotorRunState[Rightd] != runStateIdle)

nMotorEncoder[Leftd]=0;
nMotorEncoder[Rightd]=0;
motor[Leftd]=0;
motor[Rightd]=0;
motor[Leftd]=50;
motor[Rightd]=-50; //Robot turns towards middle goal.
wait10Msec(40);


nMotorEncoder[Leftd]=0;
nMotorEncoder[Rightd]=0;
nMotorEncoderTarget[Leftd]=2880;
nMotorEncoderTarget[Rightd]=2880; //Robot moves forward.
motor[Leftd]=60;
motor[Rightd]=60;
while(nMotorRunState[Leftd] != runStateIdle || nMotorRunState[Rightd] != runStateIdle)


this is an example commands list that I would want BEFORE the invent of the Infrared plus Ultrasonic.

so this is theoritically what i would do with your program, given that i am fairly new and not too in depth with the program

Quote:
#pragma config(Hubs, S1, HTMotor, HTServo, HTMotor, none)
#pragma config(Sensor, S2, Magnet, sensorHiTechnicMagnetic)
#pragma config(Sensor, S3, Sonar, sensorSONAR)
#pragma config(Sensor, S4, Infrared, sensorHiTechnicIRSeeker1200)
#pragma config(Motor, motorA, Lifter, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, mtr_S1_C1_1, Leftd, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, mtr_S1_C1_2, Rightd, tmotorNormal, PIDControl, reversed, encoder)
#pragma config(Motor, mtr_S1_C3_1, Spinner, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, mtr_S1_C3_2, motorG, tmotorNormal, openLoop)
#pragma config(Servo, srvo_S1_C2_1, Aservo1, tServoStandard)
#pragma config(Servo, srvo_S1_C2_2, Aservo2, tServoStandard)
#pragma config(Servo, srvo_S1_C2_3, Aservo3, tServoStandard)
#pragma config(Servo, srvo_S1_C2_4, Bservo1, tServoStandard)
#pragma config(Servo, srvo_S1_C2_5, Bservo2, tServoStandard)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

#include "JoystickDriver.c"

void initializeRobot()
{
// Place code here to sinitialize servos to starting positions.
// Sensors are automatically configured and setup by ROBOTC. They may need a brief time to stabilize.

return;
}

task main()
{
initializeRobot();

waitForStart(); // Wait for the beginning of autonomous phase.


nMotorEncoder[Leftd]=0;
nMotorEncoder[Rightd]=0;
nMotorEncoderTarget[Leftd]=2880;
nMotorEncoderTarget[Rightd]=2880; //Robot moves and jumps ramp.
motor[Leftd]=60;
motor[Rightd]=60;
while(nMotorRunState[Leftd] != runStateIdle || nMotorRunState[Rightd] != runStateIdle)

nMotorEncoder[Leftd]=0;
nMotorEncoder[Rightd]=0;
motor[Leftd]=0;
motor[Rightd]=0;
motor[Leftd]=50;
motor[Rightd]=-50; //Robot turns towards middle goal.
wait10Msec(40);


nMotorEncoder[Leftd]=0;
nMotorEncoder[Rightd]=0;
nMotorEncoderTarget[Leftd]=2880;
nMotorEncoderTarget[Rightd]=2880; //Robot moves forward.
motor[Leftd]=60;
motor[Rightd]=60;
while(nMotorRunState[Leftd] != runStateIdle || nMotorRunState[Rightd] != runStateIdle)

void GotoDispenser()
{
int leftPower;
int rightPower;

nMotorEncoder[Leftd] = 0;
nMotorEncoder[Rightd] = 0;

while (((nMotorEncoder[Leftd] + nMotorEncoder[Rightd])/2 < 2880) ||
(SensorValue(Sonar) > 2))
{
if (SensorValue(Infrared) < 2)
{
//
// Turn slightly left. Ideally, the power difference between the wheels
// should be proportional to the zone difference using PID but a small
// increment should suffice.
//
leftPower = 70;
rightPower = 75;
}
else if (SensorValue(Infrared) > 2)
{
leftPower = 75;
rightPower = 70;
}
else
{
leftPower = 70;
rightPower = 70;
}
motor[Leftd] = leftPower;
motor[Rightd] = rightPower;
}

motor[Leftd] = 0;
motor[Rightd] = 0;
{


*IMPORTANT*


Also, to add to your program, say if two sensors, like infrared and ultrasonic, both give a certain reading,

how do i put into robotc to run a list of programs after the two readings

example

Quote:
nMotorEncoder[Leftd] = 0;
nMotorEncoder[Rightd] = 0;

while (((nMotorEncoder[Leftd] + nMotorEncoder[Rightd])/2 < 2880) ||
(SensorValue(Sonar) > 2))
{
if (SensorValue(Infrared) < 2)
{
leftPower = 70;
rightPower = 75;
}
else if (SensorValue(Infrared) > 2)
{
leftPower = 75;
rightPower = 70;
}
else if (SensorValue(Infrared) = 2)
{
leftPower = 70;
rightPower = 70;
}
else if (SensorValue(Infrared) = 2) && (SensorValue(Ultrasonic) = 3)
{
*COMMANDS*
*COMMANDS*
*COMMANDS*
*COMMANDS*
*COMMANDS*
*COMMANDS*
}
motor[Leftd] = 0;
motor[Rightd] = 0;




of course this example, in reality, would be directly connected to the first one.

thanks

_________________
,.-~*´¨¯¨`*·~-.¸-(_Hµ§åM_)-,.-~*´¨¯¨`*·~-.¸


Last edited by husammoseswadi on Mon Jan 03, 2011 8:26 pm, edited 2 times in total.



Sun Jan 02, 2011 11:43 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: COMPLEX PROGRAMMING ISSUES (motors, sensors)
The example code in my previous posts are meant to be examples showing you how you can implement what you want. Since it is example code, I did not compile it for error checking. There are typos in the code but the compiler errors told you exactly what they are. For example, the following code has a typo that I am missing a closing parenthesis and prevButton should have been prevButtons.
Code:
bool fPressed = ((prevButtons & buttonMask) == 0) && (currButtons & buttonMask) != 0));

If you fix all the typos in the code according to the compiler errors, you should be fine.


Mon Jan 03, 2011 3:12 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: COMPLEX PROGRAMMING ISSUES (motors, sensors)
I have cut and pasted the code into RobotC. Spent quite some time to clean up the indentation of the code so I can read and understand the code better. After correcting some minor typos, it compiled successfully. The corrected code is attached below. However, it doesn't mean it is doing what you want since I don't know the ultimate intention of your code, this is my best guess of what you want the code to do. This code looks like it's for the GetOverIt competition. If so, you have several problems. Is this code for the autonomous phase? If so, you should not have code reading the jostick buttons during autonomous. In any case, you should still treat this as an example (i.e. don't use this code verbatim as your final code). You need to add a lot more code to pull the batons, for example. Obviously, your robot is not starting at a position that the IR beacon is straight ahead. So you probably need to add some more code to drive forward and turn etc. Good luck.
Code:
#pragma config(Hubs, S1, HTMotor, HTServo, HTMotor, none)
#pragma config(Sensor, S2, Magnet, sensorHiTechnicMagnetic)
#pragma config(Sensor, S3, Sonar, sensorSONAR)
#pragma config(Sensor, S4, Infrared, sensorHiTechnicIRSeeker1200)
#pragma config(Motor, motorA, Lifter, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, mtr_S1_C1_1, Leftd, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, mtr_S1_C1_2, Rightd, tmotorNormal, PIDControl, reversed, encoder)
#pragma config(Motor, mtr_S1_C3_1, Spinner, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, mtr_S1_C3_2, motorG, tmotorNormal, openLoop)
#pragma config(Servo, srvo_S1_C2_1, Aservo1, tServoStandard)
#pragma config(Servo, srvo_S1_C2_2, Aservo2, tServoStandard)
#pragma config(Servo, srvo_S1_C2_3, Aservo3, tServoStandard)
#pragma config(Servo, srvo_S1_C2_4, Bservo1, tServoStandard)
#pragma config(Servo, srvo_S1_C2_5, Bservo2, tServoStandard)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

#include "JoystickDriver.c"

void initializeRobot()
{
    // Place code here to sinitialize servos to starting positions.
    // Sensors are automatically configured and setup by ROBOTC. They may need a brief time to stabilize.

    return;
}

void GotoDispenser()
{
    int leftPower;
    int rightPower;

    nMotorEncoder[Leftd] = 0;
    nMotorEncoder[Rightd] = 0;

    while (((nMotorEncoder[Leftd] + nMotorEncoder[Rightd])/2 < 2880) ||
           (SensorValue(Sonar) > 2))
    {
        if (SensorValue(Infrared) < 2)
        {
            //
            // Turn slightly left. Ideally, the power difference between the wheels
            // should be proportional to the zone difference using PID but a small
            // increment should suffice.
            //
            leftPower = 70;
            rightPower = 75;
        }
        else if (SensorValue(Infrared) > 2)
        {
            leftPower = 75;
            rightPower = 70;
        }
        else
        {
            leftPower = 70;
            rightPower = 70;
        }
        motor[Leftd] = leftPower;
        motor[Rightd] = rightPower;
    }

    motor[Leftd] = 0;
    motor[Rightd] = 0;
}

bool ButtonPressed(int button)
{
    static int prevButtons = 0;
    int currButtons;
    int buttonMask;
    bool fPressed;
    //
    // In general, this function is more useful than just checking joy2Btn(button)
    // because it detects the edge event of a button being pressed instead of
    // keep repeating an action just because the button was being pressed and
    // held down.
    //
    currButtons = joystick.joy2_Buttons;
    buttonMask = 1 << button;
    fPressed = ((prevButtons & buttonMask) == 0) &&
               ((currButtons & buttonMask) != 0);
    prevButtons = currButtons;
    return fPressed;
}

void SetArmPosition(int pos, int power)
{
    nMotorEncoderTarget[Lifter] = pos;
    //
    // Check which direction the motor should go.
    //
    motor[Lifter] = nMotorEncoder[Lifter] < pos? power: -power;
    while(nMotorRunState[Lifter] != runStateIdle)
    {
        // Just wait.
    }
    motor[Lifter] = 0;
}

task main()
{
    initializeRobot();

    waitForStart(); // Wait for the beginning of autonomous phase.

    GotoDispenser();
    while (true)
    {
        if (ButtonPressed(1))
        {
            SetArmPosition(1, 70);
        }
        else if (ButtonPressed(2))
        {
            SetArmPosition(360, 70);
        }
    }
}


Mon Jan 03, 2011 3:55 am
Profile
Rookie
User avatar

Joined: Thu Dec 30, 2010 10:41 am
Posts: 6
Post Re: COMPLEX PROGRAMMING ISSUES (motors, sensors)
Oh, Im sorry if i didn't clarify....


Issue 1 is for running the robot with the controller

Issue 2 is for autonomous

also in one of my pictures of the errors posted, there is a line that reads

_________________
,.-~*´¨¯¨`*·~-.¸-(_Hµ§åM_)-,.-~*´¨¯¨`*·~-.¸


Mon Jan 03, 2011 8:49 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: COMPLEX PROGRAMMING ISSUES (motors, sensors)
In any case, the example I posted should have answers to all the issues you listed.


Mon Jan 03, 2011 10:17 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 10 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.