Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable scan frequence #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/LMS1xx/LMS1xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,16 @@ class LMS1xx {
*/
void setScanDataCfg(const scanDataCfg &cfg);

/*!
* @brief Set output range configuration.
* Get output range configuration :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set

* - angle resolution.
* - start angle.
* - stop angle.
* @param cfg structure containing output range configuration.
*/
void setOutputRange(const scanOutputRange &cfg);

/*!
* @brief Get current output range configuration.
* Get output range configuration :
Expand Down
12 changes: 12 additions & 0 deletions src/LMS1xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,18 @@ void LMS1xx::setScanDataCfg(const scanDataCfg &cfg) {
buf[len - 1] = 0;
}

void LMS1xx::setOutputRange(const scanOutputRange &cfg) {
char buf[100];
sprintf(buf, "%c%s 1 %X %X %X%c", 0x02, "sWN LMPoutputRange",
cfg.angleResolution, cfg.startAngle, cfg.stopAngle, 0x03);

write(sockDesc, buf, strlen(buf));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strlen would return the length until the first null character 0x00. See http://www.cplusplus.com/reference/cstring/strlen/

Since buf[100] isn't initialized to anything, the return value is unexpected. You can solve that adding 0x00 after 0x03.

However, if any of the cfg fields introduces a 0x00 byte into the buf array, the strlen would be smaller than it should.

I think it'd be better to take the length from the return value of sprintf. See http://www.cplusplus.com/reference/cstdio/sprintf/


int len = read(sockDesc, buf, 100);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the meaning of the third param of the read function? I'm asking because depending on that you should have buf[101] instead of buf[100], because the buf[len - 1] = 0 might overwrite the latest value read if read reads 100 characters.


buf[len - 1] = 0;
}

scanOutputRange LMS1xx::getScanOutputRange() const {
scanOutputRange outputRange;
char buf[100];
Expand Down
7 changes: 1 addition & 6 deletions src/LMS1xx_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,9 @@ int main(int argc, char **argv)
outputRange = laser.getScanOutputRange();
}

//check if laser is fully initialized, else reconnect
//assuming fully initialized => scaningFrequency=5000
if (cfg.scaningFrequency != 5000) {
laser.disconnect();
ROS_INFO("Waiting for laser to initialize...");
}

} while (!laser.isConnected() || cfg.scaningFrequency != 5000);
} while (!laser.isConnected());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should have an additional check instead, not forcing anything, but a sanity check to be completely sure the configuration is good.


if (laser.isConnected()) {
ROS_INFO("Connected to laser.");
Expand Down