Asked — Edited

Serial Toolbox Plugin

@PTP

I have read over the tutorial on making plugins and it was very good and helpful. I am looking to do a plugin using the serial port on the ezb to communicate with an arduino type board to communicate back and forth with various sensors, lcd's, etc.

I was wonering if I could get your source code for the serial toolbox plugin to learn from regarding serial port communications with ezb, etc. I am also taking a course on c# but there is nothing like actual examples of code when it comes to communicating with hardware serial ports. Most all courses don't go into this type of coding. Thanks much....Rick. :):)


ARC Pro

Upgrade to ARC Pro

ARC Pro will give you immediate updates and new features needed to unleash your robot's potential!

PRO
Canada
#17  

Thx @DJ and @PTP If you have a look at my code I am trying to interface with Meccanoid bios but the commands are structured and responses come back and I don't really know the size of the packet (could be 4 or 5 bytes. I wrote my own error check and put a wait in after 4 bytes but I really need to redo the meccanoid bios to make this work effectively. I also need to create a unique ID on each packet and then queue them but .....

Goal was to build 1 JD from meccanoid servos and 1 from EZB servos and mirror the second one off the first one (Move left arm on first JD and Left arm on second JD moves) I have 2 read and 2 write servo's working now but it's messy.


# To use this you need meccontrol firmware
# The commands are well documented here
# https://meccontrol.com/help/firmware/communication-protocol

# Initialize UART to 9600bps
UARTInit(0, 0, 9600)

# Set servo Degrees
$ServoDegrees0=120
$ServoDegrees1=120


# MeccanoidInitialise Resets all Servos on Pin 2
$command="MeccanoidInitialise 2"
Goto(SendCommand)

# MeccanoidSetServoMotorPosition (MNSSMP is Shortform) pin 2, servo 0, 120 degrees 0ms
$command="MeccanoidSetServoMotorPosition 2 0 120 0"
Goto(SendCommand)

# MeccanoidSetServoMotorPosition pin 2, servo 1, 120 degrees, 0ms
$command="MeccanoidSetServoMotorPosition 2 1 120 0"
Goto(SendCommand)

# MeccanoidSetServoMotorPosition pin 2, servo 2, 120 degrees, 0ms
$command="MeccanoidSetServoMotorPosition 2 2 120 0"
Goto(SendCommand)

# MeccanoidSetServoMotorPosition pin 2, servo 3, degrees, 0ms
$command="MeccanoidSetServoMotorPosition 2 3 120 0"
Goto(SendCommand)

## Disbale Red Servos

# MeccanoidDisableServoMotor pin 2, servo 0
$command="MeccanoidDisableServoMotor 2 0"
Goto(SendCommand)

# MeccanoidDisableServoMotor pin 2, servo 1
$command="MeccanoidDisableServoMotor 2 1"
Goto(SendCommand)

## Set Disabled Servos Red

# MeccanoidSetServoLEDColour pin 2, servo 0, red
$command="MeccanoidSetServoLEDColour 2 0 1"
Goto(SendCommand)

# MeccanoidSetServoLEDColour pin 2, servo 1, red
$command="MeccanoidSetServoLEDColour 2 1 1"
Goto(SendCommand)

## Set Active Servos Green
# MeccanoidSetServoLEDColour pin 2, servo 2, green
$command="MeccanoidSetServoLEDColour 2 2 2"
Goto(SendCommand)

# MeccanoidSetServoLEDColour pin 2, servo 3, green
$command="MeccanoidSetServoLEDColour 2 3 2"
Goto(SendCommand)

