Picoborg Reverse controlled by serial Term

Hi Im playing with communication LoRa modules and Arduino/ESP32 boards I can successfully send messages over a fair distance and read the message on an Arduino IDE serial monitor. I know how to send sensor readings from an arduino to a Raspberry pi over serial and store these. But would like to go further and control my Piborg robot via this method. The messages would be simple left right stop etc. and possibly compass directions.
Is controlling the pico borg in this manner feasable if so could you help?

piborg's picture

Sorry about the slow reply.

Yes, you should be able to do this using a PicoBorg Reverse :)

First you will need to setup the board at the top of your script (change the power settings to match your robot).

# Import library functions we need
import PicoBorgRev

# Setup the PicoBorg Reverse
PBR = PicoBorgRev.PicoBorgRev()
PBR.Init()
PBR.SetCommsFailsafe(False)
PBR.ResetEpo()

# Power settings
voltageIn = 1.2 * 12  # Total battery voltage
voltageOut = 12.0     # Maximum motor voltage

# Setup the power limits
if voltageOut > voltageIn:
    maxPower = 1.0
else:
    maxPower = voltageOut / float(voltageIn)

I would also suggest having a separate speed value that you can change so you can run the robot slower when testing. You can also use this later as a way to change the speed via serial as well.

# Motor speed between 0.0 (off) and 1.0 (full speed)
speed = 0.3           # 30%

Now all you need to do is get your serial commands and change the motor outputs to match. The exact commands will depend on how your motors are wired.

Here is an example assuming:

  • M1 is the left side motors
  • M2 is the right side motors
  • +ve values spin the motors forwards
  • command holds the command from the serial
# Make the command upper case and remove any white space
command = command.upper().strip()

# Get the power output for the currently set speed
power = maxPower * speed

# Action the command
if command == 'STOP':
    PBR.MotorsOff()
elif command == 'FORWARD':
    PBR.SetMotor1(power)
	PBR.SetMotor2(power)
elif command == 'REVERSE':
    PBR.SetMotor1(-power)
	PBR.SetMotor2(-power)
elif command == 'LEFT':
    PBR.SetMotor1(0)
	PBR.SetMotor2(power)
elif command == 'RIGHT':
	PBR.SetMotor1(power)
    PBR.SetMotor2(0)
elif command == 'SPIN-L':
    PBR.SetMotor1(-power)
	PBR.SetMotor2(power)
elif command == 'SPIN-R':
	PBR.SetMotor1(power)
    PBR.SetMotor2(-power)
elif command == 'SLOW':
    # Set speed to a low value for following commands
	speed = 0.3
elif command == 'FAST':
    # Set speed to a high value for following commands
	speed = 0.7
else:
    print('Unknown command: ' + command)

Hi, Thanks for the above code. I've not had a chance to try it yet as I've been tryig to get my LORA devices to communicate. I have come across Meshtastic which allows text messages to be sent over LORA devices.
The device is ESP32 based, using the serial ouputt I can receive text messages and print them to term on my Rasberry Pi. Unfortunately the Lora device prints diagnostic info along with the name of the Lora device that sent the message (see attached )
If the message is in caps will the PI only use the text message and ignore other info that is printed by serial eg Radio name and Diagnostics?
For example

Rav1: FORWARD
I have attached a sample of the serial output.

I'm also a bit confused as how I get my serial commands ? Is there something I need to add to my imports? Will The Pi automatically use serial input?

Thanks again

John

Attachments: 
piborg's picture

I don't have any experience with LoRa modules, but you will need to get the passed messages into Python instead of just being printed to the terminal before you can use them to control the board.

This module may be what you need: https://pypi.org/project/pyLoRa/

I would recommend trying to get their rx_cont.py example to work and see what it is printing for the payload (in on_rx_done), it probably won't include the diagnostic output you are currently seeing.

Subscribe to Comments for "Picoborg Reverse controlled by serial Term"