Welcome to Synthiam!

The easiest way to program the most powerful robots. Use technologies by leading industry experts. ARC is a free-to-use robot programming software that makes servo automation, computer vision, autonomous navigation, and artificial intelligence easy.

Get Started
Switzerland
Asked — Edited

Roboclaw, Packet Serial Mode With Crc/ How To Execute Cyclic Script In Moble App

Hi,

1.
did anybody already implement the Packet Serial Mode with CRC into EZB script?
before I start to translate...........maybe someone did already the work ;-)

roboclaw manual:
CRC16 Checksum Calculation
Roboclaw uses a CRC(Cyclic Redundancy Check) to validate each packet it receives. This is more
complex than a simple checksum but prevents errors that could otherwise cause unexpected
actions to execute on the Roboclaw.
The CRC can be calculated using the following code(example in C):
//Calculates CRC16 of nBytes of data in byte array message
unsigned int crc16(unsigned char *packet, int nBytes) {
for (int byte = 0; byte < nBytes; byte++) {
crc = crc ^ ((unsigned int)packet[byte] << 8);
for (unsigned char bit = 0; bit < 8; bit++) {
if (crc & 0x8000) {
crc = (crc << 1) ^ 0x1021;
} else {
crc = crc << 1;
}
}
}
return crc;
}

2.
how can I execute a script every 500ms in mobile app?


ARC Pro

Upgrade to ARC Pro

Unleash your creativity with the power of easy robot programming using Synthiam ARC Pro

AI Support Bot
Related Content
Synthiam
Based on your post activity, we found some content that may be interesting to you. Explore these other tutorials and community conversations.
PRO
Synthiam
#1  
There isn't enough information to fully understand the protocol, but here is what you're requesting based on the code posted..

PS, i guessed most of it. Such as the sending order of the packet, the crc, and the packet data itself (super fudged)

Code:


# init the first uart to 9600 (Guessing)
uartinit(0, 0, 9600)

# define the packet size to 10
definearray($packet, 10)

# specify the packet size length (which is 10)
$nBytes = 10

# put some data in the packet
$packet[0] = 10
$packet[1] = 9
$packet[2] = 8
$packet[3] = 7
$packet[4] = 6
$packet[5] = 5
$packet[6] = 4
$packet[7] = 3
$packet[8] = 2
$packet[9] = 1

# send the packet with crc every 500ms
:loop

# init the crc variable
$crc = 0

repeat ($byte, 0, $nBytes, 1)

if ($crc & 0x8000)
crc = (crc << 1) ^ 0x1021
ELSE
crc = crc << 1
endif

endrepeat

# send the packet and crc (guessing)
uartwritebinary(0, 0, $packet)
uartwrite(0, 0, $crc)

# pause for 500ms
sleep(500)

goto(loop)