NXC: detecting robot turns
-
- Posts: 35
- Joined: 15 Oct 2010, 01:29
- Location: Wellington, New Zealand
NXC: detecting robot turns
Using NXC, driving a robot with two motors (let’s say B & C) I’m trying to determine the best way to detect when the robot turns.
My thoughts so far are to do a continuous comparison of the tachocount of B & C (with some tolerance I guess because I assume the two will never be exactly identical) , detecting the turn when the delta reaches a certain threshold.
I realise though that there is also a whole raft of other motor functions out there that I don’t fully understand the meaning of (especially those to do with synch) so if there is a more effective way to do this I would be keen to hear about it.
My thoughts so far are to do a continuous comparison of the tachocount of B & C (with some tolerance I guess because I assume the two will never be exactly identical) , detecting the turn when the delta reaches a certain threshold.
I realise though that there is also a whole raft of other motor functions out there that I don’t fully understand the meaning of (especially those to do with synch) so if there is a more effective way to do this I would be keen to hear about it.
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: NXC: detecting robot turns
Is the idea that you want it to detect a turn to correct itself?
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
-
- Posts: 35
- Joined: 15 Oct 2010, 01:29
- Location: Wellington, New Zealand
Re: NXC: detecting robot turns
No. I want to keep a record of the rotation count, logging it each time that the robot makes a turn.mattallen37 wrote:Is the idea that you want it to detect a turn to correct itself?
Re: NXC: detecting robot turns
For this issue I am starting a seperate task which does just the same what you already proposed:
calculate the delta count of both encoders.
calculate the delta count of both encoders.
Code: Select all
task EncMonitor() {
while(1) {
long delta=(MotorRotationCount(OUT_B)-(MotorRotationCount(OUT_C)
int threshold=1;
if (delta>threshold) //... turn clockwise
else
if (delta<threshold) //... turn anti clockwise
Wait(3);
}
}
-
- Posts: 35
- Joined: 15 Oct 2010, 01:29
- Location: Wellington, New Zealand
Re: NXC: detecting robot turns
Thanks. That looks promising, will try it out at home tonight.doc-helmut wrote:For this issue I am starting a seperate task which does just the same what you already proposed:
calculate the delta count of both encoders.
...
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: NXC: detecting robot turns
You'd need to keep resetting the encoders, or else use an offset for that to work (and fix the syntax).
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: NXC: detecting robot turns
yes, matt is right.
I wrote this from memory, I actually was comparing cached values
(encCounter - last_delta)
so I didn't need to reset the counters itself.
I wrote this from memory, I actually was comparing cached values
(encCounter - last_delta)
so I didn't need to reset the counters itself.
-
- Posts: 35
- Joined: 15 Oct 2010, 01:29
- Location: Wellington, New Zealand
Re: NXC: detecting robot turns
Both posts above understood (and they are common sense anyway )
-
- Posts: 35
- Joined: 15 Oct 2010, 01:29
- Location: Wellington, New Zealand
Re: NXC: detecting robot turns
partial success, had to tweak the code slightly as per below otherwise it would trigger when the motors are running at the same speed (i.e. delta == 0)
testing this using the joystick tool in BrixCC and the motors spinning freely they obivously don't quite turn at the same speed and the threshold is exceeded after a few seconds. Might be different if they are robot-wheels and under (the same) load.
It does proof the concept though, and I can go certainly go forth from here with my little project.
Code: Select all
while(1) {
long delta=MotorRotationCount(OUT_B)-MotorRotationCount(OUT_C);
int threshold=20;
if (delta && delta>threshold)
{
...
}
else
if (delta && delta<(threshold*-1))
{
...
}
Wait(3);
}
It does proof the concept though, and I can go certainly go forth from here with my little project.
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: NXC: detecting robot turns
Like I said before, you either need an offset, or you need to reset the encoders.
Something like this should work:
Something like this should work:
Code: Select all
int threshold = 1;
long offset;
long delta;
while(1) {
delta = MotorRotationCount(OUT_B) - MotorRotationCount(OUT_C) - offset;
if (delta > threshold){
}
else if (delta < (threshold * -1)){
}
offset = delta;
Wait(3);
}
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Who is online
Users browsing this forum: Semrush [Bot] and 0 guests