View unanswered posts | View active topics It is currently Sat Nov 22, 2014 8:50 pm






Reply to topic  [ 6 posts ] 
hi technic magnetic sensor help 
Author Message
Rookie
User avatar

Joined: Wed Nov 30, 2011 11:18 am
Posts: 6
Post hi technic magnetic sensor help
ok so we have to biuld this magnetic bomb detecting and dismantling robot. we are using the hi-tecnic magnetic sensor to find the bombs. however the coding the senosr is a bit of a problem if you have no idea how to.......
so i have verified the the sensor works and from the HT-mag test code and for raiding the internet i have come up with this basic code to;
1.play a tone when over a set point of input
2.play a tone ever 1 second under a set point of input
#pragma config(Sensor, S1, up, sensorTouch)
#pragma config(Sensor, S4, HTMAG, sensorNone)
#pragma config(Motor, motorA, motorA, tmotorNormal, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//





#include "drivers/HTMAG-driver.h"

task main ()
{
int bais;
bais=SensorValue[HTMAG];
while(1==1);

{
if(abs(SensorValue[HTMAG]-bais)>5)

{

PlayTone( 880, 7); wait1Msec( 75);

}

else

{

PlayTone( 880, 7);

}

}

}
the robot has been biult a while ago and this is the only thing that is messing us up. please help our class soon. :)


Wed Mar 21, 2012 7:48 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3289
Location: Rotterdam, The Netherlands
Post Re: hi technic magnetic sensor help
Try this code instead:

Code:
#pragma config(Sensor, S1,     up,             sensorTouch)
#pragma config(Sensor, S4,     HTMAG,          sensorAnalogInactive)
#pragma config(Motor,  motorA,          motorA,        tmotorNormal, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "drivers/HTMAG-driver.h"

task main ()
{
  // Variable for storing the sensor value
  int magvalue = 0;

  // First calibrate the sensor.
  // This will automatically find the bias and
  // apply that value to HTMAGreadVal();
  int bias = HTMAGstartCal(HTMAG);

  while(true);
  {
    // Read the sensor's value and automatically
    // remove the bias.
    magvalue = HTMAGreadVal(HTMAG);

    if(abs(magvalue) > 5)
    {
      PlayTone( 880, 7);
      wait1Msec( 75);
    }
    else
    {
      PlayTone( 880, 7);
    }
  }
}

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Thu Mar 22, 2012 4:34 am
Profile WWW
Rookie
User avatar

Joined: Wed Nov 30, 2011 11:18 am
Posts: 6
Post Re: hi technic magnetic sensor help
mightor wrote:
Try this code instead:

Code:
#pragma config(Sensor, S1,     up,             sensorTouch)
#pragma config(Sensor, S4,     HTMAG,          sensorAnalogInactive)
#pragma config(Motor,  motorA,          motorA,        tmotorNormal, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "drivers/HTMAG-driver.h"

task main ()
{
  // Variable for storing the sensor value
  int magvalue = 0;

  // First calibrate the sensor.
  // This will automatically find the bias and
  // apply that value to HTMAGreadVal();
  int bias = HTMAGstartCal(HTMAG);

  while(true);
  {
    // Read the sensor's value and automatically
    // remove the bias.
    magvalue = HTMAGreadVal(HTMAG);

    if(abs(magvalue) > 5)
    {
      PlayTone( 880, 7);
      wait1Msec( 75);
    }
    else
    {
      PlayTone( 880, 7);
    }
  }
}

a error message says that bias is written but has no read refference


Thu Mar 22, 2012 7:30 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3289
Location: Rotterdam, The Netherlands
Post Re: hi technic magnetic sensor help
That is not an error code, it's a warning and it's harmless :)

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Thu Mar 22, 2012 12:45 pm
Profile WWW
Rookie
User avatar

Joined: Wed Nov 30, 2011 11:18 am
Posts: 6
Post Re: hi technic magnetic sensor help
then with that excluded the tones still do not play nor does a motor move when i put them in place of the tones.
i decided to just put the if statement into the HTMAG test file and see if it will work. well the motor will run in one direction (im geussing the "else" direction) but it will not change direction if a magnet is put in front of the sensor.

CODE......

Code:
#pragma config(Sensor, S4,     HTMAG,          sensorAnalogInactive)
#pragma config(Motor,  motorA,          motorA,        tmotorNormal, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "drivers/HTMAG-driver.h"

task main ()
{
  // Variable for storing the sensor value
  int magvalue = 0;

  // First calibrate the sensor.
  // This will automatically find the bias and
  // apply that value to HTMAGreadVal();
  int bias = HTMAGstartCal(HTMAG);

  while(true);
  {
    // Read the sensor's value and automatically
    // remove the bias.
    magvalue = HTMAGreadVal(HTMAG);

    if(abs(magvalue) > 5)
    {
      motor[motorA]=100;
      wait1Msec(1000);
    }
    else
    {
      motor[motorA]=-100;
      wait1Msec(100);
    }
  }
}


Fri Mar 23, 2012 8:00 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3289
Location: Rotterdam, The Netherlands
Post Re: hi technic magnetic sensor help
How about you modify your code a little to print the value of the sensor onto the screen so you can see how much it is.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Fri Mar 23, 2012 3:30 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 6 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.