View unanswered posts | View active topics It is currently Wed Jul 30, 2014 4:33 am






Reply to topic  [ 5 posts ] 
Magnet Sensor conflicting with Robot Function 
Author Message
Rookie
User avatar

Joined: Thu Dec 30, 2010 10:41 am
Posts: 6
Post Magnet Sensor conflicting with Robot Function
Hi. Our team is using a magnet sensor this year, and like last year, the magnet sensor conflicts with the robot. The magnet sensor works fine alone, but when added to the main task, all other functions on the robot becomes jumbled and refuse to work.

We are currently trying subgroups but are not too sure how to use it.


Quote:
#pragma config(Hubs, S1, HTServo, HTMotor, none, none)
#pragma config(Hubs, S2, HTMotor, none, none, none)
#pragma config(Hubs, S3, HTServo, none, none, none)
#pragma config(Sensor, S2, Magnet, sensorNone)
#pragma config(Sensor, S3, Sonar, sensorNone)
#pragma config(Sensor, S4, Magnet, sensorHiTechnicMagnetic)
#pragma config(Motor, mtr_S1_C2_1, Leftd, tmotorNormal, openLoop)
#pragma config(Motor, mtr_S1_C2_2, Rightd, tmotorNormal, openLoop, reversed)
#pragma config(Motor, mtr_S2_C1_1, lifter, tmotorNormal, openLoop)
#pragma config(Motor, mtr_S2_C1_2, sweeper, tmotorNormal, openLoop)
#pragma config(Servo, srvo_S1_C1_1, LiftServo1, tServoStandard)
#pragma config(Servo, srvo_S1_C1_2, MagnetElbow, tServoStandard)
#pragma config(Servo, srvo_S1_C1_3, MagnetSholder, tServoStandard)
#pragma config(Servo, srvo_S1_C1_4, MagnetServo, tServoStandard)
#pragma config(Servo, srvo_S1_C1_5, servo5, tServoNone)
#pragma config(Servo, srvo_S1_C1_6, StopServo, tServoStandard)
#pragma config(Servo, srvo_S3_C1_1, servo7, tServoNone)
#pragma config(Servo, srvo_S3_C1_2, servo8, tServoNone)
#pragma config(Servo, srvo_S3_C1_3, servo9, tServoNone)
#pragma config(Servo, srvo_S3_C1_4, servo10, tServoNone)
#pragma config(Servo, srvo_S3_C1_5, servo11, tServoNone)
#pragma config(Servo, srvo_S3_C1_6, LiftServo2, tServoStandard)
#pragma config(SrvoPosition, Position01, 131, 129, 129, 128, 128, 128, 128, 128)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

#include "JoystickDriver.c"

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

return;
}

task main()
{
initializeRobot();

int threshold = 20;




while (true)

{
getJoystickSettings(joystick);

if(abs(joystick.joy1_y2) > threshold) // If the right analog stick's Y-axis readings are either above or below the threshold:
{
motor[Rightd] = joystick.joy1_y2; // Right drive is assigned a power level equal to the right analog stick's Y-axis reading.
}
else // Else if the readings are within the threshold:
{
motor[Rightd] = 0; // Right drive is stopped with a power level of 0.
}

if(abs(joystick.joy1_y1) > threshold) // If the left analog stick's Y-axis readings are either above or below the threshold:
{
motor[Leftd] = joystick.joy1_y1; // Left drive is assigned a power level equal to the left analog stick's Y-axis reading.
}
else // Else if the readings are within the threshold:
{
motor[Leftd] = 0; // Leftdrive is stopped with a power level of 0.
}

{


if(SensorValue[Magnet] <640 )

servo[MagnetServo] = 127;
wait10Msec(250);


if (SensorValue[Magnet] >660 )


servo[MagnetServo] = 127;
wait10Msec(250);

if(SensorValue[Magnet] >=451)
{
servo[MagnetServo] = 255;
}



// First controller buttons below



if (joy1Btn(5)==1) //If Joy1-Button2 is pressed
{
servoTarget[LiftServo1] = 110; //lifts left side servo up to this position
servoTarget[LiftServo2] = 170; //lifts right side servo up to this position
}

else if (joy1Btn(7)==1) //If Joy1-Button3 is pressed

{

servoTarget[LiftServo1] = 20; //Turn arm on at -100% power
servoTarget[LiftServo2] = 210; //lifts right side servo down to this position


}


if (joy1Btn(4)==1)

{
motor[lifter] = -50;


}

else if (joy1Btn(1)==1)

{
motor[lifter] = 50;

}
else if (joy1Btn(2)==1)
{
motor[lifter] = 50;
wait10Msec(10);
}
else if (joy1Btn(3)==1)
{
motor[lifter]= -50;
wait10Msec(10);
}

else
{
motor[lifter] = 0;

}




// second controller entered below





// if (joy2Btn(5)) //If Joy2-Button 1 is pressed

{

//Open left arm at set value

}

if (joy2Btn(1)==1) //If Joy2-Button 1 is pressed

{

servoTarget[MagnetSholder]=34 //Swing the magnetic arm out at set value



;}

if (joy2Btn(4)==1) //If joy2-Button 4 is pressed

{

servoTarget[MagnetElbow]=210;
wait10Msec(30);
servoTarget[MagnetSholder]=165 //Bring the magnetic arm back to robot (at set value)



;}

if (joy2Btn(2)==1) //If joy2-Button 2 is pressed

{

servoTarget[MagnetElbow]=140 //Turn the magnet scoop half-way down (at set value)

// servoTarget[Bservo1] = 290; //
;}

else if (joy2Btn(3)==1) //If Joy2-Button 3 is pressed

{

servoTarget[MagnetElbow]=85; //Turn the magnet scoop all the way down (at set value)

//servoTarget[Bservo1] = 100;
}



if (joy2Btn(9)==1) //If Joy2-Button 9 is pressed

{

servoTarget[MagnetServo]=130; //The magnet flap will go up (to set value)

}

else if (joy2Btn(10)==1) //If Joy2-Button 10 is pressed

{

servoTarget[MagnetServo]=218; //The magnet flap will go back down (to set value)

}




if (joy2Btn(6)==1) //If Joy2-Button 6 is pressed

{

servoTarget[StopServo]= 30; //The flap stopping the balls goes up (to set value)

}

else if (joy2Btn(8)==1) //If Joy2-Button 8 is pressed

{

servoTarget[StopServo]= 180; //The flap stopping the balls swings back down (to set value)

}

if (joy2Btn(5)==1) //If Joy2Btn-5 is pressed

{

motor[sweeper] = 95;

}

else if (joy2Btn(7)==1)

{

motor[sweeper]= -95;

}
else
{
motor[sweeper]=0;


}
}
}
}



