rv stop

148 views
Skip to first unread message

Mark Clarhäll

unread,
Jan 17, 2024, 3:03:19 AMJan 17
to ti-inn...@googlegroups.com
Hi all,
i need some help with my coding:

How to command the Rover to:
Drive a certain path, while at the same time use the ranger to detect an obstacle, and when an obstacle is detected, stop, wait and then continue the path, when the obstacle is removed?

I need the full code. If you do so, please explain how each part of the program works.

Best regards,
Mark Clarhall
Sweden

kh7...@gmail.com

unread,
Jan 17, 2024, 3:31:31 PMJan 17
to TI-Innovator for Education
Hello Mark,
Are you looking for code for the TI-Nspire or TI-84 Plus CE? Either way, you will find an excellent activity that does just about exactly what you are looking for on TI's 10 Minutes of Code website. 
Select "Python with TI-Innovator Technology," Unit 5: Rover's Sensors and select Skill Builder 2, Off the Wall.

Here is a version with a slight modification: Instead of turning around, in this example the Rover will stop until the obstacle is removed and then continue on.
# Rover Coding
#================================
import ti_rover as rv                                   (all these modules are imported when selecting Rover Coding at start of new Python program)
from math import *
from ti_system import *
from time import *
#================================
while get_key() !="esc”:                                (pressing the esc key when the Rover is stopped will end the program)
  rv.forward(100)                                           (100 units = 10 m)
  dist=rv.ranger_measurement()
  while dist>.1:                                              (stops 10cm in front of obstacle, dist. is measured in m)
    dist=rv.ranger_measurement()
  rv.stop()
  rv.wait_until_done()

Not only do the 10-min of Code activities have great step by step instructions, teacher and student docs are available for downloads
Hope this helps to get you started.
Karlheinz

HMH

unread,
Jan 17, 2024, 3:35:17 PMJan 17
to TI-Innovator for Education
Hi Mark,
here's a piece of Python code which controls TI Rover movement relative to a moving object (another Rover, a block moved by hand, etc.). This actually is more functionality than you asked for, but it nicely demonstrates how you can handle repetitive ranger measurements in a loop and corresponding action of the Rover, depending on the distance measured. There's also a little video here which demonstrates this in practice: https://youtu.be/jbUXB23PIto
 
Feel free to holler with questions,

Greetings from Germany,
Hans-Martin
rv_adaptive_cruise_control.tns

Mark Clarhäll

unread,
Jan 18, 2024, 2:28:45 AMJan 18
to ti-inn...@googlegroups.com
Thank you all,
the thing is that I am using the Ti-nspire cx cas, which do not have the Python-function.
Is there a way to code using TI-Basic?



//Mark

--
You received this message because you are subscribed to the Google Groups "TI-Innovator for Education" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ti-innovator...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ti-innovator/9659ab46-d19a-483a-a58d-76bd9bc778fan%40googlegroups.com.

hm.h...@gmail.com

unread,
Jan 18, 2024, 3:18:46 AMJan 18
to ti-inn...@googlegroups.com

Hi Mark,

Sure – here you go, see attached. It has the same structure as the Python version, but less comments 😊. Let me know if you have specific questions to some portions of the code.

Best,

Hans-Martin

--
You received this message because you are subscribed to a topic in the Google Groups "TI-Innovator for Education" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ti-innovator/qetxKxVY14g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ti-innovator...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ti-innovator/CAFHrkzPguaVYT9-g3MVxiKSS04MLRaADj%3D5YL6hzC7xwRUbGcQ%40mail.gmail.com.

rv_follow.tns

Mark Clarhäll

unread,
Jan 18, 2024, 5:34:00 AMJan 18
to ti-inn...@googlegroups.com
Hans-Martin,
thank you so much. What a cool program!

However, I made a task for my students to code a specific path, using the RV CONTROL command e.g. Send "SET RV.MOTORS -255 210 time 2" (in various ways)

How to add a command for the rover (ranger) to detect an obstacle, stop, and when the obstacle is removed, just move on (RESUME) 

Should i insert a While-loop before the drive commands?

//Mark

HMH

unread,
Jan 18, 2024, 2:55:36 PMJan 18
to TI-Innovator for Education
Mark,

