Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python sample
07-15-2019, 01:00 AM (This post was last modified: 07-15-2019 01:01 AM by dliouville.)
Post: #1
python sample
Hi,

Is there some python sample to control blimpduino ?
I've read the Blimpduino COMMS protocol (packet definition) but it's not totally clear, I feel much better with simple sample ...
Find all posts by this user
Quote this message in a reply
08-25-2019, 01:52 PM
Post: #2
RE: python sample
(07-15-2019 01:00 AM)dliouville Wrote:  Hi,

Is there some python sample to control blimpduino ?
I've read the Blimpduino COMMS protocol (packet definition) but it's not totally clear, I feel much better with simple sample ...

I've found my way ... It work with something like this in python3 :

import socket

serverAddressPort = ("192.168.4.1", 2222)
bufferSize = 4096

# Channels values to send
ch1_value = 123 # Throttle
ch2_value = 0 # Steering
ch3_value = 0 # Height
ch4_value = 0 # unused
ch5_value = 0 # Mode Mode 0=>manual, Mode 1=> Manual control with altitude hold, Mode 2=> Yaw stabilization, Mode 3=> Yaw stabilization with altitude hold, Mode 100=> Stop motors
ch6_value = 0 # unused
ch7_value = 0 # unused
ch8_value = 0 # unused

# Transform values to bytes
header = str.encode("JJBM")
bch1 = (ch1_value).to_bytes(2, byteorder='big', signed=True)
bch2 = (ch2_value).to_bytes(2, byteorder='big', signed=True)
bch3 = (ch3_value).to_bytes(2, byteorder='big', signed=True)
bch4 = (ch4_value).to_bytes(2, byteorder='big', signed=True)
bch5 = (ch5_value).to_bytes(2, byteorder='big', signed=True)
bch6 = (ch6_value).to_bytes(2, byteorder='big', signed=True)
bch7 = (ch7_value).to_bytes(2, byteorder='big', signed=True)
bch8 = (ch8_value).to_bytes(2, byteorder='big', signed=True)

# Compose command message
bMessage = b"".join([header, bch1, bch2, bch3, bch4, bch5, bch6, bch7, bch8])

# Create a UDP socket at client side
UDPClientSocket = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)

# Send to server using created UDP socket
UDPClientSocket.sendto(bMessage, serverAddressPort)
Find all posts by this user
Quote this message in a reply
08-25-2019, 11:11 PM
Post: #3
RE: python sample
(08-25-2019 01:52 PM)dliouville Wrote:  
(07-15-2019 01:00 AM)dliouville Wrote:  Hi,

Is there some python sample to control blimpduino ?
I've read the Blimpduino COMMS protocol (packet definition) but it's not totally clear, I feel much better with simple sample ...

I've found my way ... It work with something like this in python3 :

import socket

serverAddressPort = ("192.168.4.1", 2222)
bufferSize = 4096

# Channels values to send
ch1_value = 123 # Throttle
ch2_value = 0 # Steering
ch3_value = 0 # Height
ch4_value = 0 # unused
ch5_value = 0 # Mode Mode 0=>manual, Mode 1=> Manual control with altitude hold, Mode 2=> Yaw stabilization, Mode 3=> Yaw stabilization with altitude hold, Mode 100=> Stop motors
ch6_value = 0 # unused
ch7_value = 0 # unused
ch8_value = 0 # unused

# Transform values to bytes
header = str.encode("JJBM")
bch1 = (ch1_value).to_bytes(2, byteorder='big', signed=True)
bch2 = (ch2_value).to_bytes(2, byteorder='big', signed=True)
bch3 = (ch3_value).to_bytes(2, byteorder='big', signed=True)
bch4 = (ch4_value).to_bytes(2, byteorder='big', signed=True)
bch5 = (ch5_value).to_bytes(2, byteorder='big', signed=True)
bch6 = (ch6_value).to_bytes(2, byteorder='big', signed=True)
bch7 = (ch7_value).to_bytes(2, byteorder='big', signed=True)
bch8 = (ch8_value).to_bytes(2, byteorder='big', signed=True)

# Compose command message
bMessage = b"".join([header, bch1, bch2, bch3, bch4, bch5, bch6, bch7, bch8])

# Create a UDP socket at client side
UDPClientSocket = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)

# Send to server using created UDP socket
UDPClientSocket.sendto(bMessage, serverAddressPort)

THANK YOU FOR THIS! I am not very skilled with Python and this will help me A LOT! :-D
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)