BROBOT_Class move c…
 
Share:
Notifications
Clear all

BROBOT_Class move command


c09a37237b75580df935014f5238c8b0?s=80&d=mm&r=g
(@baptiste-crepin)
Member Customer
Joined: 10 months ago
Posts: 1
Topic starter  

Hello,

I’m trying to modify the BROBOT_class (in blocky…) in order to add the move command define in OSC.ino

In the OSC script there is an example:

/1/m XXXX XXXX XXXX =>length:16 Params : speed, step1 ,step2 (all float)

first problem (solved): in regard of the rest of code it’s more probably /1/move . when I use the DEBUG mode , it was confirmed

second problem: how to format the bytearray to send ?

 

In brief, as somebody have already code this function in python ?

Thanks for your responses !

here my python class: everything is working except the move command (in orange )

# BROBOT PYTHON CLASS

# Exampe 1: Simple commands

# Before running the script you need to connect the PC to the BROBOT wifi

# Remember, default password for Wifi network JJROBOTS_XX is 87654321

 

# author: JJROBOTS 2016

# version: 1.01 (27/10/2016)

# Licence: Open Source (GNU LGPLv3)

 

import socket

import time

import struct

 

# CLASS to control BROBOT

class BROBOT(object):

  UDP_IP = “192.168.4.1”     # Default BROBOT IP (with BROBOT JJROBOTS_XX wifi)

  UDP_PORT = 2222  # Default BROBOT port

  sock = 0

  def __init__(self):

    # Create default socket with UDP protocol

    self.sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)

 

  def sendCommand(self,OSCmessage,param):

    base = bytearray(OSCmessage)  # OSC message

    param = bytearray(struct.pack(“>f”,param))

    message = base+param

    print(message)

    self.sock.sendto(message,(self.UDP_IP,self.UDP_PORT))

    time.sleep(0.05)

 

  # Mode: 0 NORMAL MODE, 1 PRO MODE

  def mode(self,value=0.0):

    print (“BROBOT Mode:”,value)

    if (value!=1): value = 0.0

    # Encapsulate the commands on OSC protocol UDP message and send…

    self.sendCommand(b‘/1/toggle1/\x00\x00,f\x00\x00’,value)

  # move command

 

  def move(self,speed=0,mstep1=0,mstep2=0):

    print(“BROBOT move”,speed,mstep1,mstep2)

    base = bytearray(b’/1/move\x00′)

    param1=bytearray(struct.pack(“>f”,speed)) #>h pour bigendian short integer, >f pour bigendianfloat

    espace =bytearray(b’\x00′)

    param2=bytearray(struct.pack(“>f”,mstep1))

    param3=bytearray(struct.pack(“>f”,mstep2))

    message = base+param1+espace+param2+espace+param3

    print(message)

    self.sock.sendto(message,(self.UDP_IP,self.UDP_PORT))

  

  #XY command Ex: /1/xy1  f,f,    XXXXXXXX => length: 24 Params: float,float (0.0-1.0)

  def moveXY(self,valeurx=0.0,valeury=0.0):

    base = bytearray(b‘/1/xy1\x00\x00,f,f’)

    param1=bytearray(struct.pack(“>f”,valeurx)) #>h pour bigendian short integer, >f pour bigendianfloat

    param2=bytearray(struct.pack(“>f”,valeury))

    message = base+param1+param2

    print(message)

    self.sock.sendto(message,(self.UDP_IP,self.UDP_PORT))

 

  #push command  PUSH (1,2,3,4)    Ex: /1/push1    f,  XXXX => length:20 Param: float

  def push1(self,valeur=0.0):

    base = bytearray(b‘/1/push1\x00\x00\x00\x00f,\x00\x00’)

    param1=bytearray(struct.pack(“>f”,valeur)) #>h pour bigendian short integer, >f pour bigendianfloat

    message = base+param1

    print(message)

    self.sock.sendto(message,(self.UDP_IP,self.UDP_PORT))

 

 

 

 

  # Throttle command. Values from [-1.0 to 1.0] positive: forward

  def throttle(self,value=0.0):

    print (“BROBOT Throttle:”,value)

    value = (value+1.0)/2.0  # Adapt values to 0.0-1.0 range

    self.sendCommand(b‘/1/fader1\x00\x00\x00,f\x00\x00’,value)  #send OSC message

 

  # Steering command. Values from [-1.0 to 1.0] positive: turn right

  def steering(self,value=0.0):

    print (“BROBOT Steering:”,value)

    value = (value+1.0)/2.0  # Adapt values to 0.0-1.0 range

    self.sendCommand(b‘/1/fader2\x00\x00\x00,f\x00\x00’,value)  #send OSC message

 

  # Servo command. Values 0 or 1 (activated)

  def servo(self,value=0.0):

    print (“BROBOT Servo:”,value)

    if (value!=1):value=0.0

    self.sendCommand(b‘/1/push1\x00\x00,f\x00\x00’,value)  #send OSC message

 

  # commande Kp Values from [0 to 1]

  def kp_acc(self,value): 

    print (“test BROBOT kp_acc:”,value)

    #value = (value+1.0)/2.0  # Adapt values to 0.0-1.0 range

    self.sendCommand(b‘/2/fader3\x00\x00\x00,f\x00\x00’,value)  #send OSC message

 

  def ki_acc(self,value):

    print (“test BROBOT ki_acc:”,value)

    #value = (value+1.0)/2.0  # Adapt values to 0.0-1.0 range

    self.sendCommand(b‘/2/fader4\x00\x00\x00,f\x00\x00’,value)  #send OSC

 

  def kp(self,value):

    print (“test BROBOT kp:”,value)

    #value = (value+1.0)/2.0  # Adapt values to 0.0-1.0 range

    self.sendCommand(b‘/2/fader1\x00\x00\x00,f\x00\x00’,value)  #send OSC message

 

  def kd(self,value):

    print (“test BROBOT kd:”,value)

    #value = (value+1.0)/2.0  # Adapt values to 0.0-1.0 range

    self.sendCommand(b‘/2/fader2\x00\x00\x00,f\x00\x00’,value)  #send OSC message

 

 

 

 

   

 


Quote
Share: