Git Product home page Git Product logo

Comments (12)

nolan4 avatar nolan4 commented on June 24, 2024 1

Sounds good! Thanks again.

from pyserialtransfer.

PowerBroker2 avatar PowerBroker2 commented on June 24, 2024
  1. You should use packed structs, i.e.:

struct __attribute__((packed)) STRUCT {
char z;
double y;
} testStruct;

  1. When transferring ints to Python, you need to either specify int32_t or list_format='h'

from pyserialtransfer.

nolan4 avatar nolan4 commented on June 24, 2024

Thanks for your fast reply! Where would I specify int32_t? Here is what I now have:
const int packetSize = 20;
struct __attribute__((packed)) STRUCT {
int ax[packetSize];
int ay[packetSize];
int az[packetSize];
int gx[packetSize];
int gy[packetSize];
int gz[packetSize];
int ts[packetSize];
} sendStruct;

data = link.rx_obj(obj_type=list, obj_byte_size= 4 * 20 * 7, list_format='h')

I do get data transferred this way, but the formatting is odd (separated by -1s and 0s?) and I am not receiving all of the data. For a packetSize of 20, I should get 140 values. I only receive 64 values (excluding the -1s and 0s) and they are shown here:

[-5152, -1, -5152, -1, -5184, -1, -5200, -1, -5248, -1, -5224, -1, -5232, -1, -5232, -1, -5328, -1, -5192, -1, -5312, -1, -5192, -1, -5192, -1, -5096, -1, -5464, -1, -5464, -1, -5464, -1, -5232, -1, -5184, -1, -5232, -1, 14248, 0, 14248, 0, 14376, 0, 14344, 0, 14392, 0, 14592, 0, 14496, 0, 14496, 0, 14416, 0, 14352, 0, 14464, 0, 14520, 0, 14520, 0, 14496, 0, 14488, 0, 14488, 0, 14616, 0, 14664, 0, 14552, 0, 14576, 0, -4520, -1, -4520, -1, -4432, -1, -4432, -1, -4584, -1, -4648, -1, -4648, -1, -4648, -1, -4504, -1, -4512, -1, -4600, -1, -4736, -1, -4736, -1, -4624, -1, -4408, -1, -4408, -1, -4448, -1, -4536, -1, -4592, -1, -4504, -1, 43, 0, 135, 0, -8, -1, -31]

from pyserialtransfer.

PowerBroker2 avatar PowerBroker2 commented on June 24, 2024

The values you're trying to transfer are most likely from an IMU and probably should be floats, which is actually easier for the libraries to handle automatically. I'd suggest switching to floats and seeing if that doesn't fix your issue.

from pyserialtransfer.

PowerBroker2 avatar PowerBroker2 commented on June 24, 2024

Where would I specify int32_t?

In the Arduino code inside your struct def like this:

struct __attribute__((packed)) STRUCT {
int32_t ax[packetSize];
int32_t ay[packetSize];
int32_t az[packetSize];
int32_t gx[packetSize];
int32_t gy[packetSize];
int32_t gz[packetSize];
int32_t ts[packetSize];
} sendStruct;

from pyserialtransfer.

nolan4 avatar nolan4 commented on June 24, 2024

Yes you're right about the IMU data. To record faster I just store the raw int16_t values coming from the accelerometer and gyroscope. The first 6 values come through correctly when I use int16_t in the struct def. The only issue is the timestamp which is the difference between two unsigned longs. Is there a correct way to determine the obj_byte_size for this struct? The code/output I have now for a packetSize of 10 is:

const int packetSize = 10;
struct __attribute__((packed)) STRUCT {
int16_t ax[packetSize];
int16_t ay[packetSize];
int16_t az[packetSize];
int16_t gx[packetSize];
int16_t gy[packetSize];
int16_t gz[packetSize];
unsigned long ts[packetSize];
} imuStruct;

y = link.rx_obj(obj_type=list, obj_byte_size=(2*packetSize*6 + 4*packetSize), list_format='h')

