About to board, so I don’t have time to write up a post, so here’s a reblog of Xander’s post at I’d Rather Be Building Robots:
via I’d Rather Be Building Robots
UPDATE: Download this program w/ setup, usage instructions and a demo here; get the driver (optional) here.
Programming my current project, Bionic NXTPod 3.0, I broke the actuators a few times by having the slide run into either the top or bottom. This was caused by my motor control: every time it went up or down, the encoders were reset, not considering whether or not the motor was exactly on target. As the errors built up, the actuators were torn down.
Looking for a solution, I saw HiTechnic‘s motor PID block – for NXT-G – which lets the motor move to an absolute encoder position, without resetting in between. Using this method, the error – usually not more than 2-3 degrees – is eliminated every time the motor moves to a new position, because the block compares the desired position to the actual position, not the assumed “0 point”. For example:
void PositionMotor(char motorToTurn, int absoluteDegrees){
if(nMotorEncoder[motorToTurn] == absoluteDegrees){}
else if(nMotorEncoder[motorToTurn] < absoluteDegrees){
bMotorReflected[motorToTurn] = false;
nMotorEncoderTarget[motorToTurn] = absoluteDegrees-nMotorEncoder[motorToTurn];
motor[motorToTurn] = 75;
while(nMotorRunState[motorToTurn] != runStateIdle){}
motor[motorToTurn] = 0;
}
else{
bMotorReflected[motorToTurn] = false;
nMotorEncoderTarget[motorToTurn] = nMotorEncoder[motorToTurn]-absoluteDegrees;
bMotorReflected[motorToTurn] = true;
motor[motorToTurn] = 75;
while(nMotorRunState[motorToTurn] != runStateIdle){}
motor[motorToTurn] = 0;
}
}
I couldn’t find all of these addresses anywhere, so I tested them to see what pins (B0 – B5) they’d turn on. A white box means that that address is turned on, and a black box means it’s off. Thanks to Xander and bullestock for helping me complete this list:
Since I received my HiTechnic magnetic field sensor, I’ve always wanted to put it to the test. In this post, I’ll discuss the sensor’s response time and it’s precision, to see if it can be used as angle sensor. These tests were inspired by a comment on mightor’s blog by Sparra Mc.
First, let’s look at the time it takes for the sensor to update its reading. The main part of the testing program is a 10-seconds loop with about four commands and no waiting, so the program runs through it thousands of times. The magnetic field sensor value is taken at the beginning of the loop, and then compared to the previous value. If the values are the same, nothing happens and the loop restarts. If they’re different, though, a variable holding the total amount of readings is increased by one. After the loop ends, this variable is divided by ten to get the readings per second. The experiment was repeated 25 times. These are the results:
These values average to about 325 readings per second, which is even more than HiTechnic specify of their website! So, the HiTechnic magnetic field sensor updates about every 3 mSecs.
Even though a low update time is important, precision matters, too. My second and last experiment focused on that. The program it runs on makes the motor (with magnet attached to it – the magnet was positioned to give the maximum possible value at the experiment’s start) run slowly, while taking a magnetic field reading every ten encoder ticks. That resulted in a total of 36 readings. The below graph shows those readings vs. the position (in degrees) the motor was in.
These values look precise enough, and, if the magnet was horizontal in the beginning (to give a 0 value), one could use it as a rotation sensor. The only problem being that the value gets negative, which might be confusing to program.
Overall, I think the HiTechnic magnetic field sensor is great and performs awesomely. With its precision it could be used for almost anything, including for (some suggestions from around the web):
So, to anyone reading this, I would STRONGLY recommend buying the HiTechnic magnetic field sensor! More info:
This program graphs magnetic field sensor values, keeping track of the maximum read value. The graph remembers 100 past values, which move to the left whenever there’s a new value (each 20 milliseconds), after which they’re forgotten. So, the graph shows values of up to two seconds ago. Furthermore, the scale of the graph is adjustable (by turning motor A), so it can adapt to different kinds of magnets. Here’s some screenshots (taken in RobotC NXT remote screen):
The graphing program can easily be adjusted to work with different sensors including light, sound, touch and ultrasound.
More info:
A few days ago, the HiTechnic Magnetic field sensor arrived at my doorstep. Ever since, I was thinking about what to use it for, and this is the result: an automatic binary encoder, sender, receiver and decoder used to synchronize two NXT motors. The video below shows the procedure:
So, the robot starts by setting the bias for the magnetic sensor before it’s near the magnet. Once the user adjusts the red stick to an acceptable angle (between 0 and 255 degrees – program is paused if angle is wrong) for the motors to sync to, that angle is translated into an eight-bit binary code. Then, the third motor compares its own position to the way it’s supposed to be – if a bit (boolean variable) is true, the black stud has to be up (0 degrees), and when the bit is false, the red stud has to be up (180 degrees). If necessary, the motor adjusts the position. At the same time, the magnetic field sensor “reads” the magnet, getting either a positive or negative number. If the received number is positive, it makes a bit true; if it’s negative, it makes that same bit false. Once it has all eight bits, it translates it back into a target for the other motor to go to, thus synchronizing the motors. At the very end, the third motor checks its position and makes sure it ends up having the black pin (north of the magnet) up.
More information:
Thanks to:
I just finished my 2nd experiment with the HiTechnic IR Link, which is used to control PF motors through IR signals. The setup is pretty simple:
The four power functions are controlled using the remote control (obviously). It starts of by telling the user to set the NXT servo to the default angle using a simple illustration. When it’s in the right position, the user simply clicks the button and starts controlling the PF motors. The remote switches between motor 1-4 when the NXT servo is turned ninety degrees in either direction, displaying the active motor’s number on the screen. Then, when the button is pressed, that motor will run until the sensor is released, looping forever. I want to thank mightor , Gary Samad and ivanseidel for helping me out with the programming for this!
Wanna know more about the remote control? Check out the following post(s):