I started learn ROS. I try to read data from launch file with param. but it gave me an error which I did not understand. Please help me. Here is the constructor:
def__init__(self,nodeName,goalx,goaly):
rospy.init_node("node", anonymous="True")
self.goalX = rospy.get_param("x1")
self.goalY = rospy.get_param("y1")
self.pub = rospy.Publisher(nodeName + '/cmd_vel',Twist,queue_size=10)
self.sub = rospy.Subscriber(nodeName+"/odom",Odometry,callback=self.update_pose)
self.odometry = Odometry()
self.rate = rospy.Rate(10)
if __name__ == "__main__":
nodeId = sys.argv[1]
try:
nodeName = "robot_"+nodeId
x = Turtlebot(nodeName,0,0)
x.move2goal()
rospy.spin()
...
Launch File:
<param name="x1" type="int" value="4" />
<param name="y1" type="int" value="0" />
<param name="x2" type="int" value="5" />
<param name="y2" type="int" value="0" />
<node pkg="stage_ros" name="stageros" type="stageros" args="$(find beginner_tutorials)/world/worldfile.world" output="screen"/>
<!-- <node pkg="beginner_tutorials" name="rotate1" args="0" type="projecttask2.py"/> -->
<node pkg="beginner_tutorials" name="rotate2" args="1" type="projecttask2.py"
Error: KeyError('x1')
You're running into this issue because of parameter namespacing. When using rospy.get_param("x1") you're checking pulling the param with respect to the relative namespace. This means you're actually checking for a param at <node_namespace>/x1. However in your node you're not declaring the param under your node; this means it's setup under the global namespace. You have two options to fix this. First, you can simply declare the params within your node's namespace like so:
<node pkg="stage_ros" name="stageros" type="stageros" args="$(find beginner_tutorials)/world/worldfile.world" output="screen">
<param name="x1" type="int" value="4" />
<param name="y1" type="int" value="0" />
<param name="x2" type="int" value="5" />
<param name="y2" type="int" value="0" />
<node/>
Secondly, you could fix the namespacing inside your node so that it pulls params from the global namespace like this:
def__init__(self,nodeName,goalx,goaly):
rospy.init_node("node", anonymous="True")
self.goalX = rospy.get_param("/x1")
self.goalY = rospy.get_param("/y1")
For more information regarding namespaces you can check the [ros wiki page].1
Related
We have a situation where the server is in Germany and we're based in the UK. We want the log4net logs to show a timestamp that is GMT, but I can't work out how or if it's possible to add an hour to the time being written to the log file.
This is our current config:
<log4net>
<root>
<level value="DEBUG" />
<appender-ref ref="LogFileAppender" />
</root>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<file value="logs\\" />
<datePattern value="dd.MM.yyyy'.log'" />
<staticLogFileName value="false" />
<appendToFile value="true" />
<rollingStyle value="Composite" />
<maxSizeRollBackups value="50" />
<maximumFileSize value="5MB" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-dd-MM HH:mm:ss.fff} %-5level - %message%newline" />
</layout>
</appender>
I found some references online to an "hourOffset", but this doesn't seem to work and never appears in the log4net documentation.
Any advise here would be welcome.
Use utcdate instead of d (or date). See also the documentation.
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%utcdate{yyyy-dd-MM HH:mm:ss.fff} %-5level - %message%newline" />
</layout>
I trying to retrive a token OAuth2. But I don't khnow how I can make a x-www-form-urlencoded request using wso2esb.
This is a snippet of my code:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="test-oauth_v1" xmlns="http://ws.apache.org/ns/synapse">
<in>
<property name="RESPONSE" scope="default" value="true"/>
<property action="remove" name="NO_ENTITY_BODY" scope="axis2"/>
<header action="remove" name="To"/>
<property name="messageType" value="application/json" scope="axis2" type="STRING"/>
<property name="basicAuth" scope="default" type="STRING" value="Z3FZVFhUQnhkQlVGNDloblxxzedtSGRBQ1kySWpmSmNvZXdh"/>
<script language="js"><![CDATA[
var body = {};
body.grant_type = 'password';
body.username = 'xxxx';
body.password = 'xxxxxxx';
mc.setPayloadJSON(body);
]]></script>
<property name="messageType" scope="default" type="STRING" value="application/x-www-form-urlencoded"/>
<header
expression="fn:concat('Basic ', get-property('basicAuth'))"
name="Authorization" scope="transport" xmlns:ns="http://org.apache.synapse/xsd"/>
<call>
<endpoint key="server_token_oauth"/>
</call>
<send />
</in>
</sequence>
Would you have any propositions ?
Best regards
You can refer this example [1]. Scope of the messageType should be axis2.
<property name="messageType" value="application/x-www-form-urlencoded" scope="axis2" type="STRING"/>
<property name="DISABLE_CHUNKING" value="true" scope="axis2" type="STRING"/>
I am trying to create en entry in my local OData service like in this example
Using Postman I am making a POST request on https://localhost:8090/odata/titles with this JSON body
{
"#odata.type":"SAPSybaseOData.titles",
"title_id":"ZZ1234",
"title":"new book",
"type":"business",
"pub_id":"1390",
"price":1,
"advance":1,
"total_sales":1,
"notes":"note",
"pubdate":"/Date(581817600000)/",
"contract":true
}
the OData service response status code is 400 - Bad request with this XML body
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<code>30068</code>
<message xml:lang="en-US">An error occurred while parsing the request body.</message>
</error>
my OData service metadata is
<edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" Version="1.0">
<edmx:DataServices xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:DataServiceVersion="1.0">
<Schema xmlns="http://schemas.microsoft.com/ado/2008/09/edm" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" Namespace="SAPSybaseOData">
<EntityType Name="titles">
<Key>
<PropertyRef Name="title_id" />
</Key>
<Property Name="title_id" Type="Edm.String" Nullable="false" MaxLength="6" Unicode="false" Collation="cp850" />
<Property Name="title" Type="Edm.String" Nullable="false" MaxLength="80" Unicode="false" Collation="cp850" />
<Property Name="type" Type="Edm.String" Nullable="false" MaxLength="12" Unicode="false" Collation="cp850" FixedLength="true" />
<Property Name="pub_id" Type="Edm.String" Nullable="true" MaxLength="4" Unicode="false" Collation="cp850" />
<Property Name="price" Type="Edm.Decimal" Nullable="true" Precision="14" Scale="4" />
<Property Name="advance" Type="Edm.Decimal" Nullable="true" Precision="14" Scale="4" />
<Property Name="total_sales" Type="Edm.Int32" Nullable="true" />
<Property Name="notes" Type="Edm.String" Nullable="true" MaxLength="200" Unicode="false" Collation="cp850" />
<Property Name="pubdate" Type="Edm.DateTime" Nullable="false" Precision="3" />
<Property Name="contract" Type="Edm.Boolean" Nullable="false" />
</EntityType>
<EntityContainer Name="SAPSybaseOData_Container" m:IsDefaultEntityContainer="true">
<EntitySet Name="titles" EntityType="SAPSybaseOData.titles" />
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
How can I create a new entry like in this example ?
Am I missing something ? How come the example is working fine and I get a parsing error ?
I have a app/helpers/application_helper.rb file with this code:
def clippy(text, bgcolor = "#ffffff")
text.gsub!('"',"'")
path_to_swf = "/flash/clippy/clippy.swf"
html = <<-EOF
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
width="110"
height="14"
id="clippy" >
<param name="movie" value="#{path_to_swf}"/>
<param name="allowScriptAccess" value="always" />
<param name="quality" value="high" />
<param name="scale" value="noscale" />
<param NAME="FlashVars" value="text=#{text}">
<param name="bgcolor" value="#{bgcolor}">
<embed src="#{path_to_swf}"
width="110"
height="14"
name="clippy"
quality="high"
allowScriptAccess="always"
type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer"
FlashVars="text=#{text}"
bgcolor="#{bgcolor}"
/>
</object>
EOF
raw(html)
end
and I am trying to use it in an HTML file (I use HAML so it is really a HAML file) but I am not sure what I need to do in order to actually call that code above and render the little clippy widget.
I have this HAML code to try to render the clippy:
.clippy-container=clippy("hello","#ffffff")
and I do that in a file located in app/views/my_file.html.haml
Any idea what I need to do in order to make the clippy render?
Thanks!
Isn't there a problem with
app/views/my_file.html.haml
Shouldn't it be
app/views/some_controller/my_file.html.haml
I tried your code, it works fine!
I'm trying to validate a form using the Struts2 validator tool but it doesn't seem to work since, apparently, the xml validator is never acknowledged.
Here is my code:
struts.xml:
<interceptors>
<interceptor name="login_interceptor" class="org.apache.struts.gesprod.produccion.BLLogin">
</interceptor>
<interceptor-stack name="login_stack">
<interceptor-ref name="login_interceptor" />
<interceptor-ref name="defaultStack" />
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="login_stack"></default-interceptor-ref>
<global-results>
<result name="input">/errores/error_input.jsp</result>
<result name="error_sql">/errores/error_sql.jsp</result>
<result name="no_logged">/login.jsp</result>
</global-results>
...
<action name="login" class="org.apache.struts.gesprod.produccion.BLUsuario" method="loginUsuario">
<result name="success" type="redirect">/welcome.jsp</result>
<result name="incorrecto_login">/login.jsp</result>
<result name="input">/login.jsp</result>
</action>
login.jsp:
<div id="login">
<s:fielderror />
<s:form id="login_form" action="login" validate="true">
<s:hidden name="intento_log" value="true" />
<s:textfield name="usuario.username_usuario" label="Usuario"/>
<s:password name="usuario.password_usuario" label="Password"/>
<s:submit value="Ingresar"/>
</s:form>
</div>
And the xml validator, placed in the same package as the Action class.
BLUsuario-login-validation.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
<field name="usuario.username_usuario">
<field-validator type="requiredstring">
<message>Show error!</message>
</field-validator>
</field>
</validators>
Can somebody help and notice if there's something wrong with my code?
I think that the problem is in the name of the xml validator. You have to rename the validator with login-validation.xml. The name that you can put to your xml validator files are:
Validation rules can be specified:
Per Action class: in a file named ActionName-validation.xml
Per Action alias: in a file named ActionName-alias-validation.xml
Inheritance hierarchy and interfaces implemented by Action class: XWork searches up the inheritance tree of the action to find default validations for parent classes of the Action and interfaces implemented
You can see more here:
http://struts.apache.org/2.0.12/docs/validation.html#Validation-DefiningValidationRules
P.D: You said that "the "input" result is never returned even if the fields are wrong". The input result is returned if there are any field error (unless you specify other thing).