acc_x: [-5168, -5432, -5328, -5328, -5136, -5216, -5400, -5496, -5496, -5264],
acc_y: [14480, 14520, 14536, 14536, 14456, 14648, 14576, 14352, 14352, 14496],
acc_z: [-4600, -4616, -4456, -4456, -4608, -4776, -4552, -4472, -4472, -4496],
gyr_x: [137, 124, -61, -54, -13, 124, -66, -3, -67, 135],
gyr_y: [19, 30, 88, 130, -387, -104, -103, -34, -120, 94],
gyr_z: [-216, 170, -338, 262, -81, -65, -213, -17, -173, -4],
ts: [3121, 0, 3299, 0, 3471, 0, 3634, 0, 3797, 0]]

from pyserialtransfer.

PowerBroker2 avatar PowerBroker2 commented on June 24, 2024

In that case, you can use list_format='h' for the 16-bit values and list_format='i' for the long values. Take a look at the pySerialTransfer readme example to see how to parse multiple objects from a single packet

from pyserialtransfer.

nolan4 avatar nolan4 commented on June 24, 2024

Ok based on the readme code, this is what I am now doing.

Here is the arduino code:

const int packetSize = 20;
struct __attribute__((packed)) STRUCT {
int16_t ax[packetSize];
int16_t ay[packetSize];
int16_t az[packetSize];
int16_t gx[packetSize];
int16_t gy[packetSize];
int16_t gz[packetSize];
unsigned long ts[packetSize];
} imuStruct;

Here is the python code (based on the readme):

packetSize = 20

acc_size = 2*packetSize*3     # bytes required for 20*3 int16_t values
gyr_size = 2*packetSize*3      # bytes required for 20*3 int16_t values
ts_size = 4*packetSize           # bytes required for 20*3 unsigned long values

a = link.rx_obj(obj_type=list, obj_byte_size=acc_size, start_pos=0, list_format='h')
g = link.rx_obj(obj_type=list, obj_byte_size=gyr_size, start_pos=acc_size, list_format='h')
ts = link.rx_obj(obj_type=list, obj_byte_size=ts_size, start_pos=(acc_size + gyr_size), list_format='i')

Here is the error:

ts = link.rx_obj(obj_type=list, obj_byte_size=ts_size, start_pos=(acc_size + gyr_size), list_format='i')
  File "/home/nolan/.local/lib/python3.8/site-packages/pySerialTransfer/pySerialTransfer.py", line 355, in rx_obj
    arr = array(list_format, buff)
ValueError: bytes length not a multiple of item size

from pyserialtransfer.

nolan4 avatar nolan4 commented on June 24, 2024

It works correctly for a packetSize of 15. I'm pretty sure it is an issue with how I am defining the obj_byte_size and start_pos. Here is the output:

a: [-4024, -4080, -4120, -4144, -4144, -4264, -4096, -4096, -3832, -3936, -4008, -4008, -3976, -3976, -4008, 15648, 15560, 15536, 15648, 15552, 15456, 15504, 15504, 15720, 15600, 15424, 15424, 15512, 15544, 15624, -2016, -1968, -2192, -2144, -1976, -2120, -2152, -2152, -2144, -2064, -1976, -1976, -2008, -2072, -2000]

g: [-80, -86, -421, -151, 80, 66, 379, -202, 53, -58, 344, -76, 220, -129, 216, -239, 352, -232, 368, -79, 18, -341, -86, -20, -420, 145, -140, 491, -136, -4, -153, -158, -157, 265, -143, 385, -297, 74, -296, 164, -381, 188, -358, 111, -49]

ts: [1020, 1201, 1369, 1644, 1807, 1970, 2133, 2296, 2459, 2649, 2812, 2975, 3139, 3302, 3465]

from pyserialtransfer.

PowerBroker2 avatar PowerBroker2 commented on June 24, 2024

(2*20*3) + (2*20*3) + (4*20*3) = 480

You can't stuff more than 254 bytes per packet

from pyserialtransfer.

nolan4 avatar nolan4 commented on June 24, 2024

Ok yes that is the issue. Is there a way I can experiment with increasing this limit? Thanks for your help!

from pyserialtransfer.

PowerBroker2 avatar PowerBroker2 commented on June 24, 2024

The max packet size is limited due to using a 1 byte COBS overhead field. If you need to send a multi-packet transmission, look at the file transfer examples

from pyserialtransfer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.