我正在使用omnet5
,veins 4.4
和sumo 0.25
。我看过Converting Veins Coordinates to GPS,因为我有更新版本,所以没有多大帮助。
这个https://stackoverflow.com/questions/40650825/connection-to-traci-server-lost-check-your-servers-log-error-message-88-soc看起来似乎可能会有一些错误检查,但我不确定用户做了什么让它工作。
我已经看到你可以使用omnet2traci将常规坐标转换为相邻坐标,但是我无法正确实现它。当我尝试在消息中调用它时:
class Veins::TraCIConnection::omnet2traci;
然后使用:
Veins::TraCICoord gpspos = omnet2traci(senderPos);
但是我收到了未声明的标识符错误。我尝试更改为.cc
和.h code
以通过创建omnet2traci coding from TraCIConnection
的小副本来补偿它。毕竟它给了我错误:
omnetpp-5.0/include/omnetpp/cdynamicexpression.h:50:9: error: expected identifier
ADD, SUB, MUL, DIV, MOD, POW, NEG,
^
.\veins/modules/mobility/traci/TraCIConstants.h:707:13: note: expanded from macro 'ADD'
#define ADD 0x80
^
omnetpp-5.0/include/omnetpp/coutvector.h:66:27: error: expected identifier
enum Type { TYPE_INT, TYPE_DOUBLE, TYPE_ENUM };
^
.\veins/modules/mobility/traci/TraCIConstants.h:304:21: note: expanded from macro 'TYPE_DOUBLE'
#define TYPE_DOUBLE 0x0B
^
在这一点上,它似乎解决了这个问题并希望它可以解决问题而不是实际解决问题。以下完整代码,部分添加已加星标。 *注意我必须剪切.cc代码的末尾部分,因为它超过了文本限制,但没有任何改变。
Waveshortmessage.msg
//Waveshortmessage.msg
cplusplus {{
**#include <stdint.h>
#include "veins/modules/mobility/traci/TraCIBuffer.h"
#include "veins/modules/mobility/traci/TraCICommandInterface.h"
#include "veins/modules/mobility/traci/TraCIConnection.h"
#include "veins/modules/mobility/traci/TraCIConstants.h"
#include "veins/modules/mobility/traci/TraCICoord.h"**
#include "veins/base/utils/Coord.h"
}}
class noncobject Coord;
**class noncobject Veins::TraCICoord;
class Veins::TraCIConnection::omnet2traci;**
packet WaveShortMessage {
//Version of the Wave Short Message
int wsmVersion = 0;
//Determine which security mechanism was used
int securityType = 0;
//Channel Number on which this packet was sent
int channelNumber;
//Data rate with which this packet was sent
int dataRate = 1;
//Power Level with which this packet was sent
int priority = 3;
//Unique number to identify the service
int psid = 0;
//Provider Service Context
string psc = "Service with some Data";
//Length of Wave Short Message
int wsmLength;
//Data of Wave Short Message
string wsmData = "Some Data";
int senderAddress = 0;
int recipientAddress = -1;
int serial = 0;
Coord senderPos;
**Veins::TraCICoord gpspos = omnet2traci(senderPos);**
simtime_t timestamp = 0;
}
Waveshortmessage.cc
//waveshortmessage.cc
// Generated file, do not edit! Created by nedtool 5.0 from veins/modules/messages/WaveShortMessage.msg.
//
**#define WANT_WINSOCK2
#include <platdep/sockets.h>
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(__CYGWIN__) || defined(_WIN64)
#include <ws2tcpip.h>
#else
#include <netinet/tcp.h>
#include <netdb.h>
#include <arpa/inet.h>
#endif
#include <algorithm>
#include <functional>
//#include "veins/modules/mobility/traci/TraCIConnection.h"
#include "veins/modules/mobility/traci/TraCIConstants.h"
#define MYDEBUG EV**
// Disable warnings about unused variables, empty switch stmts, etc:
#ifdef _MSC_VER
# pragma warning(disable:4101)
# pragma warning(disable:4065)
#endif
#include <iostream>
#include <sstream>
#include "WaveShortMessage_m.h"
namespace omnetpp {
// Template pack/unpack rules. They are declared *after* a1l type-specific pack functions for multiple reasons.
// They are in the omnetpp namespace, to allow them to be found by argument-dependent lookup via the cCommBuffer argument
// Packing/unpacking an std::vector
template<typename T, typename A>
void doParsimPacking(omnetpp::cCommBuffer *buffer, const std::vector<T,A>& v)
{
int n = v.size();
doParsimPacking(buffer, n);
for (int i = 0; i < n; i++)
doParsimPacking(buffer, v[i]);
}
template<typename T, typename A>
void doParsimUnpacking(omnetpp::cCommBuffer *buffer, std::vector<T,A>& v)
{
int n;
doParsimUnpacking(buffer, n);
v.resize(n);
for (int i = 0; i < n; i++)
doParsimUnpacking(buffer, v[i]);
}
// Packing/unpacking an std::list
template<typename T, typename A>
void doParsimPacking(omnetpp::cCommBuffer *buffer, const std::list<T,A>& l)
{
doParsimPacking(buffer, (int)l.size());
for (typename std::list<T,A>::const_iterator it = l.begin(); it != l.end(); ++it)
doParsimPacking(buffer, (T&)*it);
}
template<typename T, typename A>
void doParsimUnpacking(omnetpp::cCommBuffer *buffer, std::list<T,A>& l)
{
int n;
doParsimUnpacking(buffer, n);
for (int i=0; i<n; i++) {
l.push_back(T());
doParsimUnpacking(buffer, l.back());
}
}
// Packing/unpacking an std::set
template<typename T, typename Tr, typename A>
void doParsimPacking(omnetpp::cCommBuffer *buffer, const std::set<T,Tr,A>& s)
{
doParsimPacking(buffer, (int)s.size());
for (typename std::set<T,Tr,A>::const_iterator it = s.begin(); it != s.end(); ++it)
doParsimPacking(buffer, *it);
}
template<typename T, typename Tr, typename A>
void doParsimUnpacking(omnetpp::cCommBuffer *buffer, std::set<T,Tr,A>& s)
{
int n;
doParsimUnpacking(buffer, n);
for (int i=0; i<n; i++) {
T x;
doParsimUnpacking(buffer, x);
s.insert(x);
}
}
// Packing/unpacking an std::map
template<typename K, typename V, typename Tr, typename A>
void doParsimPacking(omnetpp::cCommBuffer *buffer, const std::map<K,V,Tr,A>& m)
{
doParsimPacking(buffer, (int)m.size());
for (typename std::map<K,V,Tr,A>::const_iterator it = m.begin(); it != m.end(); ++it) {
doParsimPacking(buffer, it->first);
doParsimPacking(buffer, it->second);
}
}
template<typename K, typename V, typename Tr, typename A>
void doParsimUnpacking(omnetpp::cCommBuffer *buffer, std::map<K,V,Tr,A>& m)
{
int n;
doParsimUnpacking(buffer, n);
for (int i=0; i<n; i++) {
K k; V v;
doParsimUnpacking(buffer, k);
doParsimUnpacking(buffer, v);
m[k] = v;
}
}
// Default pack/unpack function for arrays
template<typename T>
void doParsimArrayPacking(omnetpp::cCommBuffer *b, const T *t, int n)
{
for (int i = 0; i < n; i++)
doParsimPacking(b, t[i]);
}
template<typename T>
void doParsimArrayUnpacking(omnetpp::cCommBuffer *b, T *t, int n)
{
for (int i = 0; i < n; i++)
doParsimUnpacking(b, t[i]);
}
// Default rule to prevent compiler from choosing base class' doParsimPacking() function
template<typename T>
void doParsimPacking(omnetpp::cCommBuffer *, const T& t)
{
throw omnetpp::cRuntimeError("Parsim error: no doParsimPacking() function for type %s", omnetpp::opp_typename(typeid(t)));
}
template<typename T>
void doParsimUnpacking(omnetpp::cCommBuffer *, T& t)
{
throw omnetpp::cRuntimeError("Parsim error: no doParsimUnpacking() function for type %s", omnetpp::opp_typename(typeid(t)));
}
} // namespace omnetpp
// forward
template<typename T, typename A>
std::ostream& operator<<(std::ostream& out, const std::vector<T,A>& vec);
// Template rule which fires if a struct or class doesn't have operator<<
template<typename T>
inline std::ostream& operator<<(std::ostream& out,const T&) {return out;}
// operator<< for std::vector<T>
template<typename T, typename A>
inline std::ostream& operator<<(std::ostream& out, const std::vector<T,A>& vec)
{
out.put('{');
for(typename std::vector<T,A>::const_iterator it = vec.begin(); it != vec.end(); ++it)
{
if (it != vec.begin()) {
out.put(','); out.put(' ');
}
out << *it;
}
out.put('}');
char buf[32];
sprintf(buf, " (size=%u)", (unsigned int)vec.size());
out.write(buf, strlen(buf));
return out;
}
**Veins::TraCICoord Veins::TraCIConnection::omnet2traci(Coord coord) const {
return TraCICoord(coord.x + netbounds1.x - margin, (netbounds2.y - netbounds1.y) - (coord.y - netbounds1.y) + margin);
}
std::list<Veins::TraCICoord> Veins::TraCIConnection::omnet2traci(const std::list<Coord>& list) const {
std::list<TraCICoord> result;
std::transform(list.begin(), list.end(), std::back_inserter(result), std::bind1st(std::mem_fun<TraCICoord, TraCIConnection, Coord>(&TraCIConnection::omnet2traci), this));
return result;
}**
Register_Class(WaveShortMessage);
WaveShortMessage::WaveShortMessage(const char *name, int kind) : ::omnetpp::cPacket(name,kind)
{
this->wsmVersion = 0;
this->securityType = 0;
this->channelNumber = 0;
this->dataRate = 1;
this->priority = 3;
this->psid = 0;
this->psc = "Service with some Data";
this->wsmLength = 0;
this->wsmData = "Some Data";
this->senderAddress = 0;
this->recipientAddress = -1;
this->serial = 0;
this->gpspos = omnet2traci(senderPos);
this->timestamp = 0;
}
WaveShortMessage::WaveShortMessage(const WaveShortMessage& other) : ::omnetpp::cPacket(other)
{
copy(other);
}
WaveShortMessage::~WaveShortMessage()
{
}
WaveShortMessage& WaveShortMessage::operator=(const WaveShortMessage& other)
{
if (this==&other) return *this;
::omnetpp::cPacket::operator=(other);
copy(other);
return *this;
}
void WaveShortMessage::copy(const WaveShortMessage& other)
{
this->wsmVersion = other.wsmVersion;
this->securityType = other.securityType;
this->channelNumber = other.channelNumber;
this->dataRate = other.dataRate;
this->priority = other.priority;
this->psid = other.psid;
this->psc = other.psc;
this->wsmLength = other.wsmLength;
this->wsmData = other.wsmData;
this->senderAddress = other.senderAddress;
this->recipientAddress = other.recipientAddress;
this->serial = other.serial;
this->senderPos = other.senderPos;
this->gpspos = other.gpspos;
this->timestamp = other.timestamp;
}
void WaveShortMessage::parsimPack(omnetpp::cCommBuffer *b) const
{
::omnetpp::cPacket::parsimPack(b);
doParsimPacking(b,this->wsmVersion);
doParsimPacking(b,this->securityType);
doParsimPacking(b,this->channelNumber);
doParsimPacking(b,this->dataRate);
doParsimPacking(b,this->priority);
doParsimPacking(b,this->psid);
doParsimPacking(b,this->psc);
doParsimPacking(b,this->wsmLength);
doParsimPacking(b,this->wsmData);
doParsimPacking(b,this->senderAddress);
doParsimPacking(b,this->recipientAddress);
doParsimPacking(b,this->serial);
doParsimPacking(b,this->senderPos);
doParsimPacking(b,this->gpspos);
doParsimPacking(b,this->timestamp);
}
void WaveShortMessage::parsimUnpack(omnetpp::cCommBuffer *b)
{
::omnetpp::cPacket::parsimUnpack(b);
doParsimUnpacking(b,this->wsmVersion);
doParsimUnpacking(b,this->securityType);
doParsimUnpacking(b,this->channelNumber);
doParsimUnpacking(b,this->dataRate);
doParsimUnpacking(b,this->priority);
doParsimUnpacking(b,this->psid);
doParsimUnpacking(b,this->psc);
doParsimUnpacking(b,this->wsmLength);
doParsimUnpacking(b,this->wsmData);
doParsimUnpacking(b,this->senderAddress);
doParsimUnpacking(b,this->recipientAddress);
doParsimUnpacking(b,this->serial);
doParsimUnpacking(b,this->senderPos);
doParsimUnpacking(b,this->gpspos);
doParsimUnpacking(b,this->timestamp);
}
int WaveShortMessage::getWsmVersion() const
{
return this->wsmVersion;
}
void WaveShortMessage::setWsmVersion(int wsmVersion)
{
this->wsmVersion = wsmVersion;
}
int WaveShortMessage::getSecurityType() const
{
return this->securityType;
}
void WaveShortMessage::setSecurityType(int securityType)
{
this->securityType = securityType;
}
int WaveShortMessage::getChannelNumber() const
{
return this->channelNumber;
}
void WaveShortMessage::setChannelNumber(int channelNumber)
{
this->channelNumber = channelNumber;
}
int WaveShortMessage::getDataRate() const
{
return this->dataRate;
}
void WaveShortMessage::setDataRate(int dataRate)
{
this->dataRate = dataRate;
}
int WaveShortMessage::getPriority() const
{
return this->priority;
}
void WaveShortMessage::setPriority(int priority)
{
this->priority = priority;
}
int WaveShortMessage::getPsid() const
{
return this->psid;
}
void WaveShortMessage::setPsid(int psid)
{
this->psid = psid;
}
const char * WaveShortMessage::getPsc() const
{
return this->psc.c_str();
}
void WaveShortMessage::setPsc(const char * psc)
{
this->psc = psc;
}
int WaveShortMessage::getWsmLength() const
{
return this->wsmLength;
}
void WaveShortMessage::setWsmLength(int wsmLength)
{
this->wsmLength = wsmLength;
}
const char * WaveShortMessage::getWsmData() const
{
return this->wsmData.c_str();
}
void WaveShortMessage::setWsmData(const char * wsmData)
{
this->wsmData = wsmData;
}
int WaveShortMessage::getSenderAddress() const
{
return this->senderAddress;
}
void WaveShortMessage::setSenderAddress(int senderAddress)
{
this->senderAddress = senderAddress;
}
int WaveShortMessage::getRecipientAddress() const
{
return this->recipientAddress;
}
void WaveShortMessage::setRecipientAddress(int recipientAddress)
{
this->recipientAddress = recipientAddress;
}
int WaveShortMessage::getSerial() const
{
return this->serial;
}
void WaveShortMessage::setSerial(int serial)
{
this->serial = serial;
}
Coord& WaveShortMessage::getSenderPos()
{
return this->senderPos;
}
void WaveShortMessage::setSenderPos(const Coord& senderPos)
{
this->senderPos = senderPos;
}
Veins::TraCICoord& WaveShortMessage::getGpspos()
{
return this->gpspos;
}
void WaveShortMessage::setGpspos(const Veins::TraCICoord& gpspos)
{
this->gpspos = gpspos;
}
::omnetpp::simtime_t WaveShortMessage::getTimestamp() const
{
return this->timestamp;
}
void WaveShortMessage::setTimestamp(::omnetpp::simtime_t timestamp)
{
this->timestamp = timestamp;
}
class WaveShortMessageDescriptor : public omnetpp::cClassDescriptor
{
private:
mutable const char **propertynames;
public:
WaveShortMessageDescriptor();
virtual ~WaveShortMessageDescriptor();
virtual bool doesSupport(omnetpp::cObject *obj) const override;
virtual const char **getPropertyNames() const override;
virtual const char *getProperty(const char *propertyname) const override;
virtual int getFieldCount() const override;
virtual const char *getFieldName(int field) const override;
virtual int findField(const char *fieldName) const override;
virtual unsigned int getFieldTypeFlags(int field) const override;
virtual const char *getFieldTypeString(int field) const override;
virtual const char **getFieldPropertyNames(int field) const override;
virtual const char *getFieldProperty(int field, const char *propertyname) const override;
virtual int getFieldArraySize(void *object, int field) const override;
virtual std::string getFieldValueAsString(void *object, int field, int i) const override;
virtual bool setFieldValueAsString(void *object, int field, int i, const char *value) const override;
virtual const char *getFieldStructName(int field) const override;
virtual void *getFieldStructValuePointer(void *object, int field, int i) const override;
};
Register_ClassDescriptor(WaveShortMessageDescriptor);
WaveShortMessageDescriptor::WaveShortMessageDescriptor() : omnetpp::cClassDescriptor("WaveShortMessage", "omnetpp::cPacket")
{
propertynames = nullptr;
}
WaveShortMessageDescriptor::~WaveShortMessageDescriptor()
{
delete[] propertynames;
}
bool WaveShortMessageDescriptor::doesSupport(omnetpp::cObject *obj) const
{
return dynamic_cast<WaveShortMessage *>(obj)!=nullptr;
}
const char **WaveShortMessageDescriptor::getPropertyNames() const
{
if (!propertynames) {
static const char *names[] = { nullptr };
omnetpp::cClassDescriptor *basedesc = getBaseClassDescriptor();
const char **basenames = basedesc ? basedesc->getPropertyNames() : nullptr;
propertynames = mergeLists(basenames, names);
}
return propertynames;
}
const char *WaveShortMessageDescriptor::getProperty(const char *propertyname) const
{
omnetpp::cClassDescriptor *basedesc = getBaseClassDescriptor();
return basedesc ? basedesc->getProperty(propertyname) : nullptr;
}
int WaveShortMessageDescriptor::getFieldCount() const
{
omnetpp::cClassDescriptor *basedesc = getBaseClassDescriptor();
return basedesc ? 15+basedesc->getFieldCount() : 15;
}
unsigned int WaveShortMessageDescriptor::getFieldTypeFlags(int field) const
{
omnetpp::cClassDescriptor *basedesc = getBaseClassDescriptor();
if (basedesc) {
if (field < basedesc->getFieldCount())
return basedesc->getFieldTypeFlags(field);
field -= basedesc->getFieldCount();
}
static unsigned int fieldTypeFlags[] = {
FD_ISEDITABLE,
FD_ISEDITABLE,
FD_ISEDITABLE,
FD_ISEDITABLE,
FD_ISEDITABLE,
FD_ISEDITABLE,
FD_ISEDITABLE,
FD_ISEDITABLE,
FD_ISEDITABLE,
FD_ISEDITABLE,
FD_ISEDITABLE,
FD_ISEDITABLE,
FD_ISCOMPOUND,
FD_ISCOMPOUND,
FD_ISEDITABLE,
};
return (field>=0 && field<15) ? fieldTypeFlags[field] : 0;
}
const char *WaveShortMessageDescriptor::getFieldName(int field) const
{
omnetpp::cClassDescriptor *basedesc = getBaseClassDescriptor();
if (basedesc) {
if (field < basedesc->getFieldCount())
return basedesc->getFieldName(field);
field -= basedesc->getFieldCount();
}
static const char *fieldNames[] = {
"wsmVersion",
"securityType",
"channelNumber",
"dataRate",
"priority",
"psid",
"psc",
"wsmLength",
"wsmData",
"senderAddress",
"recipientAddress",
"serial",
"senderPos",
"gpspos",
"timestamp",
};
return (field>=0 && field<15) ? fieldNames[field] : nullptr;
}
Waveshortmessage.h
//Waveshortmessage.h
// Generated file, do not edit! Created by nedtool 5.0 from veins/modules/messages/WaveShortMessage.msg.
//
#ifndef __WAVESHORTMESSAGE_M_H
#define __WAVESHORTMESSAGE_M_H
#include <omnetpp.h>
// nedtool version check
#define MSGC_VERSION 0x0500
#if (MSGC_VERSION!=OMNETPP_VERSION)
# error Version mismatch! Probably this file was generated by an earlier version of nedtool: 'make clean' should help.
#endif
// cplusplus {{
** #include <stdint.h>
#include "veins/modules/mobility/traci/TraCIBuffer.h"
#include "veins/modules/mobility/traci/TraCICommandInterface.h"
#include "veins/modules/mobility/traci/TraCIConnection.h"
#include "veins/modules/mobility/traci/TraCIConstants.h"
#include "veins/modules/mobility/traci/TraCICoord.h" **
#include "veins/base/utils/Coord.h"
// }}
/**
* Class generated from <tt>veins/modules/messages/WaveShortMessage.msg:40</tt> by nedtool.
* <pre>
* packet WaveShortMessage
* {
* //Version of the Wave Short Message
* int wsmVersion = 0;
* //Determine which security mechanism was used
* int securityType = 0;
* //Channel Number on which this packet was sent
* int channelNumber;
* //Data rate with which this packet was sent
* int dataRate = 1;
* //Power Level with which this packet was sent
* int priority = 3;
* //Unique number to identify the service
* int psid = 0;
* //Provider Service Context
* string psc = "Service with some Data";
* //Length of Wave Short Message
* int wsmLength;
* //Data of Wave Short Message
* string wsmData = "Some Data";
*
* int senderAddress = 0;
* int recipientAddress = -1;
* int serial = 0;
* Coord senderPos;
*
* Veins::TraCICoord gpspos = omnet2traci(senderPos);
*
* simtime_t timestamp = 0;
*
* }
* </pre>
*/
class WaveShortMessage : public ::omnetpp::cPacket
{
protected:
int wsmVersion;
int securityType;
int channelNumber;
int dataRate;
int priority;
int psid;
::omnetpp::opp_string psc;
int wsmLength;
::omnetpp::opp_string wsmData;
int senderAddress;
int recipientAddress;
int serial;
Coord senderPos;
Veins::TraCICoord gpspos;
::omnetpp::simtime_t timestamp;
private:
void copy(const WaveShortMessage& other);
protected:
// protected and unimplemented operator==(), to prevent accidental usage
bool operator==(const WaveShortMessage&);
public:
WaveShortMessage(const char *name=nullptr, int kind=0);
WaveShortMessage(const WaveShortMessage& other);
virtual ~WaveShortMessage();
WaveShortMessage& operator=(const WaveShortMessage& other);
virtual WaveShortMessage *dup() const {return new WaveShortMessage(*this);}
virtual void parsimPack(omnetpp::cCommBuffer *b) const;
virtual void parsimUnpack(omnetpp::cCommBuffer *b);
// field getter/setter methods
virtual int getWsmVersion() const;
virtual void setWsmVersion(int wsmVersion);
virtual int getSecurityType() const;
virtual void setSecurityType(int securityType);
virtual int getChannelNumber() const;
virtual void setChannelNumber(int channelNumber);
virtual int getDataRate() const;
virtual void setDataRate(int dataRate);
virtual int getPriority() const;
virtual void setPriority(int priority);
virtual int getPsid() const;
virtual void setPsid(int psid);
virtual const char * getPsc() const;
virtual void setPsc(const char * psc);
virtual int getWsmLength() const;
virtual void setWsmLength(int wsmLength);
virtual const char * getWsmData() const;
virtual void setWsmData(const char * wsmData);
virtual int getSenderAddress() const;
virtual void setSenderAddress(int senderAddress);
virtual int getRecipientAddress() const;
virtual void setRecipientAddress(int recipientAddress);
virtual int getSerial() const;
virtual void setSerial(int serial);
virtual Coord& getSenderPos();
virtual const Coord& getSenderPos() const {return const_cast<WaveShortMessage*>(this)->getSenderPos();}
virtual void setSenderPos(const Coord& senderPos);
virtual Veins::TraCICoord& getGpspos();
virtual const Veins::TraCICoord& getGpspos() const {return const_cast<WaveShortMessage*>(this)->getGpspos();}
virtual void setGpspos(const Veins::TraCICoord& gpspos);
virtual ::omnetpp::simtime_t getTimestamp() const;
virtual void setTimestamp(::omnetpp::simtime_t timestamp);
**Coord traci2omnet(Veins::TraCICoord coord) const;
std::list<Coord> traci2omnet(const std::list<Veins::TraCICoord>&) const;
Veins::TraCICoord omnet2traci(Coord coord) const;
std::list<Veins::TraCICoord> omnet2traci(const std::list<Coord>&) const;**
};
inline void doParsimPacking(omnetpp::cCommBuffer *b, const WaveShortMessage& obj) {obj.parsimPack(b);}
inline void doParsimUnpacking(omnetpp::cCommBuffer *b, WaveShortMessage& obj) {obj.parsimUnpack(b);}
#endif // ifndef __WAVESHORTMESSAGE_M_H
非常感谢任何帮助。谢谢!
答案 0 :(得分:0)
转换头寸的主要原因是什么?
为什么不使用OMNet/Veins - SUMO/TraCi坐标?
答案 1 :(得分:0)
目前我正在使用VANET中的本地化工作,我遇到了同样的问题。
正如您在静脉中看到的那样,SUMO和OMNeT ++使用不同的坐标系,因此当您调用mobility->getCurrentPosition()
时,您将获得omnet坐标而不是相加坐标。
我使用proj4 C库进行了一些测试,并且值不匹配......
就像我一样,你可能正在寻找真正的相扑坐标,为此你需要打电话TraCIConnection::omnet2traci
。但问题是静脉中不存在通过connection
访问对象TraCICommandInterface
的直接接口。
为了克服这个伎俩,我直接在类TraCICommandInterface
中实现了一个公共方法,方法的签名与getLonLat
方法相同,不同之处在于我返回调用方法的相加坐标。 omnet2traci”。现在我可以获得真正的相扑坐标,并将其用于我的真实GPS数据集和我实施的一种致死技术。
遵循方法的代码:
std::pair<double, double> TraCICommandInterface::getTraCIXY(const Coord& coord){
TraCICoord newCoord;
newCoord = connection.omnet2traci(coord);
return std::make_pair(newCoord.x, newCoord.y);
}
在您的应用程序类中,使用一个TracICommandInterface对象调用此方法:
TraCIMobility* mobility;
TraCICommandInterface* traci;
现在你的initialize
方法实例化了这个对象获取活动模块和 traci 接口:
mobility = TraCIMobilityAccess().get(getParentModule());
traci = mobility->getCommandInterface();
现在你将拥有这个:
这些是omnet ++ cordinates:
Coord coordOmnet = mobility->getCurrentPosition();
这些是调用我们的工具方法的相扑坐标:
std::pair<double,double> coordTraCI = traci->getTraCIXY(mobility->getCurrentPosition());
最诚挚的问候,
佩德罗。