Should this code work as designed?

Hello,
Assuming that I understood the “Set Speed” blockly instruction, the following instructions should move the XRP 10 cm in one second:

Set Speed Left 10 cm/s Right 10 cm/s
Sleep 1

I tried the code with a couple of XRP betas and one XRP V1.0 but the XRPs move more than 40+ cm and before stopping.

Am I doing something wrong or not understanding the instruction?
Thanks.

I haven’t tested your code. My first thought is to add the following block to your program:
Set Speed Left 0 cm/s Right 0 cm/s

There is no instruction to turn off the drive motors. Yes, you set the speed and yes you have it stop processing for 1 second. After that one second is complete, there is no new instruction for the drive motors. They continue using their last instruction (speed 10 cm/s).

By adding the new block, after the 1 second sleep, the motors are commanded to stop moving. I predict this will give you the 10 cm drive that you’re expecting.

Hello,
Thanks for your great suggestion. I figured that would solve the problem. Unfortunately, it didn’t help. Here are the instructions:

I tried the instructions on both XRP Beta and the new XRP V1 and they behave the same, the robot goes almost 35 cm and stops.
Thanks.

Hmm, that’s interesting. I tried to replicate on my end, but my robot doesn’t go nearly that far. In fact, it only goes about 5cm (likely because 10cm/s is pretty slow for the XRP, and it takes a moment for the PID controller to get the robot to actually start moving). I can’t think why your robot would go so much further.

Are you using a standard XRP kit? Or do you have different motors or wheels? If so, that could explain the difference. What happens if you use the Straight block? Does it drive the right distance?

image

Hello,
Two things. When I run the code. The first couple of times, robot goes forward about 5cm but if you run the code again, it goes for 30+cm. If I use Straight instruction, it works fine every time. Therefore, I don’t think there is anything wrong with the motors or wheels. I think Frank was able to reproduce the same problem.
Thanks.

Hmm, that’s peculiar behavior. Can’t say I know what the problem is or why it would be inconsistent. When it goes 30+cm, is it going too fast for 1 second, or the right speed for too long?

I just tried the same code again with another standard XRP (a new XRP V1). The result was the same. The first run, it goes very slow for about 5cm and stops. The second time, it goes very fast and stops after 40+ cm. This is reproducible every time. I just want to say again that I have tried the code with more than 3 XRPs. Every one of them provides the same result. Also, every one of them works correctly if I use “Straight” instruction.
Thanks.

Aha! Figured out why I couldn’t replicate before - I was pressing the reset button on the board, but I suspect you were pressing the Run button in XRPCode. Using the reset button, it consistently goes 5cm. However pressing the Run button, I get the same behavior (5cm on the first run, then much further on subsequent runs).

Below is better replication code. Ensure a hard reset is performed, then run this code. The first iteration will go a short distance (5cm), all subsequent iterations will go a longer distance because the motors spin much faster. If no hard reset occurs between runs, it continues to go too far.

I suspect the problem is with the motor speed PID controller. I will submit an issue.

Issue submitted! GitHub · Where software is built

Thanks for reporting this, hopefully a fix will be rolled out soon!

I am glad that your were able to see the problem that I have been seeing. Hopefully, a fix can be found.

Thanks for all your help.

1 Like

Hello,
I saw the link. I am not too clear if what is suggested is a workaround for fixing “Set Speed”. If so, is there an instruction for Blockly programming to do what is suggested " If I add self.speedController.clear_history() to the end of set_speed()?
Thanks.

Hi there,

Yes, if you go into /lib/XRPLib/encoded_motor.py, find set_speed() (should be lines 156-169), then add self.speedController.clear_history() to the end and save the file, that should make it drive more consistently in both Blockly and MicroPython.

Hello,
I just tried it and it looks like your recommendation fixed the problem. Thanks for all your help, I apreciate it.

1 Like