ROBOTC.net forums
http://robotc.net/forums/

Using HT Compass sensor to rotate
http://robotc.net/forums/viewtopic.php?f=41&t=10371
Page 1 of 1

Author:  billyb29 [ Tue Jan 27, 2015 7:52 pm ]
Post subject:  Using HT Compass sensor to rotate

How can I use the compass sensor to make the robot rotate 90 degrees. I am not familiar with the information inside of the tHTCM struct (offset, heading, relativeHeading) what does each one stand for, and how can I calibrate the sensor? Thanks in advance, and if there's a link to anything related I don't mind it.

Author:  mightor [ Wed Jan 28, 2015 2:03 pm ]
Post subject:  Re: Using HT Compass sensor to rotate

Did you look at the examples that are shipped with the driver suite?
hitechnic-compass-test1.c, for example, there's a few of them.

= Xander

Author:  billyb29 [ Sat Jan 31, 2015 12:14 am ]
Post subject:  Re: Using HT Compass sensor to rotate

Hey Xander,

I already tried that but I get these errors:
**Error**:Undefined procedure 'HTMCsetTarget'.
**Error**:Undefined procedure 'HTMCreadHeading'.
**Error**:Undefined procedure 'HTMCreadRelativeHeading'.

Author:  billyb29 [ Sat Jan 31, 2015 12:17 am ]
Post subject:  Re: Using HT Compass sensor to rotate

It is working now, I moved the header file to the same folder where the test1.c is and it worked. Thank you again

Author:  Yoda6969 [ Tue Nov 17, 2015 8:24 am ]
Post subject:  Re: Using HT Compass sensor to rotate

Below is code that should help you set-up the compass sensor and use it to turn a set amount. Good luck with your future programming endeavors :D .

Code:
#pragma config(Sensor, S1,     compassSensor,  sensorI2CHiTechnicCompass)

task main() {
// this will link Slot 1 a index named 'nCompass'.
tSensors nCompass = S1;

// this line will tell the program that nCompass is a HiTechnicCompass sensor.
// if you are using a different type of compass sensor than you will need to set it to that one.
SensorType[nCompass] = sensorI2CHiTechnicCompass;

//first create and integer that will store the compass sensor value before you begin to turn
int startingCompassValue;

//before you start the loop that will turn the robot run the below line to set startingCompassValue to the current compass vlaue
int startingCompassValue = SensorType[nCompass];

//this while loop will say that until the compass sensor is equal to the startingCompassValue+90, keep turning left
//you can change the number '90' to set how far you want to turn.
while(SensorType[nCompass] != startingCompanssValue+90)
{
//assuming your robots motors are set up with set-up this way (with motorA on the right side when robot is facing you)
motor[motorA] = 25;
motor[motorB] = -25
}

// if you want the robot to turn the other way this code is as follows (notice the value is now '-90' and the motors turn the other way
while(SensorType[nCompass] != startingCompanssValue-90)
{
//assuming your robots motors are set up with set-up this way (with motorA on the right side when robot is facing you)
motor[motorA] = -25;
motor[motorB] = 25
}
}



note that 'startingCompassValue will not update until it is told too so make sure to write it in before the while loop. It cannot be done within the while loop as the value will keep updating and the robot is turning.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/