your code should contain the following steps:
1. Start the Rover using one of the rv drive or the rv control commands (like RV.MOTORS in your example above). If you like to define a specific time the Rover should move this is perfectly fine. Alternatively, you could specify a specific distance. In both cases, it's important the time or distance of movement will be long enough to reach/hit the obstacle. Otherwise, Rover would stop before, regardless if it has reached (or detected) the obstacle. The Rover drive and control commands are queued in a buffer of the Rover firmware and your Basic code proceeds to the next line of code immediately, even if Rover has just started  moving. Therefore it's important you avoid these rv drive or control commands within <while> or <For next> loops, unless you exactly know what you are doing.
2. Immediately after your Rover drive or control command you start your first while loop. In this while loop you measure the distance using the Ranger. The while loop continues until the measurement result of the Ranger has indicated Rover has reached the obstacle.
3. Next to the end of the while loop you place your rv.stop() command.
4. Now the Rover should have stopped in front of the obstacle. So you start a second while loop, doing Ranger measurements again until these measurements indicate the obstacle has been removed.
5. Right after the end of that second while loop you issue another RV.MOTORS command to let Rover proceed with its movement.

You let it finish its RV.MOTORS path from (5) above and end your code.
 
I hope this describes well how your code should look like. 
 
Best,
Hans-Martin

HMH

unread,
Jan 23, 2024, 11:58:05 AMJan 23
to TI-Innovator for Education
Mark,
 
here's a very simple code example to get you started. Please make sure you allow enough time for Rover to move to reach the obstacle. Otherwise it just stops, as the RV.MOTORS command times out and the program will remain in the first While loop forever, as the obstacle still is too far away.
 
Please check it out. Does it do what you wanted?
 
Best,
Hans-Martin
rv_obstacle.tns

Mark Clarhäll

unread,
Jan 24, 2024, 3:05:35 AMJan 24
to ti-inn...@googlegroups.com
Dear Hans-Martin,
Thank you again. 
I had a small group of students trying your code.
The actual code will be found in the TNS-file.

Until now they all manage to make the rover travel on a kids rug (pic), using several (+10) Send "RV CONTROL -x y time z"-commands.

Using your code does make the rover stop, while detecting an obstacle, but: I cant get the rover to continue its journey after the obstacle has been removed.

I would rather not write additional drive commands, as that would make the rover end up in another place than initially intended.

So, in detail: How to make the Rover execute the full journey, and while detecting an obstacle: stop until obstacle is no longer detected (removed) and then continue moving (no matter where the obstacle was placed/detected)

//Best regards

Mark

image.png

rv_obstacle_mark.tns

hm.h...@gmail.com

unread,
Jan 24, 2024, 4:43:01 AMJan 24
to ti-inn...@googlegroups.com

Dear Mark,

Thanks for sharing the details about your project. I like the idea of maneuvering the Rover along a curved pathway using the RV.MOTORS command.

 

Looking at your <detectdrive> code, it looks all good: You execute the entire set of pathway commands up front, before the obstacle detection and removal While loops begin. This code should detect an obstacle along the pathway and make Rover stop.

Now, if you add a <Send "RV RESUME"> command right at  the end of your code (after line 18) this should make Rover continue with the drive commands that remained in the Rover’s buffer queue after the obstacle was detected. Unfortunately, this has its drawback:

Depending on where you placed the obstacle, the current pathway command is abandoned by the RV STOP command and after removal of the obstacle Rover will continue with the next command in queue, no matter how far the previous drive command has completed before the obstacle was detected. In other words, Rover may make its next turn sooner than you like, as the previous command may just have started when the obstacle was detected.

I cannot think of a good workaround for this rather Rover system implementation related constraint. But, let’s open this up to the experts in this group: Do you have any ideas for a workaround?

Best,

Hans-Martin

 

 

From: ti-inn...@googlegroups.com <ti-inn...@googlegroups.com> On Behalf Of Mark Clarhäll
Sent: Wednesday, January 24, 2024 9:05 AM
To: ti-inn...@googlegroups.com
Subject: Re: rv stop

 

Dear Hans-Martin,

Thank you again. 
I had a small group of students trying your code.

The actual code will be found in the TNS-file.

 

Until now they all manage to make the rover travel on a kids rug (pic), using several (+10) Send "RV CONTROL -x y time z"-commands.

 

Using your code does make the rover stop, while detecting an obstacle, but: I cant get the rover to continue its journey after the obstacle has been removed.

 

