Is there any sample code for the XRP? Just simple snips of sampling the acoustic sensor and driving the motors and servo?
Sure - hop over to https://xrpcode.wpi.edu/ and connect your XRP via usb
(here’s the main XRP page too Get Started - Experiential Robotics)
That no work! haha no i tried to get the sample code online to just copy paste into the IDE but that isnt working? HELP ME
Try following along with the guide I linked above…it uses its own IDE (looks like a webpage)
When you connect to XRPCode, there is a folder called “XRPExamples” with a handful of examples to help you get started.
There’s also a lot of helpful information on the XRP User Guide site: Introduction — XRP 2023.0 documentation
kk I’ve added the sample code to the XRP IDE and the sensor is having such a hard time recognizing the black line to follow it and as well its having a hard time recognize the reflectance levels of black to white and the change in course…HELP!
Can you please be more specific and quantify the problems you’re having? It’s very difficult for us to diagnose and help with a problem without a clear test procedure and clear data, error messages, etc. What surfaces are you using the reflectance sensor on? What values are you getting on each surface? Have you double checked your wiring? Could you send a photo of your wiring so we can confirm the sensor is connected correctly?
Also, it might be worthwhile to post to https://xrp.discourse.group/. It’s a support forum specifically for the XRP, and there’s a lot more folks who may be able to help there.
from XRPLib.defaults import *
import time
THRESHOLD = 0.4
base_effort = 0.25
KP = 0.15
def line_track():
while True:
left_val = reflectance.get_left()
right_val = reflectance.get_right()
left_state = 1 if left_val > THRESHOLD else 0
right_state = 1 if right_val > THRESHOLD else 0
error = left_state - right_state
left_effort = min(max(base_effort - KP * error, 0), 1)
right_effort = min(max(base_effort + KP * error, 0), 1)
drivetrain.set_effort(left_effort, right_effort)
print(f"L: {left_val:.3f}({left_state}) R: {right_val:.3f}({right_state}) Err: {error} LE: {left_effort:.2f} RE: {right_effort:.2f}")
time.sleep(0.01)
thats the code i and my mentor came up with yesterday and we are able to get the XRP robot to move she just wont recognize the black line to follow it through the course. it is a simple course, black tape on the floor.
To diagnose a problem with your line sensor, it would be best to simplify your code to focus exclusively on the sensor to ensure nothing else in your code is causing any problems. For example:
from XRPLib.defaults import *
import time
while True:
print(reflectance.get_left(), reflectance.get_right())
time.sleep(0.1)
Try running this code, then move the sensor over different surfaces to see if the measured values change. You should get numbers between 0 and 1. For example, my XRP gives values around 0.4 on a white surface, and 0.9 on a black surface.
What values do you get?
kk i gathered all the data from the left and right reflectance values and now im doing code to recognize that hey this is a straight line and i should just go straight for now until i notice theres a turn i need to stop and turn with that turn