thanks

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


Wed Nov 30, 2011 9:31 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: Magnet Sensor conflicting with Robot Function
From your pragmas, it looks like you have servo and motor hubs set up in ports S1, S2, and S3. Then you also have ports S2 and S3 set up with magnet and sonar sensors. This may be causing a problem.

_________________
sudo rm -rf /


Wed Nov 30, 2011 9:44 pm
Profile
Rookie
User avatar

Joined: Thu Dec 30, 2010 10:41 am
Posts: 6
Post Re: Magnet Sensor conflicting with Robot Function
We removed

#pragma config(Sensor, S2, Magnet, sensorNone)
#pragma config(Sensor, S3, Sonar, sensorNone)

and still nothing happened. Also, since the pragmas had "sensorNone" at the end, they didn't have anything to do with the conflicts anyway.


When we run the program without the magnet sensor portion:
Quote:
{


if(SensorValue[Magnet] <640 )

servo[MagnetServo] = 127;
wait10Msec(250);


if (SensorValue[Magnet] >660 )


servo[MagnetServo] = 127;
wait10Msec(250);

if(SensorValue[Magnet] >=451)
{
servo[MagnetServo] = 255;
}



Our program runs beautifully, but when this section is added, the robot goes haywire and nothing seems to respond. 2 servos go to what seems pre-determined positions and stay there when the portion is added and nothing functions.

I then tried to put the magnet portion into a while loop and still no luck:

Quote:
{
while (true)
{

if(SensorValue[Magnet] <640 )

servo[MagnetServo] = 127;
wait10Msec(250);


if (SensorValue[Magnet] >660 )


servo[MagnetServo] = 127;
wait10Msec(250);

if(SensorValue[Magnet] >=451)
{
servo[MagnetServo] = 255;
}
}



Is this happening to anyone else? would putting the codes into subgroups work? and if so, how because we have no idea how to use subgroups.

Thanks.

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


Thu Dec 01, 2011 12:23 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: Magnet Sensor conflicting with Robot Function
What other functions does that code mess with? Because I don't know how your robot is set up, I don't know if the "MagnetServo" servo moving erratically will affect other functions of your robot. If that would account for what you're seeing, that might be your problem. From what I can see from your code, the "MagnetSero" servo has conflicting instructions being sent to it sometimes.

_________________
sudo rm -rf /


Thu Dec 01, 2011 12:41 pm
Profile
Rookie

Joined: Wed Jul 21, 2010 11:23 pm
Posts: 39
Post Re: Magnet Sensor conflicting with Robot Function
husammoseswadi wrote:
When we run the program without the magnet sensor portion:
Quote:
{

if(SensorValue[Magnet] <640 )

servo[MagnetServo] = 127;
wait10Msec(250);


if (SensorValue[Magnet] >660 )


servo[MagnetServo] = 127;
wait10Msec(250);

if(SensorValue[Magnet] >=451)
{
servo[MagnetServo] = 255;
}
Our program runs beautifully, but when this section is added, the robot goes haywire and nothing seems to respond. 2 servos go to what seems pre-determined positions and stay there when the portion is added and nothing functions.
Thanks.


As soon as you add this code to the main while loop you are adding a 5 second wait regardless what the magnetsensor value returns. If you mean for the two wait10ms(250) to be part of the if statements you need to add the braces like this

Code:
if (SensorValue[Magnet] >660 )
{servo[MagnetServo] = 127;
wait10Msec(250);
}

But even with this change your loop will stall for 2.5 seconds if the magnet sensor isn't between 640 and 660, which will still cause a response problem.

It seems to me that you want to be doing the magnet servo stuff in a completely separate task, since it doesn't seem to relate to the joystick input anyhow. Do that by adding code as follows
above task main...
Code:
task magnetball()
{while(true)
{
// insert the above quoted magnetball code here

}

}


Then, in task main, add a line that says StartTask(magnetball);


Fri Dec 02, 2011 2:01 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 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.