I would rather not write additional drive commands, as that would make the rover end up in another place than initially intended.

 

So, in detail: How to make the Rover execute the full journey, and while detecting an obstacle: stop until obstacle is no longer detected (removed) and then continue moving (no matter where the obstacle was placed/detected)

 

//Best regards

 

Mark

 

image001.png

Mark Clarhäll

unread,
Jan 25, 2024, 2:18:57 AMJan 25
to ti-inn...@googlegroups.com
Hans-Martin,
still the Rover doesn't move as I wish:
I did try the program: the Rover moves and stops when an obstacle is detected. 
But it continues moving right after that, no matter if the obstacle (my foot) is removed or not.
Adding a Wait command right after the first WHILE loop, makes it wait (of course) before moving on. That command seems unnecessary.
Am I missing any commands?

//Mark

rv_obstacle_mark.tns

hm.h...@gmail.com

unread,
Jan 25, 2024, 6:17:22 AMJan 25
to ti-inn...@googlegroups.com

Mark,

Interesting!

No, you are not missing any commands. The issue is in the criteria you put in your two While loops. In your first While loop you make Rover stop as soon as it sees an obstacle less than 25cm away. So, after Rover has stopped, this obstacle will be, say, 22-23cm away from Rover.

In your second While loop, your criteria is to make Rover stand still as long as there is an obstacle less than 10cm away. Well, your obstacle is 22-23cm away, so the criteria for the second While loop is not met and the code immediately goes to the RESUME command.

To be safe and add some margin, make your second While loop criteria a little larger than your first one, e.g. keep your 25cm criteria as is, but increase your second While loop criteria to 30cm. This way, you account for any Ranger inaccuracies and make Rover stay in place safely, until the obstacle is removed.

You may try to move the obstacle slowly away from Rover to illustrate the effect of this margin to your students.

Let me know if this solved the issue.

image001.png

John Hanna

unread,
Jan 25, 2024, 6:47:48 AMJan 25
to ti-inn...@googlegroups.com

Been following quietly.

I wonder if rv.motors() is not a member of the drive queue.

 

 

Regards,

     John

image001.png

Deeley Judith

unread,
Jan 25, 2024, 6:47:56 AMJan 25
to ti-inn...@googlegroups.com
Hello all, 
my students are working on this as well.  Following your paths and updates. 

Judith A. Deeley, EdD

Engineering|Robotics|STEAM
Academic Team Advisor



Sent: Thursday, January 25, 2024 6:17 AM

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the email address and know the content is safe.

John Hanna

unread,
Jan 25, 2024, 7:50:42 AMJan 25
to ti-inn...@googlegroups.com

Yeah… rv.motors is not on the Drive menu so I assume it’s not a ‘drive queue’ function. I could be wrong.

 

The drive queue is important to this type of activity because the Innovator processes the drive queue while you are doing something else, like detecting an obstacle.

 

When you issue a series of Drive commands they are placed in the drive queue to be processed one-by-one. As the queue is being processed other things can happen in your program.

 

Other queue functions:

    rv.clear() (use after rv.stop() to clear the queue)

    rv.wait_until_done() (wait until the drive queue is empty). I use this to make the LED change colors at the corners of a square: green on the sides and red at the corners.

 

Regards,

     John

image002.jpg
image003.png

Mark Clarhäll

unread,
Jan 25, 2024, 7:57:03 AMJan 25
to ti-inn...@googlegroups.com
We are getting closer!
Changing distance to "While dist≤0.3" solved one problem.

Now the Rover drives, stops and continues after the obstacle is removed. Perfect!

But that action only happens once. Is there a way to make the Rover repeat that action while travelling.?

Mark

rv_obstacle_mark.tns

Hans-M. Hilbig

unread,
Jan 25, 2024, 8:11:59 AMJan 25
to ti-inn...@googlegroups.com
Mark,
 
Aha, you‘re gonna make your project more ambitious?
Well, welcome to the world of nested loops. But, here’s the disclaimer: please bear in mind each time the Rover detects an obstacle, its current drive command is abandoned and, after the obstacle is removed, it proceeds with the next drive command in queue. So, multiple obstacles will make your Rover leave its path and move all over your rug. It’s a two wheel drive, so I want to make sure you know what you are doing 😅😅, when Rover ends up in the weeds. 
 
