AGV_Mockup.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2022 Technical University of Munich, Chair of Materials Handling,
3  * Material Flow, Logistics – All Rights Reserved
4  *
5  * You may use, distribute and modify this code under the terms of the 3-clause
6  * BSD license. You should have received a copy of that license with this file.
7  * If not, please write to {kontakt.fml@ed.tum.de}.
8  */
9 
10 #include "ros/ros.h"
11 #include <iostream>
12 #include "vda5050_msgs/State.h"
13 #include "vda5050_msgs/AGVPosition.h"
14 #include <string>
15 #include <ctime>
16 #include <math.h>
17 
18 using namespace std;
19 
20 
21 string getTimestamp()
22 {
23  time_t now;
24  time(&now);
25  char buf[sizeof "2011-10-08T07:07:09Z"];
26  strftime(buf, sizeof buf, "%FT%TZ", gmtime(&now));
27  return(buf);
28 }
29 
30 /*
31  * This is an AGV mockup to send messages to the supervisor and check if the translation works
32  * It includes the following messages:
33  * MapId
34  * Position (x, y and theta)
35  * BatteryCharge
36  */
37 
38 //creates the order msg
39 vda5050_msgs::State createMessage()
40 {
41  vda5050_msgs::State msg;
42  msg.header.headerId=1;
43  msg.header.timestamp=getTimestamp();
44  msg.header.version="1.1";
45  msg.header.manufacturer="fml Enterprise";
46  msg.header.serialNumber="ajf894ajc";
47  msg.orderId="pass nr 3.5";
48  msg.orderUpdateId=876324;
49  msg.zoneSetId="fml hall of fame";
50  msg.agvPosition.x=0;
51  msg.agvPosition.y=0;
52  msg.agvPosition.theta=0;
53  msg.agvPosition.positionInitialized=true;
54  msg.agvPosition.mapId="ae9748b3-8996-4a67-8709-cbbd40d95ea5";
55  msg.batteryState.batteryCharge=70.0;
56  msg.driving=true;
57 
58  return (msg);
59 
60 }
61 
62 vda5050_msgs::State updateMessage(vda5050_msgs::State msg, float angle, float r, float mx, float my)
63 {
64 
65  msg.agvPosition.x=r*cos(angle)+mx;
66  msg.agvPosition.y=r*sin(angle)+my;
67  msg.agvPosition.theta=angle;
68  return (msg);
69 }
70 
71 int main(int argc, char **argv)
72 {
73  string topicPublish = "state";
74  string topicViz="viz";
75  if (argc > 1)
76  topicPublish=argv[1];
77  ros::init(argc, argv, "state_msg_mockup");
78  ros::NodeHandle nh;
79  ros::Rate loop_rate(10);
80  ros::Publisher publisherState = nh.advertise<vda5050_msgs::State>(topicPublish, 1000);
81  vda5050_msgs::State msg = createMessage();
82  float mx=30;
83  float my=30;
84  float r=10;
85  cout << topicPublish << "\n";
86  float angle=-M_PI;
87  while(ros::ok())
88  {
89  publisherState.publish(msg);
90  ros::spinOnce();
91  loop_rate.sleep();
92  msg.header.headerId+=1;
93  msg=updateMessage(msg,angle,r,mx,my);
94  angle+=0.05;
95  if (angle >= M_PI)
96  angle=-M_PI;
97  }
98  return(0);
99 };
100 
ros::Publisher
createMessage
vda5050_msgs::State createMessage()
Definition: AGV_Mockup.cpp:39
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
ros.h
ros::spinOnce
ROSCPP_DECL void spinOnce()
ros::Publisher::publish
void publish(const boost::shared_ptr< M > &message) const
ros::NodeHandle::advertise
Publisher advertise(AdvertiseOptions &ops)
ros::ok
ROSCPP_DECL bool ok()
getTimestamp
string getTimestamp()
Definition: AGV_Mockup.cpp:21
updateMessage
vda5050_msgs::State updateMessage(vda5050_msgs::State msg, float angle, float r, float mx, float my)
Definition: AGV_Mockup.cpp:62
ros::Rate::sleep
bool sleep()
main
int main(int argc, char **argv)
Definition: AGV_Mockup.cpp:71
std
ros::Rate
ros::NodeHandle


vda5050_connector
Author(s): Florian Rothmeyer , Florian Spiegel
autogenerated on Wed Mar 22 2023 02:38:56