Documentation

← back to Oculus Prime Contents

Oculus Prime - Script Examples using the Telnet API

This page contains examples of customizing the functionality of Oculus Prime using Python scripts, interfacing with the robot using the telnet API, and importing the Oculus Prime python module.

On this page:
    Synth Voice on Detection
    Listen for Noise While Docked
    Wait to Reach Waypoint
    Loop Through Waypoints

Synth Voice on Detection

The following script, useful for running along with patrol routes, has the robot make an audible announcement whenever any of its sensing functions (sound, motion, human) detect anything.

It sets oculusprime.reconnect to True before connecting, which causes the script to keep trying to connect and re-connect to the server, even if the server is stopped and re-started. This way the script can be run by default on system boot.

The sensing functions write results to the streamactivity state variable, so the script uses the python module’s waitForReplySearch function to wait for any writes to that variable, then speaks up using the speech command:


Listen for Noise While Docked

The script below waits until the robot is docked by requesting the dockstatus state variable, then turns on the microphone and enables sound detection. If it hears a noise, it will launch a pre-defined patrol route named “recon” to go and check out the situation. This presumes that the “recon” route is scheduled to run anytime; ie., set to 7 days a week, with ‘stop after’ set to 24 hours.

When the route is complete and the robot re-docks, the route is cancelled – so the route will only run once, ignoring the scheduled minutes between runs.


Wait to Reach Waypoint

Below is a simple example of having a script wait for the robot to reach a waypoint. The ROS node remote_nav.py handles sending navigation commands and status back and forth between ROS and the Oculus Prime Server Application, and it helps to understand a bit how that works:

Waypoints aren’t sent to ROS by name, ROS only understands ‘where to go next.’ So instead, the server application assigns the waypoint coordinates (x meters, y meters, angle in radians) to the rossetgoal state variable. The ROS node continuously checks for that state variable for new goal coordinates to send the robot to. When it receives and accepts a new goal, it deletes the rossetgoal state variable and applies the coordinates to the roscurrentgoal state variable. When it reaches the goal, the node deletes roscurrentgoal.

The script below sets a goal using the gotowaypoint command, then waits until the telnet stream reports that the roscurrentgoal state value has been deleted. It then assumes that the waypoint has been reached, and exits.


Loop Through Waypoints

Expanding on the example above, this script assigns a set of waypoints to a python list, then iterates through the list, causing the robot to drive through each waypoint forever (or until the battery dies).


NEXT: Another Script Example, Auto-starting Scripts

← back to Oculus Prime Contents


CART 0 items | US$
    Check Order Status
Follow →
instagram twitter facebook youtube
© 2024 Xaxxon
Products Documentation Downloads Source Code
Warranty & Returns About Us Contact/Support News
instagram twitter facebook youtube