If you still like to see this code, I‘ll send you one once I‘m back at my PC this evening. 
 
Best,
Hans-Martin

Hans-M. Hilbig

unread,
Jan 25, 2024, 8:14:53 AMJan 25
to ti-inn...@googlegroups.com
John,
 
Initially I had the same thought, but RV.MOTORS is queued, just like RV.FORWARD and all the other drive commands. 
 
Best,
HM

Mark Clarhäll

unread,
Jan 25, 2024, 9:16:20 AMJan 25
to ti-inn...@googlegroups.com
Well, that made me think twice. I'll settle with one single stop.
Again, thank you so much for your guidance.
Maybe this could end up in another TI-Codes activity?

There is another issue though, happening every now and then:
When my students code, and their program  contains several (+10) Send "RV. MOTORS X Y TIME Z" the Rover executes the entire program.
BUT this only happens the first time (after pressing ctrl B and ctrl R followed by enter.
Second time the Rover just won't run. 
The problem could be solved by restarting both the handheld and the Rover.
But that takes a lot of time, doing so each time, and for a teenager, pretty annoying.

Is that the buffer memory being clogged up by too many commands?
Am I the only one experiencing this?

//Mark

Deeley Judith

unread,
Jan 25, 2024, 10:03:31 AMJan 25
to ti-inn...@googlegroups.com
Is there a place where we can upload short video clip for trouble shooting?

From: ti-inn...@googlegroups.com <ti-inn...@googlegroups.com> on behalf of Mark Clarhäll <mark.c...@gmail.com>
Sent: Thursday, January 25, 2024 9:15:59 AM
To: ti-inn...@googlegroups.com <ti-inn...@googlegroups.com>
Subject: Re: rv stop
 

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the email address and know the content is safe.

hm.h...@gmail.com

unread,
Jan 25, 2024, 11:48:33 AMJan 25
to ti-inn...@googlegroups.com

Mark,

Always happy to help! Again, I like your project as it involves ‘curved’ waypaths which challenges the students to experiment with several values until they see the path fit the curve on the rug. Maybe you could do some math, as the ratio of the left motor vs. the right motor speed determines the radius of the arc the Rover is moving. Or ask the students: what is the smallest radius a Rover can turn (vs. a car)?

 

Regarding your buffer clogg up issue, you are not alone. I experienced something similar a good while ago. Four ideas come to mind for you to check out:

  1. Check your Rover’s TI Hub firmware is up to date. You can do this by running this little code:
    Send "VERSION"
    GetStr str0
    Disp str0
    It should read: 1.5.0.49. or better
  2. Add a Send "DISCONNECT RV" command to the end of your code that shows the issue. This ‘logically’ disconnects Hub and Rover from the CX HH.
  3. Alternatively, issue a Send "RV STOP CLEAR" at the end of your code, preceeded by a Wait xx, long enough to make sure your Rover queue had come to an end. This should clear the buffer.
  4. Avoid ‘overstressing’ the buffer, by partitioning it into smaller chunks. Like: Send your first 10 lines of drive commands to the Rover and send your next batch at a later time, once the first batch has completed. Not sure your project would allow that setup.

 

Start with idea #1 above and let me know if you none of the first three has fixed your issue. Then I’ll help you with #4, as this is a little tricky.

 

Hope it helps,

image001.png

hm.h...@gmail.com

unread,
Jan 25, 2024, 11:58:16 AMJan 25
to ti-inn...@googlegroups.com

Hi Judith,

 

Not that I’m aware of. I’m using my YouTube channel and send the link. If I don’t want to make the clip available to the public beyond the TI-Innovator Google group, I upload it as ‘non-public’, share the link and delete the clip once it’s no longer needed.

image001.png

John Hanna

unread,
Feb 2, 2024, 8:27:19 AMFeb 2
to ti-inn...@googlegroups.com

Python CX II:

The Rover menu Commands contains sleep, but I have to import the time module. I think if the command is on the Rover menu then the rover module should import sleep for me. Ditto with all other Commands.

 

Also learned that rv.stop does stop motors commands.

 

Regards,

     John

 


Sent: Thursday, January 25, 2024 11:48 AM
To: ti-inn...@googlegroups.com

Subject: RE: rv stop

image001.png
Reply all
Reply to author
Forward
0 new messages