Shop OBEX P1 Docs P2 Docs Learn Events
(SOLVED) #28044 laserRangeFinder: problems with SC-C: convert lrfBaseTest_1.spin to c-program: — Parallax Forums

(SOLVED) #28044 laserRangeFinder: problems with SC-C: convert lrfBaseTest_1.spin to c-program:

nomadnomad Posts: 276
edited 2016-10-10 12:13 in Learn with BlocklyProp
hello

i have problems convert lrfBaseTest_1.spin to lrfBaseTest_1.c

on the c-source : program cant read the distance-values.
troubles with the serial-stuff
as attachments lrf-c.zip (spin + my bad c-source).
my new c-code:
//
// automatically generated by spin2cpp v3.2.0 on Sun Oct 9 16:18:15 2016
// ./spin2cpp.linux LRF_Basic.spin
//

/*
run fehler bei: range = readDec(lrf);
┌───────────────────────────────────────────────┐
│ Laser Range Finder: Basic Demonstration │
│ │
│ Author: Joe Grand [www.grandideastudio.com] │
│ Contact: support@parallax.com │
│ │
│ See end of file for terms of use. │
└───────────────────────────────────────────────┘

Program Description:

This program demonstrates the Parallax Laser Range Finder (LRF) module.
The distance to the target object is displayed in the Parallax Serial Terminal.


Laser Range Finder Connector (4 pin male header)
────────────────────────────────────────────────

SIN ────── P6
SOUT ────── P7
VCC ────── +5V (VDD)
GND ──────┐

GND (VSS)


Revisions:

1.1 (July 2011): Initial release

*/
#include <simpletools.h>
#include <simpletext.h>
#include <fdserial.h>
#include "LRF_Basic.h"

float range;

serial *lrf;

char s[14];
char ch[1];
int i;

char c;

#define Yield__() __asm__ volatile( "" ::: "memory" )
#define Highmult__(X, Y) ( ( (X) * (int64_t)(Y) ) >> 32 )
uint8_t LRF_Basic::dat[] = {
0x50, 0x61, 0x72, 0x61, 0x6c, 0x6c, 0x61, 0x78, 0x20, 0x4c, 0x61, 0x73, 0x65, 0x72, 0x20, 0x52,
0x61, 0x6e, 0x67, 0x65, 0x20, 0x46, 0x69, 0x6e, 0x64, 0x65, 0x72, 0x0d, 0x42, 0x61, 0x73, 0x69,
0x63, 0x20, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x20, 0x44, 0x65, 0x6d, 0x6f, 0x6e, 0x73, 0x74, 0x72,
0x61, 0x74, 0x69, 0x6f, 0x6e, 0x0d, 0x0d, 0x00,
};
// Extended Full Duplex Serial by Martin Hebel (http://obex.parallax.com/objects/31/)

int main()
{
lrf = fdserial_open(0, 1, 0, 115200);

print("Waiting for LRF module...\n");

// Send character
writeChar(lrf, 'U'); //putChar('U');

while(!(fdserial_rxCheck(lrf) == ':'))
{
Yield__();
}

print("Ready!\n");

while(1)
{
// Send command
writeChar(lrf, 'R');

memset(s, 0, 6);
for(i = 0; i < 6; i++)
{
s = readChar(lrf);
if(s == 'D') Yield__();
if(s == '=') Yield__();
if(s == ' ') Yield__();
}

sscan(s, "%f", &range);

print("Distance: %2.2f cm\n", range/10.0); // in centimeter
pause(200);
}
}

/*
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ TERMS OF USE: MIT License │
├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation │
│files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, │
│modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software│
│is furnished to do so, subject to the following conditions: │
│ │
│The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.│
│ │
│THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE │
│WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR │
│COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │
│ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
*/

dirty, but running....
for landingGear:

please, can somebody help me:
Thanks for tips, hints and tricks.
regards
nomad
Sign In or Register to comment.