Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/libraries/AP_Airspeed/models/NMEA_Sensor.m
Views: 1799
clc1clear23% This is a example of using MATLAB to test a sensor drive using TCP4% we send a NMEA messages at 1hz, note that this assumes that SITL is5% running at real time.67% NMEA is a basic one way protocol but more complex protocols can be8% implemented in the same way910% Use the same TCP/UDP libbary that is used for MALTAB SITL11addpath(genpath('../../SITL/examples/JSON/MATLAB/tcp_udp_ip_2.0.6'))1213% if this dosn't work try the MALTAB SITL example first14pnet('closeall')1516% Init the TCP port, 5763 is serial 217u = pnet('tcpconnect','127.0.0.1',5763);1819flipflop = true;20while(true)2122if flipflop23% send MTW temp message24water_temp = 10 + randn();25NMEA_string = sprintf('$YXMTW,%0.1f,C',water_temp);26else27% send VHW speed message28water_speed_knots = 5 + randn()*2;29water_speed_kph = water_speed_knots * 1.852;30NMEA_string = sprintf('$VWVHW,,T,,M,%0.1f,N,%0.1f,F',water_speed_knots,water_speed_kph);31end32flipflop = ~flipflop;3334% Calculate the correct checksum35NMEA_string = add_checksum(NMEA_string);3637% send to ap38pnet(u,'printf',sprintf('%s\r\n',NMEA_string));39pnet(u,'writepacket');4041% also print to MATLAB console42fprintf("%s\n",NMEA_string);4344% 1hz (ish)45pause(1);46end4748function NMEA_string_out = add_checksum(NMEA_string_in)49checksum = uint8(0);50for i = 2:numel(NMEA_string_in)51checksum = bitxor(checksum,uint8(NMEA_string_in(i)),'uint8');52end53NMEA_string_out = sprintf('%s*%s',NMEA_string_in,dec2hex(checksum));54end555657