|
Page 1 of 1
|
[ 6 posts ] |
|
hi technic magnetic sensor help
| Author |
Message |
|
teddy268
Rookie
Joined: Wed Nov 30, 2011 11:18 am Posts: 6
|
 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 |
|
 |
|
mightor
Moderator
Joined: Wed Mar 05, 2008 8:14 am Posts: 2858 Location: Rotterdam, The Netherlands
|
 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); } } } |  |  |  |  |
_________________| Some people, when confronted with a problem, think, "I know, I'll use threads," | and then two they hav erpoblesms. (@nedbat)| My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
| Thu Mar 22, 2012 4:34 am |
|
 |
|
teddy268
Rookie
Joined: Wed Nov 30, 2011 11:18 am Posts: 6
|
 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 |
|
 |
|
mightor
Moderator
Joined: Wed Mar 05, 2008 8:14 am Posts: 2858 Location: Rotterdam, The Netherlands
|
 Re: hi technic magnetic sensor help
That is not an error code, it's a warning and it's harmless  - Xander
_________________| Some people, when confronted with a problem, think, "I know, I'll use threads," | and then two they hav erpoblesms. (@nedbat)| My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
| Thu Mar 22, 2012 12:45 pm |
|
 |
|
teddy268
Rookie
Joined: Wed Nov 30, 2011 11:18 am Posts: 6
|
 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......
|
| Fri Mar 23, 2012 8:00 am |
|
 |
|
mightor
Moderator
Joined: Wed Mar 05, 2008 8:14 am Posts: 2858 Location: Rotterdam, The Netherlands
|
 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
_________________| Some people, when confronted with a problem, think, "I know, I'll use threads," | and then two they hav erpoblesms. (@nedbat)| My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
| Fri Mar 23, 2012 3:30 pm |
|
|
|
Page 1 of 1
|
[ 6 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
|
|