# # Check to See if a servo Is Moved and stop > 230 degrees
repeatuntil($servoDegrees0 > 230)

  # make movecheck = servo degress to see if moved
  $moveCheck0=$servoDegrees0

  # MeccanoidGetServoMotorPosition pin 2, servo 0
  $command="MeccanoidGetServoMotorPosition 2 0"
  Goto(SendCommand)

  # convert $readData to degrees
  $arraySize=GetarraySize("$readData")


  # Check 5 fields and Carriage Return Line Feed (13,10) and buffer of 4
  if ($arraySize=5 AND $readData[0]=49 AND $readData[$arraySize-1]=10 AND $readData[$arraySize-2]=13 AND $bufferSize=5 )

    # Convert First field of array to ASCII
    $degreesString00=GetAsByte($readData[0])
    $degreesString01=GetAsByte($readData[1])
    $degreesString02=GetAsByte($readData[2])

    # Build Command MeccanoidSetServoMotorPosition (MNSSMP is Shortform) pin 2, servo 0
    $command="MeccanoidSetServoMotorPosition 2 2 "
    $command=$command + $degreesString00+$degreesString01+$degreesString02+" 0"

    # Convert First field of array to Decimal
    $servoDegrees0=$readData[0]*100-4800
    $servoDegrees0=$servoDegrees0 + $readData[1]*10-480
    $servoDegrees0=$servoDegrees0 + $readData[2]-48

    # Check 4 fields and Carriage Return Line Feed (13,10) and buffer of 4
  ELSEif ($arraySize=4 AND $readData[$arraySize-1]=10 AND $readData[$arraySize-2]=13 AND $bufferSize=4)
    # Convert First field of array to ASCII
    $degreesString00=GetAsByte($readData[0])
    $degreesString01=GetAsByte($readData[1])

    # Build Command MeccanoidSetServoMotorPosition (MNSSMP is Shortform) pin 2, servo 0
    $command="MeccanoidSetServoMotorPosition 2 2 "
    $command=$command+$degreesString00+$degreesString01+" 0"

    # Convert servo Position to degrees
    $servoDegrees0=$readData[0]*10-480
    $servoDegrees0 + $servoDegrees0=$readData[1]-48
  endif

    # clear out uart buffers
  $bufferSize=UartAvailable(0,0)
  UARTReadBinary (0, 0, $bufferSize, $garbage)
  Print("Degrees servo 0 = " +$servoDegrees0)
  if ($servoDegrees0 >1 AND $servoDegrees0 < 230)
    if ($moveCheck0!=$servoDegrees0)
      Goto(SendCommand)
    endif
  ELSE
    halt[]
  endif

    ## NOW REPEAT EVERYHTING AGAIN FOR servo 1 #####
    # Need to clean and merge with servo 0#
    # make movecheck = servo degress to see if moved
  $moveCheck1=$servoDegrees1
  # MeccanoidGetServoMotorPosition pin 2, servo 1
  $command="MeccanoidGetServoMotorPosition 2 1"
  Goto(SendCommand)

  # convert $readData to degrees
  $arraySize=GetarraySize("$readData")


  # Check 5 fields and Carriage Return Line Feed (13,10) and buffer of 4
  if ($arraySize=5 AND $readData[0]=49 AND $readData[$arraySize-1]=10 AND $readData[$arraySize-2]=13 AND $bufferSize=5 )

    # Convert First field of array to ASCII
    $degreesString10=GetAsByte($readData[0])
    $degreesString11=GetAsByte($readData[1])
    $degreesString12=GetAsByte($readData[2])
    
    # Build Command MeccanoidSetServoMotorPosition (MNSSMP is Shortform) pin 2, servo 0
    $command="MeccanoidSetServoMotorPosition 2 3 "
    $command=$command + $degreesString10+$degreesString11+$degreesString12+" 0"

    # Convert First field of array to Degrees
    $servoDegrees1=$readData[0]*100-4800
    $servoDegrees1=$servoDegrees1 + $readData[1]*10-480

    # Check 4 fields and Carriage Return Line Feed (13,10) and buffer of 4
  ELSEif ($arraySize=4 AND $readData[$arraySize-1]=10 AND $readData[$arraySize-2]=13 AND $bufferSize=4)
    # Convert First field of array to ASCII
    $degreesString10=GetAsByte($readData[0])
    $degreesString11=GetAsByte($readData[1])

    # Build Command MeccanoidSetServoMotorPosition (MNSSMP is Shortform) pin 2, servo 0
    $command="MeccanoidSetServoMotorPosition 2 3 "
    $command=$command+$degreesString10+$degreesString11+" 0"

    # Convert servo position to degrees
    $servoDegrees1=$readData[0]*10-480
    $servoDegrees1 + $servoDegrees1=$readData[1]-48
  endif

    # clear out uart buffers
  $bufferSize=UartAvailable(0,0)
  UARTReadBinary (0, 0, $bufferSize, $garbage)
  Print("Degrees servo 1 = " +$servoDegrees1)
  if ($servoDegrees0 >1 AND $servoDegrees0 < 230)
    # only move if degrees changed for servo 1
    if ($moveCheck1!=$servoDegrees1)
      Goto(SendCommand)
    endif

  ELSE
    halt[]
  endif


ENDrepeatuntil


Halt()

# Wait Loop as we collect feedback from client
:SendCommand
print("command " +$command)
UARTWrite(0, 0, $command)

$bufferSize=0
# Keep Checking until BufferSize => Target
repeatuntil($bufferSize >= 4)
  $bufferSize=UartAvailable(0,0)
endrepeatuntil

sleep(30) #Wait a bit longer until buffers are full
# now just one more check if it really was all data
$bufferSize=UartAvailable(0,0)
# Now Read the buffers into $readData
UARTReadBinary (0, 0, $bufferSize, $readData)

Return

PRO
Synthiam
#18  

I think you'll need to start by telling us what a "meccanoid bios" is. Is there a data sheet?

PRO
Canada
#19  

Meccanoid BIOS was the original firmware released by Meccano for Meccanoid. It was supposed to be open source but the version they released was not easy to interface with. Some smart folks wrote some code to interface with it (I see there is even a tutorial on EZ-Robot) to control servo's (but they don't read current servo position from it) . It ran on a Arduino.

Meccontrol wrote a better version of the meccanoid BIOS you could interface with, but it was really written to interface with his own app, although he did publish a command interface I mentioned at top of code. Anyway I think I have derailed the thread. I will need to read up on creating plugins.


# To use this you need meccontrol firmware
# The commands are well documented here
# https://meccontrol.com/help/firmware/communication-protocol